public class SubclassFinder extends Object
InstanceParameterSet
that can be used to
instantiate a sub-class of InstantiableFromParameterSet
.SelectionParameter
using all possible
ParameterSet
s (for classes that are a subclass of a specified
superclass) as elementsClassLoader
than the callerModifier and Type | Field and Description |
---|---|
static String |
includePath
This field can be set to include a path into the search performed in
findSubclasses(Class, String)
thereby enabling to find self-implemented classes not included in the Jstacs class hierarchy. |
Constructor and Description |
---|
SubclassFinder() |
Modifier and Type | Method and Description |
---|---|
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> LinkedList<InstanceParameterSet<? extends T>> |
getInstanceParameterSets(Class<T> clazz,
String startPackage)
This method returns a list of
InstanceParameterSet s that can be used to create a subclass of clazz . |
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 |
static <T> SelectionParameter |
getSelectionParameter(Class<? extends ParameterSet> clazz,
String startPackage,
String name,
String comment,
boolean required)
This method creates an
SelectionParameter that contains
InstanceParameterSet for each possible
class. |
public static String includePath
findSubclasses(Class, String)
thereby enabling to find self-implemented classes not included in the Jstacs class hierarchy.
The default value of this field is null
.
findSubclasses(Class, String)
it is highly recommended to reset the value. If this is not done, preceeding searches might take longer.
public static <T> LinkedList<Class<? extends T>> findInstantiableSubclasses(Class<T> clazz, String startPackage) throws ClassNotFoundException, IOException
T
that can be instantiated, i.e.
are neither an interface nor abstract, and that are located in a package
below startPackage
.T
- The class to obtain the sub-classes forclazz
- the Class
object for TstartPackage
- the package under which to searchClass
objects for the sub-classesClassNotFoundException
- if one of the classes is present in the file system or jar
but cannot be loaded by the class loaderIOException
- is thrown if the classes are searched for in a jar file, but
that file could not be accessed or readpublic static <S,T> LinkedList<Class<? extends S>> filterBySuperclass(Class<S> superclass, LinkedList<Class<? extends T>> listToFilter)
LinkedList
of the Class
objects for all classes
in listToFilter
that are sub-classes of
superClass
.S
- the class that is used as filterT
- a common super-class of all classes in
listToFilter
superclass
- the additional class to use as a filter criterionlistToFilter
- the list of classespublic static LinkedList<Class<? extends InstanceParameterSet>> getParameterSetFor(Class<? extends InstantiableFromParameterSet> clazz)
LinkedList
of the classes of the
InstanceParameterSet
s that can be used to instantiate the
sub-class of InstantiableFromParameterSet
that is given by
clazz
clazz
- the Class
object of the sub-class of
InstantiableFromParameterSet
LinkedList
of Class
es of the corresponding
InstanceParameterSet
spublic static <T> LinkedList<Class<? extends T>> findSubclasses(Class<T> clazz, String startPackage) throws ClassNotFoundException, IOException
T
including interfaces and
abstract classes that are located in a package below
startPackage
.T
- The class to obtain the sub-classes forclazz
- the Class
object for TstartPackage
- the package under which to searchClass
objects for the sub-classesClassNotFoundException
- if one of the classes is present in the file system or jar
but cannot be loaded by the class loaderIOException
- is thrown if the classes are searched for in a jar file, but
that file could not be accessed or readpublic static <T> SelectionParameter getSelectionParameter(Class<? extends ParameterSet> clazz, String startPackage, String name, String comment, boolean required) throws Exception
SelectionParameter
that contains
InstanceParameterSet
for each possible
class. The classes are specified by
findInstantiableSubclasses(Class, String)
and
filterBySuperclass(Class, LinkedList)
.T
- The class to use the sub-classes in the
SelectionParameter
clazz
- the Class
object for T
startPackage
- the package under which to start the searchname
- the name of the SelectionParameter
comment
- the comment for the SelectionParameter
required
- whether the SelectionParameter
is requiredSelectionParameter
that contains
InstanceParameterSet
for each
possible class.Exception
- if the SelectionParameter
could not be created properlyfindInstantiableSubclasses(Class, String)
,
filterBySuperclass(Class, LinkedList)
,
getInstanceParameterSets(Class, String)
public static <T> LinkedList<InstanceParameterSet<? extends T>> getInstanceParameterSets(Class<T> clazz, String startPackage) throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException
InstanceParameterSet
s that can be used to create a subclass of clazz
.
The classes are specified by
findInstantiableSubclasses(Class, String)
and
filterBySuperclass(Class, LinkedList)
.T
- The class to use the sub-classes in the
SelectionParameter
clazz
- the Class
object for T
startPackage
- the package under which to start the searchLinkedList
that contains
InstanceParameterSet
for each
possible class.InstantiationException
- if any InstanceParameterSet
has no nullary
constructor; or if the instantiation fails for some other
reasonIllegalAccessException
- if any InstanceParameterSet
or its nullary
constructor is not accessibleClassNotFoundException
- if one of the classes is present in the file system or jar
but cannot be loaded by the class loaderIOException
- if the classes are searched for in a jar file, but that file
could not be accessed or readfindInstantiableSubclasses(Class, String)
,
filterBySuperclass(Class, LinkedList)