java.lang.Object
dk.cloudcreate.essentials.shared.reflection.Classes

public final class Classes extends Object
Utility class for working with Class's
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    compareTypeSpecificity(Class<?> leftSide, Class<?> rightSide)
    Compares leftSide with the rightSide for inheritance order.
    It returns: negative integer - if the leftSide is less specific then the rightSide
    Example: If leftSide is a CharSequence and rightSide is a String (a specialization of CharSequence). zero - if the leftSide is equally specific to rightSide (i.e.
    static boolean
    doesClassExistOnClasspath(String fullyQualifiedClassName)
    Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpath
    static boolean
    doesClassExistOnClasspath(String fullyQualifiedClassName, ClassLoader classLoader)
    Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpath
    static Class<?>
    forName(String fullyQualifiedClassName)
    Load a class based on a fully qualified class name (FQCN)
    static Class<?>
    forName(String fullyQualifiedClassName, ClassLoader classLoader)
    Load a class based on a fully qualified class name (FQCN) and using a specific ClassLoader
    static List<Class<?>>
    Get all superclasses of a type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Classes

      public Classes()
  • Method Details

    • forName

      public static Class<?> forName(String fullyQualifiedClassName) throws ReflectionException
      Load a class based on a fully qualified class name (FQCN)
      Parameters:
      fullyQualifiedClassName - the Fully Qualified Class Name (FQCN) as a
      Returns:
      The class loaded
      Throws:
      ReflectionException - in case loading the class failed
    • forName

      public static Class<?> forName(String fullyQualifiedClassName, ClassLoader classLoader) throws ReflectionException
      Load a class based on a fully qualified class name (FQCN) and using a specific ClassLoader
      Parameters:
      fullyQualifiedClassName - the Fully Qualified Class Name (FQCN) as a string
      classLoader - the class loader to use
      Returns:
      The class loaded
      Throws:
      ReflectionException - in case loading the class failed
    • compareTypeSpecificity

      public static int compareTypeSpecificity(Class<?> leftSide, Class<?> rightSide)
      Compares leftSide with the rightSide for inheritance order.
      It returns:
      • negative integer - if the leftSide is less specific then the rightSide
        Example: If leftSide is a CharSequence and rightSide is a String (a specialization of CharSequence).
      • zero - if the leftSide is equally specific to rightSide (i.e. leftSide and rightSide are the same class)
        Example: If leftSide is a CharSequence and rightSide is a CharSequence
      • negative integer - if the leftSide is more specific then the rightSide
        Example: If leftSide is a String (a subclass of CharSequence) and rightSide is a CharSequence.
      Parameters:
      leftSide - the left side type
      rightSide - the right side type
      Returns:
      the inheritance comparison between the leftSide and rightSide
      Throws:
      IllegalArgumentException - in case leftSide and rightSide aren't either the same class or in a inheritance hierarchy with each other
    • superClasses

      public static List<Class<?>> superClasses(Class<?> type)
      Get all superclasses of a type.
      Parameters:
      type - The type to get all super classes for
      Returns:
      All superclasses of type
    • doesClassExistOnClasspath

      public static boolean doesClassExistOnClasspath(String fullyQualifiedClassName)
      Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpath
      Parameters:
      fullyQualifiedClassName - the fully qualified name of the class
      Returns:
      true if a class with the given Fully Qualified Class Name (FQCN) exists on the classpath, otherwise false
    • doesClassExistOnClasspath

      public static boolean doesClassExistOnClasspath(String fullyQualifiedClassName, ClassLoader classLoader)
      Check if a class with the specified Fully Qualified Class Name (FQCN) exists on the classpath
      Parameters:
      fullyQualifiedClassName - the fully qualified name of the class
      classLoader - the classloader used to check if the class exist
      Returns:
      true if a class with the given Fully Qualified Class Name (FQCN) exists on the classpath, otherwise false