edu.stanford.nlp.util
Class Interner

java.lang.Object
  extended by edu.stanford.nlp.util.Interner

public class Interner
extends Object

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

Author:
Dan Klein

Field Summary
protected static Interner interner
           
protected  Map map
           
 
Constructor Summary
Interner()
           
 
Method Summary
static Interner getGlobal()
          For getting the instance that global methods use.
static Object globalIntern(Object o)
          Returns a unique object o' that .equals the argument o.
 Object intern(Object o)
          Returns a unique object o' that .equals the argument o.
 Set internAll(Set s)
          Returns a unique object o' that .equals the argument o.
static void main(String[] args)
          Test method: interns its arguments and says whether they == themselves.
static Interner setGlobal(Interner 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

interner

protected static Interner interner

map

protected Map map
Constructor Detail

Interner

public Interner()
Method Detail

getGlobal

public static Interner getGlobal()
For getting the instance that global methods use.


setGlobal

public static Interner setGlobal(Interner interner)
For supplying a new instance for the global methods to use. Returns the previous global interner.


globalIntern

public static Object globalIntern(Object o)
Returns a unique object o' that .equals the argument o. If o itself is returned, this is the first request for an object .equals to o.


intern

public Object intern(Object o)
Returns a unique object o' that .equals the argument o. If o itself is returned, this is the first request for an object .equals to o.


internAll

public Set internAll(Set s)
Returns a unique object o' that .equals the argument o. If o itself is returned, this is the first request for an object .equals to o.


size

public int size()

main

public static void main(String[] args)
Test method: interns its arguments and says whether they == themselves.



Stanford NLP Group