static final class ClassMap.MethodCache
extends java.lang.Object
It stores the association between: - a key made of a method name & an array of argument types. - a method.
Since the invocation of the associated method is dynamic, there is no need (nor way) to differentiate between foo(int,int) & foo(Integer,Integer) since in practise, only the latter form will be used through a call. This of course, applies to all 8 primitive types.
Modifier and Type | Field and Description |
---|---|
private static java.lang.reflect.Method |
CACHE_MISS
The cache miss marker method.
|
private MethodMap |
methodMap
Map of methods that are searchable according to method parameters to find a match.
|
private java.util.Map<MethodKey,java.lang.reflect.Method> |
methods
The method cache.
|
private static int |
PRIMITIVE_SIZE
The initial size of the primitive conversion map.
|
private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> |
PRIMITIVE_TYPES
The primitive type to class conversion map.
|
Constructor and Description |
---|
MethodCache() |
Modifier and Type | Method and Description |
---|---|
static java.lang.reflect.Method |
cacheMiss()
A method that returns itself used as a marker for cache miss,
allows the underlying cache map to be strongly typed.
|
(package private) java.lang.reflect.Method |
get(MethodKey methodKey)
Find a Method using the method name and parameter objects.
|
(package private) java.lang.reflect.Method[] |
get(java.lang.String methodName)
Gets all the methods with a given name from this map.
|
(package private) java.lang.String[] |
names()
Gets all the method names from this map.
|
(package private) static java.lang.Class<?> |
primitiveClass(java.lang.Class<?> parm)
Converts a primitive type to its corresponding class.
|
(package private) void |
put(java.lang.reflect.Method method)
Adds a method to the map.
|
private static final java.lang.reflect.Method CACHE_MISS
private static final int PRIMITIVE_SIZE
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> PRIMITIVE_TYPES
private final java.util.Map<MethodKey,java.lang.reflect.Method> methods
Cache of Methods, or CACHE_MISS, keyed by method name and actual arguments used to find it.
private final MethodMap methodMap
public static java.lang.reflect.Method cacheMiss()
static java.lang.Class<?> primitiveClass(java.lang.Class<?> parm)
If the argument type is primitive then we want to convert our primitive type signature to the corresponding Object type so introspection for methods with primitive types will work correctly.
parm
- a may-be primitive type classjava.lang.reflect.Method get(MethodKey methodKey) throws MethodKey.AmbiguousException
Look in the methodMap for an entry. If found, it'll either be a CACHE_MISS, in which case we simply give up, or it'll be a Method, in which case, we return it.
If nothing is found, then we must actually go and introspect the method from the MethodMap.
methodKey
- the method keyMethodKey.AmbiguousException
- When more than one method is a match for the parameters.void put(java.lang.reflect.Method method)
method
- the method to addjava.lang.String[] names()
java.lang.reflect.Method[] get(java.lang.String methodName)
methodName
- the seeked methods name