Class ClassMisc
The main algorithm is computing the actual ordered complete set of classes and interfaces that a given class extends or implements. This set order is based on the super-class then (recursive interface) declaration order, attempting to reflect the (hopefully intended) abstraction order (from strong to weak).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addSuperClasses
(Set<Class<?>> superSet, Class<?> baseClass) Collect super classes and interfaces in super-order.private static void
addSuperInterfaces
(Set<Class<?>> superSet, Class<?> clazz) Recursively add super-interfaces in super-order.static Class
<?> getCommonSuperClass
(Class<?> baseClass, Class<?> other) Gets the closest common super-class of two classes.getSuperClasses
(Class<?> baseClass, Class<?>... otherClasses) Build the set of super classes and interfaces common to a collection of classes.
-
Constructor Details
-
ClassMisc
private ClassMisc()Lets not instantiate it.
-
-
Method Details
-
addSuperClasses
Collect super classes and interfaces in super-order.This orders from stronger to weaker abstraction in the sense that Integer is a stronger abstraction than Number.
- Parameters:
superSet
- the set of super classes to collect intobaseClass
- the root class.
-
addSuperInterfaces
Recursively add super-interfaces in super-order.On the premise that a class also tends to enumerate interface in the order of weaker abstraction and that interfaces follow the same convention (strong implements weak).
- Parameters:
superSet
- the set of super classes to fillclazz
- the root class.
-
getCommonSuperClass
Gets the closest common super-class of two classes.When building an array, this helps strong-typing the result.
- Parameters:
baseClass
- the class to serve as baseother
- the other class- Returns:
- Object.class if nothing in common, the closest common class or interface otherwise
-
getSuperClasses
Build the set of super classes and interfaces common to a collection of classes.The returned set is ordered and puts classes in order of super-class appearance then interfaces of each super-class.
- Parameters:
baseClass
- the class to serve as baseotherClasses
- the (optional) other classes- Returns:
- an empty set if nothing in common, the set of common classes and interfaces that does not contain the baseClass nor Object class
-