Class Indexer<E extends java.lang.Comparable<E>>

  • All Implemented Interfaces:
    java.io.Serializable

    public class Indexer<E extends java.lang.Comparable<E>>
    extends java.lang.Object
    implements java.io.Serializable
    Maintains a two-way map between a set of objects and contiguous integers from 0 to the number of objects.
    Author:
    Dan Klein, Adam Pauls
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected TIntMap<E> indexes  
      protected boolean locked  
      protected java.util.ArrayList<E> objects  
    • Constructor Summary

      Constructors 
      Constructor Description
      Indexer()  
      Indexer​(boolean sync)  
      Indexer​(java.util.Collection<? extends E> c)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E elem)  
      int getIndex​(E e)
      Return the index of the element If doesn't exist, add it.
      E getObject​(int index)  
      java.lang.Iterable<E> getObjects()  
      int indexOf​(E o)
      Returns the index of the given object, or -1 if the object is not present in the indexer.
      void lock()  
      int size()
      Returns the number of objects indexed.
      void trim()
      Save some space my compacting underlying maps and lists.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • objects

        protected java.util.ArrayList<E extends java.lang.Comparable<E>> objects
      • indexes

        protected TIntMap<E extends java.lang.Comparable<E>> indexes
      • locked

        protected boolean locked
    • Constructor Detail

      • Indexer

        public Indexer​(boolean sync)
      • Indexer

        public Indexer()
      • Indexer

        public Indexer​(java.util.Collection<? extends E> c)
    • Method Detail

      • lock

        public void lock()
      • getObject

        public E getObject​(int index)
      • add

        public boolean add​(E elem)
      • size

        public int size()
        Returns the number of objects indexed.
      • indexOf

        public int indexOf​(E o)
        Returns the index of the given object, or -1 if the object is not present in the indexer.
        Parameters:
        o -
        Returns:
      • getIndex

        public int getIndex​(E e)
        Return the index of the element If doesn't exist, add it.
      • trim

        public void trim()
        Save some space my compacting underlying maps and lists.
      • getObjects

        public java.lang.Iterable<E> getObjects()