Class SimpleIndexer<E>

java.lang.Object
pascal.taie.util.SimpleIndexer<E>
All Implemented Interfaces:
Serializable, Indexer<E>

public class SimpleIndexer<E> extends Object implements Indexer<E>
A simple map and list based implementation of Indexer. The indexes of the objects are same as their indexes in the list.

If getIndex(Object) is called with an object that was absent in this indexer, it will be added to the indexer automatically. If getObject(int) is called with an index that does not map to any object, an IllegalArgumentException will be thrown.

If you want to obtain an object of its corresponding index by getObject(i), make sure that the object has been indexed by getIndex(o).

See Also:
  • Constructor Details

    • SimpleIndexer

      public SimpleIndexer()
      Constructs an empty indexer.
    • SimpleIndexer

      public SimpleIndexer(int initialCapacity)
      Constructs an empty mapper with the specified initial capacity.
    • SimpleIndexer

      public SimpleIndexer(Collection<? extends E> c)
      Constructs a mapper with a collection. The elements in the collection will be added to the new-created mapper.
  • Method Details

    • getIndex

      public int getIndex(E o)
      Specified by:
      getIndex in interface Indexer<E>
      Returns:
      the index of the given object.
    • getObject

      public E getObject(int index)
      Specified by:
      getObject in interface Indexer<E>
      Returns:
      the corresponding object of the given index.
    • toString

      public String toString()
      Overrides:
      toString in class Object