java.lang.Object
org.bzdev.util.ClassSorter
Sort classes in an order such that for a class c appearing after a
different class c1, c1.isAssignableFrom(c) returns false. In the
list created by this class, a subclass appears before its
superclasses and before the interfaces it implements, and an
interface appears before the interfaces it extends.
Note: when used with a security manager, this class needs the runtime permission getClassLoader. For a class loader, the only method called is hashCode() and the class loaders are local variables in a comparator.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a class.LinkedList<Class<?>>
Create a list of classes ordered so that for a class c appearing after a class c1, c1.isAssignableFrom(c) returns false.static int
getClassDepth
(Class<?> clazz) Get the class depth - the maximum number of hops to Object or to the furthest interface or superinterface.static Comparator<Class<?>>
Get the comparator used to compare classes
-
Constructor Details
-
ClassSorter
public ClassSorter()
-
-
Method Details
-
getClassDepth
Get the class depth - the maximum number of hops to Object or to the furthest interface or superinterface.- Parameters:
clazz
- the class whose depth is to be determined- Returns:
- the class depth
-
getComparator
Get the comparator used to compare classes- Returns:
- the comparator.
-
addKey
Add a class. The queue of classes that were added will be cleared whencreateList
is called.- Parameters:
key
- the class to add- Throws:
IllegalArgumentException
- the argument was invalid (e.g., null)
-
createList
Create a list of classes ordered so that for a class c appearing after a class c1, c1.isAssignableFrom(c) returns false.Note: once called, the classes added by calling addKey will no longer be remembered.
- Returns:
- the list
-