up
Class Index<E>

java.lang.Object
  extended by up.Index<E>
Type Parameters:
E - the type of the index entries

public class Index<E>
extends java.lang.Object

An index for objects. An index maintains a bijective mapping between a set of objects and a contiguous prefix of the non-negative integers. In the context of this mapping, the objects are called index entries and the integers are called index values.


Constructor Summary
Index()
          Constructs an empty index.
 
Method Summary
 int add(E entry)
          Adds the specified entry to this index.
 boolean contains(E entry)
          Tests whether this index contains the specified entry.
 java.util.List<E> getEntries()
          Returns the list of all entries of this index.
 E getEntry(int index)
          Returns the entry with the specified index value.
 int getIndex(E entry)
          Returns the index value for the specified entry.
 int getNEntries()
          Returns the number of entries in this index.
 E internalize(E entry)
          Return the canonical version of the specified entry in this index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Index

public Index()
Constructs an empty index.

Method Detail

add

public int add(E entry)
Adds the specified entry to this index.

Parameters:
entry - the entry to be added to this index
Returns:
the index value of the new entry

internalize

public E internalize(E entry)
Return the canonical version of the specified entry in this index. This adds the entry to the index if it is not already present.

Parameters:
entry - the entry whose canonical version should be returned
Returns:
the canonical version of the specified entry in this index

getEntry

public E getEntry(int index)
Returns the entry with the specified index value.

Parameters:
index - the index value of the entry to be returned
Returns:
the entry with the specified index, or null if this index does not contain an entry with the specified index value

getEntries

public java.util.List<E> getEntries()
Returns the list of all entries of this index.

Returns:
the list of all entries of this index, in ascending order of their index values

getNEntries

public int getNEntries()
Returns the number of entries in this index.

Returns:
the number of entries in this index

getIndex

public int getIndex(E entry)
Returns the index value for the specified entry.

Parameters:
entry - the entry whose index value should be returned
Returns:
the index value for the specified entry, or -1 if this index does not contain the specified entry

contains

public boolean contains(E entry)
Tests whether this index contains the specified entry.

Parameters:
entry - the entry whose presence in this index is to be tested
Returns:
true if this index contains the specified entry