public final class MethodKey
extends java.lang.Object
This stores a method (or class) name and parameters.
This replaces the original key scheme which used to build the key by concatenating the method name and parameters class names as one string with the exception that primitive types were converted to their object class equivalents.
The key is still based on the same information, it is just wrapped in an object instead. Primitive type classes are converted to they object equivalent to make a key; int foo(int) and int foo(Integer) do generate the same key.
A key can be constructed either from arguments (array of objects) or from parameters (array of class). Roughly 3x faster than string key to access the map & uses less memory.Modifier and Type | Class and Description |
---|---|
static class |
MethodKey.AmbiguousException
Simple distinguishable exception, used when
we run across ambiguous overloading.
|
private static class |
MethodKey.Parameters<T>
Utility for parameters matching.
|
Modifier and Type | Field and Description |
---|---|
private static MethodKey.Parameters<java.lang.reflect.Constructor<?>> |
CONSTRUCTORS
The parameter matching service for constructors.
|
private static int |
HASH
The hash code constants.
|
private int |
hashCode
The hash code.
|
private static int |
INCOMPARABLE
A method/ctor doesn't match a previously compared one.
|
private static int |
LESS_SPECIFIC
whether a method/ctor is less specific than a previously compared one.
|
private java.lang.String |
method
The method name.
|
private static MethodKey.Parameters<java.lang.reflect.Method> |
METHODS
The parameter matching service for methods.
|
private static int |
MORE_SPECIFIC
whether a method/ctor is more specific than a previously compared one.
|
private static java.lang.Class<?>[] |
NOARGS
A marker for empty parameter list.
|
private java.lang.Class<?>[] |
params
The parameters.
|
Constructor and Description |
---|
MethodKey(java.lang.reflect.Method aMethod)
Creates a key from a method.
|
MethodKey(java.lang.String aMethod,
java.lang.Class<?>[] args)
Creates a key from a method name and a set of parameters.
|
MethodKey(java.lang.String aMethod,
java.lang.Object[] args)
Creates a key from a method name and a set of arguments.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
debugString()
Outputs a human readable debug representation of this key.
|
boolean |
equals(java.lang.Object obj) |
(package private) java.lang.String |
getMethod()
Gets this key's method name.
|
java.lang.reflect.Constructor<?> |
getMostSpecificConstructor(java.util.List<java.lang.reflect.Constructor<?>> methods)
Gets the most specific constructor that is applicable to the parameters of this key.
|
java.lang.reflect.Method |
getMostSpecificMethod(java.util.List<java.lang.reflect.Method> methods)
Gets the most specific method that is applicable to the parameters of this key.
|
(package private) java.lang.Class<?>[] |
getParameters()
Gets this key's method parameter classes.
|
int |
hashCode() |
static boolean |
isInvocationConvertible(java.lang.Class<?> formal,
java.lang.Class<?> actual,
boolean possibleVarArg)
Determines whether a type represented by a class object is
convertible to another type represented by a class object using a
method invocation conversion, treating object types of primitive
types as if they were primitive types (that is, a Boolean actual
parameter type matches boolean primitive formal type).
|
static boolean |
isStrictInvocationConvertible(java.lang.Class<?> formal,
java.lang.Class<?> actual,
boolean possibleVarArg)
Determines whether a type represented by a class object is
convertible to another type represented by a class object using a
method invocation conversion, without matching object and primitive
types.
|
java.lang.String |
toString() |
private final int hashCode
private final java.lang.String method
private final java.lang.Class<?>[] params
private static final java.lang.Class<?>[] NOARGS
private static final int HASH
private static final int MORE_SPECIFIC
private static final int LESS_SPECIFIC
private static final int INCOMPARABLE
private static final MethodKey.Parameters<java.lang.reflect.Method> METHODS
private static final MethodKey.Parameters<java.lang.reflect.Constructor<?>> CONSTRUCTORS
public MethodKey(java.lang.String aMethod, java.lang.Object[] args)
aMethod
- the method to generate the key fromargs
- the intended method argumentsMethodKey(java.lang.reflect.Method aMethod)
aMethod
- the method to generate the key from.MethodKey(java.lang.String aMethod, java.lang.Class<?>[] args)
aMethod
- the method to generate the key fromargs
- the intended method parametersjava.lang.String getMethod()
java.lang.Class<?>[] getParameters()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String debugString()
public java.lang.reflect.Method getMostSpecificMethod(java.util.List<java.lang.reflect.Method> methods)
methods
- a list of methods.MethodKey.AmbiguousException
- if there is more than one.public java.lang.reflect.Constructor<?> getMostSpecificConstructor(java.util.List<java.lang.reflect.Constructor<?>> methods)
methods
- a list of constructors.MethodKey.AmbiguousException
- if there is more than one.public static boolean isInvocationConvertible(java.lang.Class<?> formal, java.lang.Class<?> actual, boolean possibleVarArg)
formal
- the formal parameter type to which the actual
parameter type should be convertibleactual
- the actual parameter type.possibleVarArg
- whether or not we're dealing with the last parameter
in the method declarationpublic static boolean isStrictInvocationConvertible(java.lang.Class<?> formal, java.lang.Class<?> actual, boolean possibleVarArg)
formal
- the formal parameter type to which the actual
parameter type should be convertibleactual
- the actual parameter type.possibleVarArg
- whether or not we're dealing with the last parameter
in the method declaration