org.onemind.commons.java.lang.reflect
public class ClassLookupCache extends LookupCache
ClassLookupCache cache = new ClassLookupCache(); cache.addPackage("*"); //default package cache.addPackage("java.io.*"); Class c = cache.getClass("File"); //c = java.io.File c = cache.getClass("File1"); //c = nullNOTE: 1. The cache is static for all instances of the lookup cache. 2. The packages is instance specific 3. It will cache only positive and negative response of fully qualified name thus lookup of non-fully-qualified has some performance hit, but for the sake of correctness
Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
_logger
the logger *
|
private java.util.HashSet |
_packages
the packages *
|
Constructor and Description |
---|
ClassLookupCache() |
Modifier and Type | Method and Description |
---|---|
void |
addImport(java.lang.String importName)
Add a new package.
|
protected void |
clearNegCache()
Clear all the negative cache
|
java.lang.Class |
getClass(java.lang.String className)
Get the class given by the fully-qualified or non-fully qualified java class name
|
java.util.Set |
getPackages()
Get all the import packages in this lookup cache.
|
protected boolean |
isInCache(java.lang.Object o)
Test if the key is in cache
|
protected boolean |
isInNegCache(java.lang.Object o)
Get whether the object is in negative cache
|
java.lang.Object |
produce(java.lang.Object key)
Produce the class given the key Produce the object given the key.
|
protected void |
setDoNegativeCache(boolean b)
Turn on/off the negative cache
|
lookup
private final java.util.HashSet _packages
private static final java.util.logging.Logger _logger
public void addImport(java.lang.String importName)
packageName
- the package namepublic java.lang.Class getClass(java.lang.String className)
className
- the class namepublic java.lang.Object produce(java.lang.Object key)
produce
in class LookupCache
key
- the keypublic java.util.Set getPackages()
protected void clearNegCache()
clearNegCache
in class LookupCache
protected boolean isInCache(java.lang.Object o)
isInCache
in class LookupCache
o
- the objectprotected boolean isInNegCache(java.lang.Object o)
isInNegCache
in class LookupCache
o
- the objectprotected void setDoNegativeCache(boolean b)
setDoNegativeCache
in class LookupCache
b
- true to turn on the neg cache