|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
edu.stanford.nlp.util.Index<E>
public class Index<E>
An Index is a collection that maps between an Object vocabulary and a
contiguous non-negative integer index beginning (inclusively) at 0. 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.
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.
AbstractCollection
,
Serialized FormField Summary | |
---|---|
protected java.util.Map<java.lang.Object,java.lang.Integer> |
indexes
|
protected boolean |
locked
|
protected java.util.List<E> |
objects
|
Constructor Summary | |
---|---|
Index()
Creates a new Index. |
|
Index(java.util.Collection<? extends E> c)
Creates a new Index and adds every member of c to it. |
Method Summary | |
---|---|
boolean |
add(E o)
Adds an object to the Index. |
boolean |
addAll(java.util.Collection<? extends E> c)
Adds every member of Collection to the Index. |
void |
clear()
Clears this Index. |
boolean |
contains(java.lang.Object o)
Checks whether an Object already has an index in the Index |
static Index |
deserializeReadable(java.lang.String file)
|
E |
get(int i)
Gets the object whose index is the integer argument. |
int |
indexOf(java.lang.Object o)
Takes an Object and returns the integer index of the Object. |
int |
indexOf(java.lang.Object o,
boolean add)
Takes an Object and returns the integer index of the Object. |
int[] |
indices(java.util.List<E> elems)
Returns the index of each elem in an array. |
boolean |
isLocked()
Queries the Index for whether it's locked or not. |
java.util.Iterator<E> |
iterator()
Returns an iterator over the elements of the collection. |
void |
lock()
Locks the Index. |
static void |
main(java.lang.String[] args)
|
java.util.Collection<E> |
objects(int[] indices)
Looks up the objects corresponding to an array of indices, and returns them in a Collection . |
java.util.List<E> |
objectsList()
Returns a complete List of indexed objects, in the order of their indices. |
boolean |
remove(java.lang.Object o)
Removes an object from the index, if it exists (otherwise nothing happens). |
void |
serializeReadable(java.lang.String file)
|
int |
size()
Checks the number of indexed objects. |
java.lang.String |
toString()
|
void |
unlock()
Unlocks the Index. |
Index<E> |
unmodifiableView()
Returns and unmodifiable view of the Index. |
Methods inherited from class java.util.AbstractCollection |
---|
containsAll, isEmpty, removeAll, retainAll, toArray, toArray |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
equals, hashCode |
Field Detail |
---|
protected java.util.List<E> objects
protected java.util.Map<java.lang.Object,java.lang.Integer> indexes
protected boolean locked
Constructor Detail |
---|
public Index()
public Index(java.util.Collection<? extends E> c)
Method Detail |
---|
public void clear()
clear
in interface java.util.Collection<E>
clear
in class java.util.AbstractCollection<E>
public int[] indices(java.util.List<E> elems)
public java.util.Collection<E> objects(int[] indices)
Collection
.
indices
-
Collection
of the objects corresponding to the indices argument.public int size()
size
in interface java.util.Collection<E>
size
in class java.util.AbstractCollection<E>
public E get(int i)
i
- the integer index to be queried for the corresponding argument
public java.util.List<E> objectsList()
List
of indexed objects, in the order of their indices. DANGER!
The current implementation returns the actual index list, not a defensive copy. Messing with this List
can seriously screw up the state of the Index. (perhaps this method needs to be eliminated? I don't think it's
ever used in ways that we couldn't use the Index itself for directly. --Roger, 12/29/04)
List
of indexed objectspublic boolean isLocked()
public void lock()
add(E)
will
leave the Index unchanged and return false
).
public void unlock()
add(E)
will
leave the Index unchanged and return false
).
public int indexOf(java.lang.Object o)
o
- the Object whose index is desired.
public int indexOf(java.lang.Object o, boolean add)
o
- the Object whose index is desired.
public boolean addAll(java.util.Collection<? extends E> c)
addAll
in interface java.util.Collection<E>
addAll
in class java.util.AbstractCollection<E>
public boolean add(E o)
add
in interface java.util.Collection<E>
add
in class java.util.AbstractCollection<E>
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<E>
contains
in class java.util.AbstractCollection<E>
o
- the object to be queried.
public void serializeReadable(java.lang.String file)
public static Index deserializeReadable(java.lang.String file)
public java.lang.String toString()
toString
in class java.util.AbstractCollection<E>
public static void main(java.lang.String[] args)
public java.util.Iterator<E> iterator()
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in class java.util.AbstractCollection<E>
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<E>
remove
in class java.util.AbstractCollection<E>
o
- the object to remove
public Index<E> unmodifiableView()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |