T - the type parameter.public final class ThreadSafeIndexer<T>
extends java.lang.Object
Class ThreadSafeIndexer indexes objects.
ThreadSafeIndexer are thread-safe.| Modifier and Type | Field | Description |
|---|---|---|
static int |
DEFAULT_INIT_CAPACITY |
The default initial capacity, which is 500.
|
| Constructor | Description |
|---|---|
ThreadSafeIndexer() |
Creates a new
ThreadSafeIndexer instance with the default
initial capacity. |
ThreadSafeIndexer(int initCapacity) |
Creates a new
ThreadSafeIndexerinstance with the specified
initial capacity. |
| Modifier and Type | Method | Description |
|---|---|---|
int |
getIndex(T object) |
Returns the index of the specified object.
|
int |
getIndexIfIndexed(T object) |
Returns the index of the specified object, or returns
-1 if the specified object is not indexed. |
int[] |
getIndices(T[] objects) |
Returns an array of object indices corresponding to the specified
object array.
|
T |
item(int index) |
Returns the object with the specified index.
|
java.util.List<T> |
items() |
Returns an listed of all indexed objects.
|
java.util.List<T> |
items(int[] indices) |
Returns a list of objects with the specified indices.
|
int |
size() |
Returns the number of indexed objects.
|
java.lang.String |
toString() |
Returns
this.items().toString(). |
public static final int DEFAULT_INIT_CAPACITY
public ThreadSafeIndexer()
ThreadSafeIndexer instance with the default
initial capacity.DEFAULT_INIT_CAPACITYpublic ThreadSafeIndexer(int initCapacity)
ThreadSafeIndexerinstance with the specified
initial capacity.initCapacity - the initial capacityjava.lang.IllegalArgumentException - if initCapacity < 1public int getIndex(T object)
object - the object whose index will be retrievedjava.lang.NullPointerException - if object==nullpublic int[] getIndices(T[] objects)
objects - an array of objectsjava.lang.IllegalArgumentException - if there is a j satisfying
(0 <= j && j < objects.length) && objects[j].isEmpty()java.lang.NullPointerException - if objects == nulljava.lang.NullPointerException - if there is a j satisfying
(0 <= j && j < objects.length) && (objects[j] == null)public int getIndexIfIndexed(T object)
-1 if the specified object is not indexed.object - an object-1 if the specified object is not indexedjava.lang.NullPointerException - if object == null.public int size()
public T item(int index)
index - an object indexjava.lang.IndexOutOfBoundsException - if
index < 0 || index >= this.size()public java.util.List<T> items(int[] indices)
indices - an array of object indicesjava.lang.IndexOutOfBoundsException - if there exists a j satisfying
(0 <= j && j < indices.length)
&& (indices[j] < 0 || indices[j] >= this.size())public java.util.List<T> items()
this.size(), and it will satisfy
this.items().get(k).equals(this.item(k))==true
for 0 <= k && k < this.size()public java.lang.String toString()
this.items().toString().toString in class java.lang.Objectthis