java.lang.Object
org.bzdev.util.ClassArraySorter.Key
- Enclosing class:
- ClassArraySorter
Class providing a key representing an array of classes.
Keys used for entries in a
ClassArraySorter
will
typically be created using the constructor
Key(Class[])
. The remaining constructors
provide keys that may be matched against those in the sorter.-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.Constructor with possibly null array entries.Constructor with possibly null array entries and an argument-count array, but no object-map array.Key
(Class<?>[] types, boolean allowNull, int[] argcount, ClassArraySorter.ArgCountMap[] objectMaps) Constructor with possibly null array entries, an argument-count array, and an object-map array. -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
hashCode()
boolean
Check that each class in this Key is assignable from the corresponding class in the argument Key.boolean
isAssignableFrom
(ClassArraySorter.Key key, boolean cast) Check that each class in this Key is assignable from the corresponding class in the argument Key after a permissible cast.void
Change primitive types to their corresponding subclasses ofNumber
.int
size()
Get the number of classes in this key.Class<?>[]
toArray()
Convert this key to an arrayClass<?>[]
Convert this key to an array given an existing array.toString()
void
Indicate that this key represents a parameter list for a method with a variable number of arguments.
-
Constructor Details
-
Key
Constructor.- Parameters:
types
- an array of classes that the key represents
-
Key
Constructor with possibly null array entries. If one of the types is null, that entry is assumed to match any class when the key is passed as an argument toisAssignableFrom(Key)
orisAssignableFrom(Key,boolean)
.- Parameters:
types
- an array of classes that the key representsallowNull
- true if null values are allowed in the types array
-
Key
Constructor with possibly null array entries and an argument-count array, but no object-map array. If one of the types in the types array is null, that entry is assumed to match any class when the key is passed as an argument toisAssignableFrom(Key)
orisAssignableFrom(Key,boolean)
. The parameter argcount is an array with the same length as the array passed in the types argument. When an element of the argcount array has a non-negative value and the key is used as an argument forisAssignableFrom(Key)
orisAssignableFrom(Key,boolean)
, and a match for a specific element in the array would fail, an alternative test is used. For the expression key1.isAssignableFrom(key2) key1.isAssignableFrom(key2, true), or key1.isAssignableFrom(key2, false), let c1 be an element in key1's class array and let c2 be the corresponding element in key2's class array, and let cnt be the corresponding value of key2's argcount array. If c1.isAssignableFrom(c2) is true, the entries match. If c1.isAssignableFrom(c2) is false, there are several cases:- if key2's argcount array entry corresponding to e2 has
a non-negative value, then the
element also matches if c1 is a functional interface (i.e.,
has the annotation
FunctionalInterface
, and has a public instance method that is not a default method and whose number of arguments is cnt. - if key2's argcount array entry corresponding to c2 has the
value
ClassArraySorter.INTERFACE_TEST
, an error will occur with this constructor as an object map is required for this case. - if key2's argcount array entry corresponding to e2 has the
value
ClassArraySorter.NO_ARGCOUNT_TEST
, then the elements do not match.
- Parameters:
types
- an array of classes that the key representsallowNull
- true if null values are allowed in the types arrayargcount
- the argument-count array- Throws:
IllegalArgumentException
- an argument was not consistent with this constructor.
- if key2's argcount array entry corresponding to e2 has
a non-negative value, then the
element also matches if c1 is a functional interface (i.e.,
has the annotation
-
Key
public Key(Class<?>[] types, boolean allowNull, int[] argcount, ClassArraySorter.ArgCountMap[] objectMaps) throws IllegalArgumentException Constructor with possibly null array entries, an argument-count array, and an object-map array. If one of the types in the types array is null, that entry is assumed to match any class when the key is passed as an argument toisAssignableFrom(Key)
orisAssignableFrom(Key,boolean)
. The parameter argcount is an array with the same length as the array passed in the types argument. When an element of the argcount array has a non-negative value and the key is used as an argument forisAssignableFrom(Key)
orisAssignableFrom(Key,boolean)
, and a match for a specific element in the array would fail, an alternative test is used. For the expression key1.isAssignableFrom(key2) key1.isAssignableFrom(key2, true), or key1.isAssignableFrom(key2, false), let c1 be and element in key1's class array and let c2 be an element in key2's class array, and let cnt be the corresponding value of key2's argcount array. If c1.isAssignableFrom(c2) is true, the entries match. If c1.isAssignableFrom(c2) is false, there are several cases:- if key2's argcount array entry corresponding to e2 has
a non-negative value, then the
element also matches if c1 is a functional interface (i.e.,
has the annotation
FunctionalInterface
, and has a public instance method that is not a default method and whose number of arguments is cnt. - if key2's argcount array entry corresponding to c2 has the
value
ClassArraySorter.INTERFACE_TEST
, and c1 is an interface and then the supplied map, if any, is tested against the interface's public, non-default methods. If the value in the map for such a method's name does not matches the number of arguments that method has, the test fails. Otherwise the test fails. - if key2's argcount array entry corresponding to e2 has the
value
ClassArraySorter.NO_ARGCOUNT_TEST
, then the elements do not match.
- Parameters:
types
- an array of classes that the key representsallowNull
- true if null values are allowed in the types arrayargcount
- the argument-count arrayobjectMaps
- the object-map array, each entry of which maps the names of methods to the expected argument count for that method.- Throws:
IllegalArgumentException
- an object map was required but not provided or the argument allowNull was false while one of the elements in the types argument was null
- if key2's argcount array entry corresponding to e2 has
a non-negative value, then the
element also matches if c1 is a functional interface (i.e.,
has the annotation
-
-
Method Details
-
varargsMode
Indicate that this key represents a parameter list for a method with a variable number of arguments. When called, the key must contain at least one class in its array and the last element must be an array.- Throws:
IllegalStateException
- the key is not compatible with a parameter list for a method or constructor that takes a variable number of arguments
-
promotePrimitives
public void promotePrimitives()Change primitive types to their corresponding subclasses ofNumber
. -
size
public int size()Get the number of classes in this key.- Returns:
- the number of classes in this key
-
toArray
Convert this key to an array- Returns:
- an array containing classes in the same order in which they were entered
-
toArray
Convert this key to an array given an existing array. If the existing array is as long as or longer than the array that is needed, that array will be used. Otherwise a new array will be allocated.- Parameters:
array
- to store the values; null if a new array should be allocated- Returns:
- an array containing classes in the same order in which they were entered
-
equals
-
isAssignableFrom
Check that each class in this Key is assignable from the corresponding class in the argument Key.- Parameters:
key
- the argument key- Returns:
- true if the classes in this key are assignable from the classes in the argument key; false othewise
-
isAssignableFrom
Check that each class in this Key is assignable from the corresponding class in the argument Key after a permissible cast. If this key represents the parameters for a method with a variable number of arguments, the argument key should provide the classes for the arguments passed in a method call.- Parameters:
key
- the argument keycast
- true if the argument key's numerical types should be cast to this key's type.- Returns:
- true if the classes in this key are assignable from the classes in the argument key; false othewise
-
hashCode
public int hashCode() -
toString
-