public class ClassDiscovery
extends java.lang.Object
ClassDiscovery.StringCompare
Modifier and Type | Class and Description |
---|---|
class |
ClassDiscovery.StringCompare
compares two strings with the following order:
case insensitive german umlauts (ä , ö etc.) or other non-ASCII letters are treated as special chars special chars < numbers < letters |
Modifier and Type | Field and Description |
---|---|
protected static java.util.Hashtable<java.lang.String,java.util.Vector> |
m_Cache
for caching queries (classname+packagename <-> Vector with classnames)
|
static boolean |
VERBOSE
whether to output some debug information
|
Constructor and Description |
---|
ClassDiscovery() |
Modifier and Type | Method and Description |
---|---|
protected static void |
addCache(java.lang.Class cls,
java.lang.String pkgname,
java.util.Vector classnames)
adds the list of classnames to the cache
|
static void |
clearCache()
clears the cache for class/classnames relation
|
static java.util.Vector |
find(java.lang.Class cls,
java.lang.String pkgname)
Checks the given package for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
static java.util.Vector |
find(java.lang.Class cls,
java.lang.String[] pkgnames)
Checks the given packages for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
static java.util.Vector |
find(java.lang.String classname,
java.lang.String pkgname)
Checks the given package for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
static java.util.Vector |
find(java.lang.String classname,
java.lang.String[] pkgnames)
Checks the given packages for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
static java.util.Vector |
findPackages()
Lists all packages it can find in the classpath.
|
protected static java.util.Vector |
getCache(java.lang.Class cls,
java.lang.String pkgname)
returns the list of classnames associated with this class and package, if
available, otherwise null
|
protected static java.util.HashSet |
getSubDirectories(java.lang.String prefix,
java.io.File dir,
java.util.HashSet list)
adds all the sub-directories recursively to the list
|
protected static java.net.URL |
getURL(java.lang.String classpathPart,
java.lang.String pkgname)
If the given package can be found in this part of the classpath then
an URL object is returned, otherwise
null . |
static boolean |
hasInterface(java.lang.Class intf,
java.lang.Class cls)
Checks whether the given class implements the given interface.
|
static boolean |
hasInterface(java.lang.String intf,
java.lang.String cls)
Checks whether the given class implements the given interface.
|
protected static void |
initCache()
initializes the cache for the classnames
|
static boolean |
isSubclass(java.lang.Class superclass,
java.lang.Class otherclass)
Checks whether the "otherclass" is a subclass of the given "superclass".
|
static boolean |
isSubclass(java.lang.String superclass,
java.lang.String otherclass)
Checks whether the "otherclass" is a subclass of the given "superclass".
|
static void |
main(java.lang.String[] args)
Possible calls:
weka.core.ClassDiscovery <packages>
Prints all the packages in the current classpath weka.core.ClassDiscovery <classname> <packagename(s)> Prints the classes it found. |
public static final boolean VERBOSE
protected static java.util.Hashtable<java.lang.String,java.util.Vector> m_Cache
public static boolean isSubclass(java.lang.String superclass, java.lang.String otherclass)
superclass
- the superclass to check againstotherclass
- this class is checked whether it is a subclass
of the the superclasspublic static boolean isSubclass(java.lang.Class superclass, java.lang.Class otherclass)
superclass
- the superclass to check againstotherclass
- this class is checked whether it is a subclass
of the the superclasspublic static boolean hasInterface(java.lang.String intf, java.lang.String cls)
intf
- the interface to look for in the given classcls
- the class to check for the interfacepublic static boolean hasInterface(java.lang.Class intf, java.lang.Class cls)
intf
- the interface to look for in the given classcls
- the class to check for the interfaceprotected static java.net.URL getURL(java.lang.String classpathPart, java.lang.String pkgname)
null
.classpathPart
- the part of the classpath to look for the packagepkgname
- the package to look forpublic static java.util.Vector find(java.lang.String classname, java.lang.String[] pkgnames)
classname
- the class/interface to look forpkgnames
- the packages to search inpublic static java.util.Vector find(java.lang.String classname, java.lang.String pkgname)
classname
- the class/interface to look forpkgname
- the package to search inpublic static java.util.Vector find(java.lang.Class cls, java.lang.String[] pkgnames)
cls
- the class/interface to look forpkgnames
- the packages to search inpublic static java.util.Vector find(java.lang.Class cls, java.lang.String pkgname)
cls
- the class/interface to look forpkgname
- the package to search inprotected static java.util.HashSet getSubDirectories(java.lang.String prefix, java.io.File dir, java.util.HashSet list)
prefix
- the path prefixdir
- the directory to look in for sub-dirslist
- the current list of sub-dirspublic static java.util.Vector findPackages()
protected static void initCache()
protected static void addCache(java.lang.Class cls, java.lang.String pkgname, java.util.Vector classnames)
cls
- the class to cache the classnames forpkgname
- the package name the classes were found inclassnames
- the list of classnames to cacheprotected static java.util.Vector getCache(java.lang.Class cls, java.lang.String pkgname)
cls
- the class to get the classnames forpkgname
- the package name for the classespublic static void clearCache()
public static void main(java.lang.String[] args)
args
- the commandline arguments