edu.stanford.nlp.util
Class Index

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--edu.stanford.nlp.util.Index
All Implemented Interfaces:
Collection, List

public class Index
extends AbstractList

Index is a list which maps between an Object vocabulary and contiguous integer indices. It supports constant-time lookup in both directions.

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.

Since:
1.0
Author:
Dan Klein
See Also:
AbstractList

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)
           
 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
Specified by:
size in class AbstractCollection

get

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

isLocked

public boolean isLocked()

lock

public void lock()

unlock

public void unlock()

indexOf

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

lastIndexOf

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

addAll

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

subList

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

add

public boolean add(Object o)
Specified by:
add in interface List
Overrides:
add in class AbstractList

contains

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

main

public static void main(String[] args)


Stanford NLP Group