E
- The type of objects in the Indexpublic interface Index<E>
extends java.lang.Iterable<E>, java.io.Serializable
Often one uses a List to associate a unique index with each Object
(e.g. controlled vocabulary, feature map, etc.). Index offers constant-time
performance for both index -> Object
(get(int)
) and Object -> index
(indexOf(Object)
) as well as for contains(Object)
.
Otherwise it behaves like a normal list. Index also
supports lock()
and unlock()
to ensure that it's
only modified when desired.
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
boolean |
addAll(java.util.Collection<? extends E> c) |
int |
addToIndex(E o)
Takes an Object and returns the integer index of the Object.
|
void |
clear() |
boolean |
contains(java.lang.Object o) |
E |
get(int i)
Gets the object whose index is the integer argument.
|
int |
indexOf(E o)
Returns the integer index of the Object in the Index or -1 if the Object
is not already in the Index.
|
int |
indexOf(E o,
boolean add)
Deprecated.
You should use either the addToIndex(E) or indexOf(E) methods instead
|
boolean |
isLocked()
Queries the Index for whether it's locked or not.
|
void |
lock()
Locks the Index.
|
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. |
void |
saveToFilename(java.lang.String s)
Save the contents of this index into a file.
|
void |
saveToWriter(java.io.Writer out)
Save the contents of this index into string form, as part of a larger
text-serialization.
|
int |
size()
Returns the number of indexed objects.
|
void |
unlock()
Unlocks the Index.
|
int size()
E get(int i)
i
- the integer index to be queried for the corresponding argumentint indexOf(E o)
o
- The Object whose index is desired.int addToIndex(E o)
o
- the Object whose index is desired.@Deprecated int indexOf(E o, boolean add)
o
- the Object whose index is desired.add
- Whether it is okay to add new items to the indexjava.util.List<E> objectsList()
List
of indexed objects, in the order of their indices.List
of indexed objectsjava.util.Collection<E> objects(int[] indices)
Collection
.indices
- An array of indicesCollection
of the objects corresponding to the indices argument.boolean isLocked()
void lock()
add(E)
will
leave the Index unchanged and return false
).void unlock()
add(E)
will
leave the Index unchanged and return false
).void saveToWriter(java.io.Writer out) throws java.io.IOException
out
- Writer to save to.java.io.IOException
- Exception thrown if cannot save.void saveToFilename(java.lang.String s)
s
- File name.boolean contains(java.lang.Object o)
boolean add(E e)
boolean addAll(java.util.Collection<? extends E> c)
void clear()