|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.onemind.commons.java.datastructure.LookupCache
org.onemind.commons.java.lang.reflect.ClassLookupCache
public class ClassLookupCache
A class lookup cache can lookup non-fully-qualified name classes for a given set
of packages and will cache the lookup for later use. For example,
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
Field Summary | |
---|---|
private static java.util.logging.Logger |
_logger
the logger * |
private java.util.HashSet |
_packages
the packages * |
Constructor Summary | |
---|---|
ClassLookupCache()
|
Method Summary | |
---|---|
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 |
Methods inherited from class org.onemind.commons.java.datastructure.LookupCache |
---|
lookup |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final java.util.HashSet _packages
private static final java.util.logging.Logger _logger
Constructor Detail |
---|
public ClassLookupCache()
Method Detail |
---|
public void addImport(java.lang.String importName)
packageName
- the package namepublic java.lang.Class getClass(java.lang.String className)
className
- the class name
public java.lang.Object produce(java.lang.Object key)
produce
in class LookupCache
key
- the key
public java.util.Set getPackages()
protected void clearNegCache()
clearNegCache
in class LookupCache
protected boolean isInCache(java.lang.Object o)
isInCache
in class LookupCache
o
- the object
protected boolean isInNegCache(java.lang.Object o)
isInNegCache
in class LookupCache
o
- the object
protected void setDoNegativeCache(boolean b)
setDoNegativeCache
in class LookupCache
b
- true to turn on the neg cache
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |