Top Description Inners Fields Constructors Methods
org.apache.commons.jexl2.internal.introspection

public final Class MethodKey

extends Object
Class Inheritance
Imports
java.util.List, .LinkedList, .Iterator, .Arrays, java.lang.reflect.Constructor, .Method

A method key usable by the introspector cache.

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
MethodKey.AmbiguousException

Simple distinguishable exception, used when we run across ambiguous overloading.

private abstract static class
MethodKey.Parameters<
Method or Constructor
T
>

Utility for parameters matching.

Field Summary

Modifier and TypeField and Description
private static final MethodKey.Parameters<Constructor<?>>
CONSTRUCTORS

The parameter matching service for constructors.

private static final int
HASH

The hash code constants.

private final int
hashCode

The hash code.

private static final int
INCOMPARABLE

A method/ctor doesn't match a previously compared one.

private static final int
LESS_SPECIFIC

whether a method/ctor is less specific than a previously compared one.

private final String
method

The method name.

private static final MethodKey.Parameters<Method>
METHODS

The parameter matching service for methods.

private static final int
MORE_SPECIFIC

whether a method/ctor is more specific than a previously compared one.

private static final Class<?>[]
NOARGS

A marker for empty parameter list.

private final Class<?>[]
params

The parameters.

Constructor Summary

AccessConstructor and Description
public
MethodKey(String
the method to generate the key from
aMethod
,
Object[]
the intended method arguments
args
)

Creates a key from a method name and a set of arguments.

pack-priv
MethodKey(Method
the method to generate the key from.
aMethod
)

Creates a key from a method.

pack-priv
MethodKey(String
the method to generate the key from
aMethod
,
Class<?>[]
the intended method parameters
args
)

Creates a key from a method name and a set of parameters.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

method(p0, p1, ...)
debugString
()

Outputs a human readable debug representation of this key.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
pack-priv String

Returns:

the method name
getMethod
()

Gets this key's method name.

public Constructor<?>

Returns:

the most specific constructor.
getMostSpecificConstructor
(List<Constructor<?>>
a list of constructors.
methods
)

Gets the most specific constructor that is applicable to the parameters of this key.

public Method

Returns:

the most specific method.
getMostSpecificMethod
(List<Method>
a list of methods.
methods
)

Gets the most specific method that is applicable to the parameters of this key.

pack-priv Class<?>[]

Returns:

the parameters
getParameters
()

Gets this key's method parameter classes.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public static boolean

Returns:

true if either formal type is assignable from actual type, or formal is a primitive type and actual is its corresponding object type or an object type of a primitive type that can be converted to the formal type.
isInvocationConvertible
(Class<?>
the formal parameter type to which the actual parameter type should be convertible
formal
,
Class<?>
the actual parameter type.
actual
,
boolean
whether or not we're dealing with the last parameter in the method declaration
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).

public static boolean

Returns:

true if either formal type is assignable from actual type, or formal and actual are both primitive types and actual can be subject to widening conversion to formal.
isStrictInvocationConvertible
(Class<?>
the formal parameter type to which the actual parameter type should be convertible
formal
,
Class<?>
the actual parameter type.
actual
,
boolean
whether or not we're dealing with the last parameter in the method declaration
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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

CONSTRUCTORSback to summary
private static final MethodKey.Parameters<Constructor<?>> CONSTRUCTORS

The parameter matching service for constructors.

HASHback to summary
private static final int HASH

The hash code constants.

hashCodeback to summary
private final int hashCode

The hash code.

INCOMPARABLEback to summary
private static final int INCOMPARABLE

A method/ctor doesn't match a previously compared one.

LESS_SPECIFICback to summary
private static final int LESS_SPECIFIC

whether a method/ctor is less specific than a previously compared one.

methodback to summary
private final String method

The method name.

METHODSback to summary
private static final MethodKey.Parameters<Method> METHODS

The parameter matching service for methods.

MORE_SPECIFICback to summary
private static final int MORE_SPECIFIC

whether a method/ctor is more specific than a previously compared one.

NOARGSback to summary
private static final Class<?>[] NOARGS

A marker for empty parameter list.

paramsback to summary
private final Class<?>[] params

The parameters.

Constructor Detail

MethodKeyback to summary
public MethodKey(String aMethod, Object[] args)

Creates a key from a method name and a set of arguments.

Parameters
aMethod:String

the method to generate the key from

args:Object[]

the intended method arguments

MethodKeyback to summary
pack-priv MethodKey(Method aMethod)

Creates a key from a method.

Parameters
aMethod:Method

the method to generate the key from.

MethodKeyback to summary
pack-priv MethodKey(String aMethod, Class<?>[] args)

Creates a key from a method name and a set of parameters.

Parameters
aMethod:String

the method to generate the key from

args:Class<?>[]

the intended method parameters

Method Detail

debugStringback to summary
public String debugString()

Outputs a human readable debug representation of this key.

Returns:String

method(p0, p1, ...)

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getMethodback to summary
pack-priv String getMethod()

Gets this key's method name.

Returns:String

the method name

getMostSpecificConstructorback to summary
public Constructor<?> getMostSpecificConstructor(List<Constructor<?>> methods)

Gets the most specific constructor that is applicable to the parameters of this key.

Parameters
methods:List<Constructor<?>>

a list of constructors.

Returns:Constructor<?>

the most specific constructor.

Exceptions
AmbiguousException:
if there is more than one.
getMostSpecificMethodback to summary
public Method getMostSpecificMethod(List<Method> methods)

Gets the most specific method that is applicable to the parameters of this key.

Parameters
methods:List<Method>

a list of methods.

Returns:Method

the most specific method.

Exceptions
AmbiguousException:
if there is more than one.
getParametersback to summary
pack-priv Class<?>[] getParameters()

Gets this key's method parameter classes.

Returns:Class<?>[]

the parameters

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isInvocationConvertibleback to summary
public static boolean isInvocationConvertible(Class<?> formal, 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). This behavior is because this method is used to determine applicable methods for an actual parameter list, and primitive types are represented by their object duals in reflective method calls.

Parameters
formal:Class<?>

the formal parameter type to which the actual parameter type should be convertible

actual:Class<?>

the actual parameter type.

possibleVarArg:boolean

whether or not we're dealing with the last parameter in the method declaration

Returns:boolean

true if either formal type is assignable from actual type, or formal is a primitive type and actual is its corresponding object type or an object type of a primitive type that can be converted to the formal type.

isStrictInvocationConvertibleback to summary
public static boolean isStrictInvocationConvertible(Class<?> formal, 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. This method is used to determine the more specific type when comparing signatures of methods.

Parameters
formal:Class<?>

the formal parameter type to which the actual parameter type should be convertible

actual:Class<?>

the actual parameter type.

possibleVarArg:boolean

whether or not we're dealing with the last parameter in the method declaration

Returns:boolean

true if either formal type is assignable from actual type, or formal and actual are both primitive types and actual can be subject to widening conversion to formal.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.apache.commons.jexl2.internal.introspection back to summary

public Class MethodKey.AmbiguousException

extends RuntimeException
Class Inheritance

Simple distinguishable exception, used when we run across ambiguous overloading. Caught by the introspector.

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

Version Id for serializable.

Constructor Detail

AmbiguousExceptionback to summary
public AmbiguousException()
org.apache.commons.jexl2.internal.introspection back to summary

private abstract Class MethodKey.Parameters<T>

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.jexl2.internal.introspection.MethodKey.Parameters
Type Parameters
<T>
Method or Constructor

Utility for parameters matching.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private LinkedList<T>

Returns:

a list that contains only applicable methods (number of formal and actual arguments matches, and argument types are assignable to formal types through a method invocation conversion).
getApplicables
(List<T>
list of all candidate methods
methods
,
Class<?>[]
the actual types of the arguments
classes
)

Returns all methods that are applicable to actual argument types.

private T

Returns:

the most specific method.
getMostSpecific
(List<T>
a list of methods.
methods
,
Class<?>[]
list of argument types.
classes
)

Gets the most specific method that is applicable to actual argument types.

protected abstract Class<?>[]

Returns:

the parameters
getParameterTypes
(T
a method or constructor
app
)

Extract the parameter types from its applicable argument.

private boolean

Returns:

true if method is applicable to arguments
isApplicable
(T
method that will be called
method
,
Class<?>[]
arguments to method
classes
)

Returns true if the supplied method is applicable to actual argument types.

private boolean

Returns:

see isMethodInvocationConvertible.
isConvertible
(Class<?>
the formal parameter type to which the actual parameter type should be convertible
formal
,
Class<?>
the actual parameter type.
actual
,
boolean
whether or not we're dealing with the last parameter in the method declaration
possibleVarArg
)

private boolean

Returns:

see isStrictMethodInvocationConvertible.
isStrictConvertible
(Class<?>
the formal parameter type to which the actual parameter type should be convertible
formal
,
Class<?>
the actual parameter type.
actual
,
boolean
whether or not we're dealing with the last parameter in the method declaration
possibleVarArg
)

private int

Returns:

MORE_SPECIFIC if c1 is more specific than c2, LESS_SPECIFIC if c1 is less specific than c2, INCOMPARABLE if they are incomparable.
moreSpecific
(Class<?>[]
first signature to compare
c1
,
Class<?>[]
second signature to compare
c2
)

Determines which method signature (represented by a class array) is more specific.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Parametersback to summary
private Parameters()

Method Detail

getApplicablesback to summary
private LinkedList<T> getApplicables(List<T> methods, Class<?>[] classes)

Returns all methods that are applicable to actual argument types.

Parameters
methods:List<T>

list of all candidate methods

classes:Class<?>[]

the actual types of the arguments

Returns:LinkedList<T>

a list that contains only applicable methods (number of formal and actual arguments matches, and argument types are assignable to formal types through a method invocation conversion).

getMostSpecificback to summary
private T getMostSpecific(List<T> methods, Class<?>[] classes)

Gets the most specific method that is applicable to actual argument types.

Parameters
methods:List<T>

a list of methods.

classes:Class<?>[]

list of argument types.

Returns:T

the most specific method.

Exceptions
AmbiguousException:
if there is more than one.
getParameterTypesback to summary
protected abstract Class<?>[] getParameterTypes(T app)

Extract the parameter types from its applicable argument.

Parameters
app:T

a method or constructor

Returns:Class<?>[]

the parameters

isApplicableback to summary
private boolean isApplicable(T method, Class<?>[] classes)

Returns true if the supplied method is applicable to actual argument types.

Parameters
method:T

method that will be called

classes:Class<?>[]

arguments to method

Returns:boolean

true if method is applicable to arguments

isConvertibleback to summary
private boolean isConvertible(Class<?> formal, Class<?> actual, boolean possibleVarArg)
Parameters
formal:Class<?>

the formal parameter type to which the actual parameter type should be convertible

actual:Class<?>

the actual parameter type.

possibleVarArg:boolean

whether or not we're dealing with the last parameter in the method declaration

Returns:boolean

see isMethodInvocationConvertible.

See Also
isInvocationConvertible(Class, Class, boolean)
isStrictConvertibleback to summary
private boolean isStrictConvertible(Class<?> formal, Class<?> actual, boolean possibleVarArg)
Parameters
formal:Class<?>

the formal parameter type to which the actual parameter type should be convertible

actual:Class<?>

the actual parameter type.

possibleVarArg:boolean

whether or not we're dealing with the last parameter in the method declaration

Returns:boolean

see isStrictMethodInvocationConvertible.

See Also
isStrictInvocationConvertible(Class, Class, boolean)
moreSpecificback to summary
private int moreSpecific(Class<?>[] c1, Class<?>[] c2)

Determines which method signature (represented by a class array) is more specific. This defines a partial ordering on the method signatures.

Parameters
c1:Class<?>[]

first signature to compare

c2:Class<?>[]

second signature to compare

Returns:int

MORE_SPECIFIC if c1 is more specific than c2, LESS_SPECIFIC if c1 is less specific than c2, INCOMPARABLE if they are incomparable.