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 and Description |
|---|---|
static int |
DEFAULT_INIT_CAPACITY
The default initial capacity, which is 500.
|
| Constructor and 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 and 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. |
T |
item(int index)
Returns the object with the specified index.
|
java.util.List<T> |
items()
Returns an listed of indexed objects.
|
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 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()
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