edu.stanford.nlp.util
Class Index

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byedu.stanford.nlp.util.Index
All Implemented Interfaces:
Collection, List, RandomAccess, Serializable

public class Index
extends AbstractList
implements Serializable, RandomAccess

An Index is a list which maps between an Object vocabulary and contiguous integer indices. It supports constant-time lookup in both directions (via get(int) and indexOf(Object). The indexOf(Object) method compares objects by equals, as other Collections.

The typical usage would be:

Index index = new Index(collection);

followed by

int i = index.indexOf(object);

or

Object o = index.get(i);

The source contains a concrete example of use as the main method.

An Index can be locked or unlocked: a locked index cannot have new items added to it.

Since:
1.0
Author:
Dan Klein
See Also:
AbstractList, Serialized Form

Field Summary
protected  Map indexes
           
protected  boolean locked
           
protected  List objects
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Index()
           
Index(Collection c)
           
 
Method Summary
 boolean add(Object o)
          Adds an object to the Index.
 boolean addAll(Collection c)
           
 boolean contains(Object o)
           
 Object get(int i)
           
 int indexOf(Object o)
           
 int[] indices(List elems)
          Returns the index of each elem in an array.
 boolean isLocked()
           
 int lastIndexOf(Object o)
           
 void lock()
           
static void main(String[] args)
           
 int size()
           
 List subList(int from, int to)
           
 void unlock()
           
 
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, iterator, listIterator, listIterator, remove, removeRange, set
 
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

objects

protected List objects

indexes

protected Map indexes

locked

protected boolean locked
Constructor Detail

Index

public Index()

Index

public Index(Collection c)
Method Detail

indices

public int[] indices(List elems)
Returns the index of each elem in an array.


size

public int size()
Specified by:
size in interface List

get

public Object get(int i)
Specified by:
get in interface List

isLocked

public boolean isLocked()

lock

public void lock()

unlock

public void unlock()

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface List

subList

public List subList(int from,
                    int to)
Specified by:
subList in interface List

add

public boolean add(Object o)
Adds an object to the Index. If it was already in the Index, then nothing is done. If it is not in the Index, then it is added iff the Index hasn't been locked.

Specified by:
add in interface List
Returns:
true if the item was added to the index and false if the item was already in the index or if the index is locked

contains

public boolean contains(Object o)
Specified by:
contains in interface List

main

public static void main(String[] args)


Stanford NLP Group