Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## de.jstacs.utils
Class SubclassFinder

    java.lang.Object
      de.jstacs.utils.SubclassFinder

    public class SubclassFinder

extends Object

Utility-class with static methods to

- find all sub-classes of a certain class (or interface) within the scope of the current class-loader
- find all sub-classes of a certain class (or interface) within the scope of the current class-loader that can be instantiated, i.e. that are neither interfaces nor abstract
- filter a set of classes by inheritance from a super-class
- obtain the class of an `InstanceParameterSet` that can be used to instantiate a sub-class of `InstantiableFromParameterSet`.
- obtain a `CollectionParameter` using all possible `InstanceParameterSet`s (for classes that are a subclass of a specified superclass) as elements

The methods may fail to find a certain sub-class, if

- it was loaded by another `ClassLoader` than the caller
- it was loaded from a physically other place than the super-class, e.g. another jar-file.

Author:
  Jan Grau, Jens Keilwagen

Constructor Summary
`SubclassFinder()`

Method Summary
`static
`<S,T> LinkedList<Class<? extends S>>`
` | `filterBySuperclass(Class<S> superclass, LinkedList<Class<? extends T>> listToFilter)` Returns a `LinkedList` of the `Class` objects for all classes in `listToFilter` that are sub-classes of `superClass`.
`static
`<T> LinkedList<Class<? extends T>>`
` | `findInstantiableSubclasses(Class<T> clazz, String startPackage)` Returns all sub-classes of `T` that can be instantiated, i.e.
`static
`<T> LinkedList<Class<? extends T>>`
` | `findSubclasses(Class<T> clazz, String startPackage)` Returns all sub-classes of `T` including interfaces and abstract classes that are located in a package below `startPackage`.
`static
`<T> CollectionParameter`
` | `getCollection(Class<T> clazz, String startPackage, String name, String comment, boolean required)` This method creates an `CollectionParameter` that contains `InstanceParameterSet` for each possible class.
`static LinkedList<Class<? extends InstanceParameterSet>>` | `getParameterSetFor(Class<? extends InstantiableFromParameterSet> clazz)` Returns a `LinkedList` of the classes of the `InstanceParameterSet`s that can be used to instantiate the sub-class of `InstantiableFromParameterSet` that is given by `clazz`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SubclassFinder

    public SubclassFinder()

Method Detail

### findInstantiableSubclasses

    public static <T> LinkedList<Class<? extends T>> findInstantiableSubclasses(Class<T> clazz,
                                                                                String startPackage)
                                                                     throws ClassNotFoundException,
                                                                            IOException

  Returns all sub-classes of `T` that can be instantiated, i.e. are neither an interface nor abstract, and that are located in a package below `startPackage`.

  Type Parameters:
    `T` - The class to obtain the sub-classes for
  Parameters:
    `clazz` - the `Class` object for T
    `startPackage` - the package under which to search
  Returns:
    the `Class` objects for the sub-classes
  Throws:
    `ClassNotFoundException` - if one of the classes is present in the file system or jar but cannot be loaded by the class loader
    `IOException` - is thrown if the classes are searched for in a jar file, but that file could not be accessed or read

### filterBySuperclass

    public static <S,T> LinkedList<Class<? extends S>> filterBySuperclass(Class<S> superclass,
                                                                          LinkedList<Class<? extends T>> listToFilter)

  Returns a `LinkedList` of the `Class` objects for all classes in `listToFilter` that are sub-classes of `superClass`.

  Type Parameters:
    `S` - the class that is used as filter
    `T` - a common super-class of all classes in `listToFilter`
  Parameters:
    `superclass` - the additional class to use as a filter criterion
    `listToFilter` - the list of classes
  Returns:
    the filtered list

### getParameterSetFor

    public static LinkedList<Class<? extends InstanceParameterSet>> getParameterSetFor(Class<? extends InstantiableFromParameterSet> clazz)

  Returns a `LinkedList` of the classes of the `InstanceParameterSet`s that can be used to instantiate the sub-class of `InstantiableFromParameterSet` that is given by `clazz`

  Parameters:
    `clazz` - the `Class` object of the sub-class of `InstantiableFromParameterSet`
  Returns:
    a `LinkedList` of `Class`es of the corresponding `InstanceParameterSet`s

### findSubclasses

    public static <T> LinkedList<Class<? extends T>> findSubclasses(Class<T> clazz,
                                                                    String startPackage)
                                                         throws ClassNotFoundException,
                                                                IOException

  Returns all sub-classes of `T` including interfaces and abstract classes that are located in a package below `startPackage`.

  Type Parameters:
    `T` - The class to obtain the sub-classes for
  Parameters:
    `clazz` - the `Class` object for T
    `startPackage` - the package under which to search
  Returns:
    the `Class` objects for the sub-classes
  Throws:
    `ClassNotFoundException` - if one of the classes is present in the file system or jar but cannot be loaded by the class loader
    `IOException` - is thrown if the classes are searched for in a jar file, but that file could not be accessed or read

### getCollection

    public static <T> CollectionParameter getCollection(Class<T> clazz,
                                                        String startPackage,
                                                        String name,
                                                        String comment,
                                                        boolean required)
                                             throws InstantiationException,
                                                    IllegalAccessException,
                                                    ClassNotFoundException,
                                                    IOException

  This method creates an `CollectionParameter` that contains `InstanceParameterSet` for each possible class. The classes are specified by `findInstantiableSubclasses(Class, String)` and `filterBySuperclass(Class, LinkedList)`.

  Type Parameters:
    `T` - The class to use the sub-classes in the `CollectionParameter`
  Parameters:
    `clazz` - the `Class` object for `T`
    `startPackage` - the package under which to start the search
    `name` - the name of the `CollectionParameter`
    `comment` - the comment for the `CollectionParameter`
    `required` - whether the `CollectionParameter` is required
  Returns:
    a `CollectionParameter` that contains `InstanceParameterSet` for each possible class.
  Throws:
    `InstantiationException` - if any `InstanceParameterSet` has no nullary constructor; or if the instantiation fails for some other reason
    `IllegalAccessException` - if any `InstanceParameterSet` or its nullary constructor is not accessible
    `ClassNotFoundException` - if one of the classes is present in the file system or jar but cannot be loaded by the class loader
    `IOException` - if the classes are searched for in a jar file, but that file could not be accessed or read
  See Also:
    `findInstantiableSubclasses(Class, String)`, `filterBySuperclass(Class, LinkedList)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD