org.bson.util
Class ClassMap<T>
java.lang.Object
org.bson.util.ClassMap<T>
- All Implemented Interfaces:
- Map<Class,T>
public class ClassMap<T>
- extends Object
- implements Map<Class,T>
Maps Class objects to values. A ClassMap is different from a regular Map
in that get(c) does not only look to see if 'c' is a key in the
Map, but also walks the up superclass and interface graph of 'c'
to find matches. Derived matches of this sort are then "cached" in the
registry so that matches are faster on future gets.
This is a very useful class for Class based registries.
Example:
ClassMap m = new ClassMap();
m.put(Animal.class, "Animal");
m.put(Fox.class, "Fox");
m.Fox.class) --> "Fox"
m.get(Dog.class) --> "Animal"
(assuming Dog.class < Animal.class)
| Nested classes/interfaces inherited from interface java.util.Map |
Map.Entry<K,V> |
ClassMap
public ClassMap()
getInternalMap
protected Map<Class,T> getInternalMap()
- internalMap
getCache
protected Map<Class,T> getCache()
- cache
size
public int size()
- size
- Specified by:
size in interface Map<Class,T>
isEmpty
public boolean isEmpty()
- isEmpty
- Specified by:
isEmpty in interface Map<Class,T>
containsKey
public boolean containsKey(Object key)
- containsKey
- Specified by:
containsKey in interface Map<Class,T>
cacheContainsKey
protected boolean cacheContainsKey(Object key)
- cacheContainsKey
containsValue
public boolean containsValue(Object object)
- containsValue
- Specified by:
containsValue in interface Map<Class,T>
get
public T get(Object key)
- get
- Specified by:
get in interface Map<Class,T>
put
public T put(Class key,
T value)
- put
- Specified by:
put in interface Map<Class,T>
remove
public T remove(Object object)
- remove
- Specified by:
remove in interface Map<Class,T>
putAll
public void putAll(Map map)
- putAll
- Specified by:
putAll in interface Map<Class,T>
clear
public void clear()
- clear
- Specified by:
clear in interface Map<Class,T>
keySet
public Set<Class> keySet()
- keySet
- Specified by:
keySet in interface Map<Class,T>
values
public Collection<T> values()
- values
- Specified by:
values in interface Map<Class,T>
entrySet
public Set<Map.Entry<Class,T>> entrySet()
- entrySet
- Specified by:
entrySet in interface Map<Class,T>
equals
public boolean equals(Object object)
- equals
- Specified by:
equals in interface Map<Class,T>- Overrides:
equals in class Object
hashCode
public int hashCode()
- hashCode
- Specified by:
hashCode in interface Map<Class,T>- Overrides:
hashCode in class Object
initCache
protected void initCache()
- initCache
toString
public String toString()
- toString
- Overrides:
toString in class Object
getAncestry
public static List<Class> getAncestry(Class c)
- getAncestry
Walks superclass and interface graph, superclasses first, then
interfaces, to compute an ancestry list. Supertypes are visited
left to right. Duplicates are removed such that no Class will
appear in the list before one of its subtypes.
Does not need to be synchronized, races are harmless
as the Class graph does not change at runtime.