public class ClassTable<T> extends Object
Map<Class,T>, in which get(java.lang.Class<?>)
will walk
the class hiearchy of its argument looking for a mapping (and will cache that
mapping for subsequent use). Primarily useful as a Method
cache.
Warningput(java.lang.Class<?>, T)
on a base set of classes,
followed by calls to get(java.lang.Class<?>)
with arbitrary descendents of those classes.
Interspersed calls to get()
and put()
are discouraged,
as they may leave different mappings for members of the same class hierarchy. If
you need to replace a mapping, call replace(java.lang.Class<?>, T)
.
Constructor and Description |
---|
ClassTable() |
Modifier and Type | Method and Description |
---|---|
T |
get(Class<?> klass)
Returns the mapping corresponding to the passed class, traversing its
concrete inheritance hierarchy until a match is found.
|
T |
getByObject(Object obj)
Returns the mapping corresponding to the passed object's class.
|
void |
put(Class<?> klass,
T object)
Adds a mapping to the table, replacing any previous exact mapping for that
class.
|
void |
replace(Class<?> klass,
T value)
Replaces the mapping for the passed class and all known subclasses.
|
int |
size()
Returns the number of mappings in this object.
|
public int size()
public void put(Class<?> klass, T object)
public T get(Class<?> klass)
null
if unable to find a match.public T getByObject(Object obj)