edu.stanford.nlp.util.Interner Maven / Gradle / Ivy
package edu.stanford.nlp.util;
import java.lang.ref.WeakReference;
import java.util.Map;
import java.util.Set;
/**
* 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
*/
public class Interner {
protected static Interner