Class ReflectionUtil


  • public final class ReflectionUtil
    extends Object
    Reflection utilities. Contains methods such as getting sub classes. By default only classes prefixed with 'uk.gov.gchq' will be scanned. If you wish to include your own packages/classes in the scanner you can call addReflectionPackages(String...) or set the System Property "koryphe.reflection.packages" with a csv of your additional packages.
    • Method Detail

      • getClassFromName

        public static Class<?> getClassFromName​(String className)
        Simply returns Class.forName(className), but any ClassNotFoundException exceptions are caught and null is returned.
        Parameters:
        className - the class name to lookup
        Returns:
        the class if found, otherwise null.
      • getSimpleClassNames

        public static Map<String,​Set<Class>> getSimpleClassNames​(Class<?> clazz)
        Get a map of simple class name to class, for all sub classes of a given class. The results are cached.
        Parameters:
        clazz - the class to get simple class names for.
        Returns:
        a map of simple class name to class
      • getSubTypes

        public static Set<Class> getSubTypes​(Class<?> clazz)
        Get implementations of a given class. The results are cached.
        Parameters:
        clazz - the class to get sub types of.
        Returns:
        the sub classes.
      • getAnnotatedTypes

        public static Set<Class> getAnnotatedTypes​(Class<? extends Annotation> annoClass)
        Get classes annotated with the given annotation class. The results are cached.
        Parameters:
        annoClass - the annotation class to get classes for.
        Returns:
        the annotated classes.
      • isPublicConcrete

        public static boolean isPublicConcrete​(Class clazz)
        Parameters:
        clazz - the class to test
        Returns:
        true if the class is public, not abstract and not an interface.
      • keepPublicConcreteClasses

        public static void keepPublicConcreteClasses​(Collection<Class> classes)
        Removes non public or non concrete classes from the given collection.
        Parameters:
        classes - the collection of classes to modify.
      • resetReflectionPackages

        public static void resetReflectionPackages()
        Resets the list of packages that are scanned. It will be set back to the default path and the paths set in the system property "koryphe.reflection.packages".
      • resetReflectionCache

        public static void resetReflectionCache()
        Resets the caches.
      • updateReflectionPackages

        public static void updateReflectionPackages()
        Updates the reflection packages using the system property.
      • addReflectionPackages

        public static void addReflectionPackages​(String... newPackages)
        Adds new reflection packages. If any new packages are found then the reflection cache is reset.
        Parameters:
        newPackages - new packages to add. These can be CSVs.
      • addReflectionPackages

        public static void addReflectionPackages​(Iterable<String> newPackages)
      • getReflectionPackages

        public static Set<String> getReflectionPackages()