Package com.gengoai

Class 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 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.