|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.util.Interner<T>
public class Interner<T>
For interning (canonicalizing) things.
It maps any object to a unique interned version which .equals the presented object. If presented with a new object which has no previous interned version, the presented object becomes the interned version. You can tell if your object has been chosen as the new unique representative by checking whether o == intern(o). The interners use WeakHashMap, meaning that if the only pointers to an interned item are the interners' backing maps, that item can still be garbage collected. Since the gc thread can silently remove things from the backing map, there's no public way to get the backing map, but feel free to add one at your own risk. Note that in general it is just as good or better to use the static Interner.globalIntern() method rather than making an instance of Interner and using the instance-level intern(). Author: Dan Klein Date: 9/28/03
Field Summary | |
---|---|
protected static Interner<java.lang.Object> |
interner
|
protected java.util.Map<T,java.lang.ref.WeakReference<T>> |
map
|
Constructor Summary | |
---|---|
Interner()
|
Method Summary | ||
---|---|---|
void |
clear()
|
|
static Interner<java.lang.Object> |
getGlobal()
For getting the instance that global methods use. |
|
static
|
globalIntern(T o)
Returns a unique object o' that .equals the argument o. |
|
T |
intern(T o)
Returns a unique object o' that .equals the argument o. |
|
java.util.Set<T> |
internAll(java.util.Set<T> s)
Returns a Set such that each element in the returned set
is a unique object e' that .equals the corresponding element e in the
original set. |
|
static void |
main(java.lang.String[] args)
Test method: interns its arguments and says whether they == themselves. |
|
static Interner<java.lang.Object> |
setGlobal(Interner<java.lang.Object> interner)
For supplying a new instance for the global methods to use. |
|
int |
size()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static Interner<java.lang.Object> interner
protected java.util.Map<T,java.lang.ref.WeakReference<T>> map
Constructor Detail |
---|
public Interner()
Method Detail |
---|
public static Interner<java.lang.Object> getGlobal()
public static Interner<java.lang.Object> setGlobal(Interner<java.lang.Object> interner)
public static <T> T globalIntern(T o)
public void clear()
public T intern(T o)
public java.util.Set<T> internAll(java.util.Set<T> s)
Set
such that each element in the returned set
is a unique object e' that .equals the corresponding element e in the
original set.
public int size()
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |