Class ClassSorter

java.lang.Object
org.bzdev.util.ClassSorter

public class ClassSorter extends Object
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 Details

    • ClassSorter

      public ClassSorter()
  • Method Details

    • getClassDepth

      public static int getClassDepth(Class<?> clazz)
      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

      public static Comparator<Class<?>> getComparator()
      Get the comparator used to compare classes
      Returns:
      the comparator.
    • addKey

      public void addKey(Class<?> key)
      Add a class. The queue of classes that were added will be cleared when createList is called.
      Parameters:
      key - the class to add
      Throws:
      IllegalArgumentException - the argument was invalid (e.g., null)
    • createList

      public LinkedList<Class<?>> 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