java.lang.Object
org.bzdev.util.ClassArraySorter
Sort class arrays in a standard order.
The ordering is such that for each array index, a given class will
appear before its superclasses and before the interfaces it implements.
Similarly interfaces will appear before the interfaces they extend.
Arrays that contain the same class for array index 0 will be adjacent
in the sorted order. For an index j, if arrays are selected so that
the classes for each index smaller than j match, and if these arrays
are kept in the same order, then for these selected arrays, all arrays
with the same class at index j will be adjacent.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Table mapping strings to integers.static class
Class providing a key representing an array of classes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Constant used to denote that an argument count array entry should match any interface.static final int
Constant used to denote that an argument count array entry should be ignored. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a Key.Create a list of class arrays ordered so that for a class array ca appearing after a class array ca1, then for all indices i such that ca[j] = ca1[j] when j < i, ca1[i].isAssignableFrom(ca[i]) returns false unless ca[i] = ca1[i].createList
(boolean remember) Create a list of class arrays ordered so that for a class array ca appearing after a class array ca1, then for all indices i such that ca[j] = ca1[j] when j < i, ca1[i].isAssignableFrom(ca[i]) returns false unless ca[i] = ca1[i], optionally remembering the list.static Comparator<ClassArraySorter.Key>
Get the comparator used to compare class arrays.
-
Field Details
-
NO_ARGCOUNT_TEST
public static final int NO_ARGCOUNT_TESTConstant used to denote that an argument count array entry should be ignored. An argument-count array is used by theClassArraySorter.Key
supplied as an argument toClassArraySorter.Key.isAssignableFrom(Key)
orClassArraySorter.Key.isAssignableFrom(Key,boolean)
, and is provided by the constructorsKey(Class[],boolean,int[])
, andKey(Class[],boolean,int[],ArgCountMap[])
. -
INTERFACE_TEST
public static final int INTERFACE_TESTConstant used to denote that an argument count array entry should match any interface. An argument-count array is used by theClassArraySorter.Key
supplied as an argument toClassArraySorter.Key.isAssignableFrom(Key)
orClassArraySorter.Key.isAssignableFrom(Key,boolean)
, and is provided by the constructorsKey(Class[],boolean,int[])
, and.Key(Class[],boolean,int[],ArgCountMap[])
.
-
-
Constructor Details
-
ClassArraySorter
public ClassArraySorter()
-
-
Method Details
-
getComparator
Get the comparator used to compare class arrays.- Returns:
- the comparator.
-
addKey
Add a Key. The queue of Keys that were added will be cleared whencreateList
is called.- Parameters:
key
- the Key to add- Throws:
IllegalArgumentException
- the argument was invalid (e.g., null)
-
createList
Create a list of class arrays ordered so that for a class array ca appearing after a class array ca1, then for all indices i such that ca[j] = ca1[j] when j < i, ca1[i].isAssignableFrom(ca[i]) returns false unless ca[i] = ca1[i].Note: once called, the class arrays added by calling addKey will no longer be remembered.
- Returns:
- the list
-
createList
Create a list of class arrays ordered so that for a class array ca appearing after a class array ca1, then for all indices i such that ca[j] = ca1[j] when j < i, ca1[i].isAssignableFrom(ca[i]) returns false unless ca[i] = ca1[i], optionally remembering the list.Note: once called, the class arrays added by calling addKey will no longer be remembered if the argument has the value
false
.- Parameters:
remember
- true if the list should be remembered; false otherwise- Returns:
- the list
-