org.bson.util
Class ClassMap<T>
java.lang.Object
org.bson.util.ClassMap<T>
public class ClassMap<T>
- extends Object
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)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ClassMap
public ClassMap()
getAncestry
public static <T> List<Class<?>> getAncestry(Class<T> c)
- 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.
get
public T get(Object key)
put
public T put(Class<?> key,
T value)
remove
public T remove(Object key)
clear
public void clear()
size
public int size()
isEmpty
public boolean isEmpty()