Class ClassFinder


  • public final class ClassFinder
    extends Object
    Utility class for finding names of classes implementing an interface or class in directories or JAR files.
    Author:
    Pascal Essiembre
    • Method Detail

      • findSubTypes

        public static <T> List<Class<? extends T>> findSubTypes​(Class<T> superClass)
        Finds the names of all subtypes of the super class, scanning the roots of this class classpath. This method is null-safe. If no classes are found, an empty list will be returned.
        Type Parameters:
        T - super type
        Parameters:
        superClass - the class from which to find subtypes
        Returns:
        list of class names
        Since:
        1.4.0
      • findSubTypes

        public static <T> List<Class<? extends T>> findSubTypes​(Class<T> superClass,
                                                                Predicate<String> predicate)
        Finds the names of all subtypes of the super class, scanning the roots of this class classpath. This method is null-safe. If no classes are found, an empty list will be returned.
        Type Parameters:
        T - super type
        Parameters:
        superClass - the class from which to find subtypes
        predicate - filter to keep classes testing true
        Returns:
        list of class names
        Since:
        2.0.0
      • findSubTypes

        public static <T> List<Class<? extends T>> findSubTypes​(List<File> files,
                                                                Class<T> superClass)
        Finds the names of all subtypes of the super class in list of File supplied. This method is null-safe. If no classes are found, an empty list will be returned.
        Type Parameters:
        T - super type
        Parameters:
        files - directories and/or JARs to scan for classes
        superClass - the class from which to find subtypes
        Returns:
        list of class names
        Since:
        1.4.0
      • findSubTypes

        public static <T> List<Class<? extends T>> findSubTypes​(List<File> files,
                                                                Class<T> superClass,
                                                                Predicate<String> accept)
        Finds the names of all subtypes of the super class in list of File supplied. This method is null-safe. If no classes are found, an empty list will be returned.
        Type Parameters:
        T - super type
        Parameters:
        files - directories and/or JARs to scan for classes
        superClass - the class from which to find subtypes
        accept - filter to keep classes testing true
        Returns:
        list of class names
        Since:
        2.0.0
      • findSubTypes

        public static <T> List<Class<? extends T>> findSubTypes​(File file,
                                                                Class<T> superClass)
        Finds the names of all subtypes of the super class for the supplied File. This method is null-safe. If no classes are found, an empty list will be returned. If the file is null or does not exists, or if it is not a JAR or directory, an empty string list will be returned.
        Type Parameters:
        T - super type
        Parameters:
        file - directory or JAR to scan for classes
        superClass - the class from which to find subtypes
        Returns:
        list of class names
        Since:
        1.4.0
      • findSubTypes

        public static <T> List<Class<? extends T>> findSubTypes​(File file,
                                                                Class<T> superClass,
                                                                Predicate<String> predicate)
        Finds the names of all subtypes of the super class for the supplied File. This method is null-safe. If no classes are found, an empty list will be returned. If the file is null or does not exists, or if it is not a JAR or directory, an empty string list will be returned.
        Type Parameters:
        T - super type
        Parameters:
        file - directory or JAR to scan for classes
        superClass - the class from which to find subtypes
        predicate - filter to keep classes testing true
        Returns:
        list of class names
        Since:
        2.0.0