Package com.gengoai
Class Interner<E>
- java.lang.Object
-
- com.gengoai.Interner<E>
-
- Type Parameters:
E
- the type parameter
- All Implemented Interfaces:
Serializable
public final class Interner<E> extends Object implements Serializable
Mimics
String.intern()
with any object using heap memory. Uses weak references so that objects no longer in memory can be reclaimed.- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Interner(@NonNull Collection<? extends E> items)
Instantiates a new Interner initializing it with the given items.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
intern(E object)
Adds or gets the canonical version of the incoming object.Collection<E>
internAll(@NonNull Iterable<? extends E> iterable)
Interns all elements in the given iterable.int
size()
The number of items that have been interned.String
toString()
-
-
-
Constructor Detail
-
Interner
public Interner(@NonNull @NonNull Collection<? extends E> items)
Instantiates a new Interner initializing it with the given items.- Parameters:
items
- the items
-
-
Method Detail
-
intern
public E intern(E object)
Adds or gets the canonical version of the incoming object.
- Parameters:
object
- The object to intern- Returns:
- The interned value
- Throws:
NullPointerException
- if the object is null
-
internAll
public Collection<E> internAll(@NonNull @NonNull Iterable<? extends E> iterable)
Interns all elements in the given iterable.
- Parameters:
iterable
- the items of elements to intern.- Returns:
- the interned elements.
- Throws:
NullPointerException
- if the collection is null
-
size
public int size()
The number of items that have been interned.
- Returns:
- the number of items that have been interned.
-
-