## edu.stanford.nlp.util.concurrent
Class SynchronizedInterner<T>

    java.lang.Object
      edu.stanford.nlp.util.concurrent.SynchronizedInterner<T>

    public class SynchronizedInterner<T>

extends Object

For interning (canonicalizing) things in a multi-threaded environment.

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 a concurrent map with weak references, 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 SynchronizedInterner.globalIntern() method rather than making an instance of SynchronizedInterner and using the instance-level intern().

Author:
  Ilya Sherman
See Also:
  `Interner`

Field Summary
`protected Interner<T>` `delegate`
`protected static Object` `globalMutex`
`protected static SynchronizedInterner<Object>` `interner`
`protected Object` `mutex`

Constructor Summary
`SynchronizedInterner(Interner<T> delegate)`
`SynchronizedInterner(Interner<T> delegate, Object mutex)`

Method Summary
`void` `clear()`
`static SynchronizedInterner<Object>` `getGlobal()` For getting the instance that global methods use.

`static

`<T> T`

`

`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.
`Set<T>` `internAll(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(String[] args)` Test method: interns its arguments and says whether they == themselves.
`static SynchronizedInterner<Object>` `setGlobal(Interner<Object> delegate)` 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

### globalMutex

    protected static final Object globalMutex

### interner

    protected static SynchronizedInterner<Object> interner

### delegate

    protected final Interner<T> delegate

### mutex

    protected final Object mutex

Constructor Detail

### SynchronizedInterner

    public SynchronizedInterner(Interner<T> delegate)

### SynchronizedInterner

    public SynchronizedInterner(Interner<T> delegate,
                                Object mutex)

Method Detail

### getGlobal

    public static SynchronizedInterner<Object> getGlobal()

  For getting the instance that global methods use.

### setGlobal

    public static SynchronizedInterner<Object> setGlobal(Interner<Object> delegate)

  For supplying a new instance for the global methods to use.

  Returns:
    the previous global interner.

### globalIntern

    public static <T> T globalIntern(T 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.

### clear

    public void clear()

### intern

    public T intern(T 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<T> internAll(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.

### size

    public int size()

### main

    public static void main(String[] args)
                     throws InterruptedException

  Test method: interns its arguments and says whether they == themselves.

  Throws:
    `InterruptedException`

Stanford NLP Group