E
- Element type to storepublic class ConcurrentHashIndex<E> extends java.util.AbstractCollection<E> implements Index<E>, java.util.RandomAccess
Modifier and Type | Field and Description |
---|---|
static int |
UNKNOWN_ID |
Constructor and Description |
---|
ConcurrentHashIndex()
Constructor.
|
ConcurrentHashIndex(int initialCapacity)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o) |
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.
|
boolean |
isLocked()
Queries the Index for whether it's locked or not.
|
java.util.Iterator<E> |
iterator() |
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.
|
java.lang.String |
toString() |
void |
unlock()
Unlocks the Index.
|
containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
public static final int UNKNOWN_ID
public ConcurrentHashIndex()
public ConcurrentHashIndex(int initialCapacity)
initialCapacity
- public E get(int i)
Index
public int indexOf(E o)
Index
public int addToIndex(E o)
Index
addToIndex
in interface Index<E>
o
- the Object whose index is desired.@Deprecated public int indexOf(E o, boolean add)
Index
public boolean add(E o)
public boolean addAll(java.util.Collection<? extends E> c)
public java.util.List<E> objectsList()
Index
List
of indexed objects, in the order of their indices.objectsList
in interface Index<E>
List
of indexed objectspublic java.util.Collection<E> objects(int[] indices)
Index
Collection
.public boolean isLocked()
Index
public void lock()
Index
Index.add(E)
will
leave the Index unchanged and return false
).public void unlock()
Index
Index.add(E)
will
leave the Index unchanged and return false
).public void saveToWriter(java.io.Writer out) throws java.io.IOException
Index
saveToWriter
in interface Index<E>
out
- Writer to save to.java.io.IOException
- Exception thrown if cannot save.public void saveToFilename(java.lang.String s)
Index
saveToFilename
in interface Index<E>
s
- File name.public java.util.Iterator<E> iterator()
public int size()
Index
public java.lang.String toString()
toString
in class java.util.AbstractCollection<E>
public boolean contains(java.lang.Object o)