Package beagleutil
Class ThreadSafeIndexer<T>
java.lang.Object
beagleutil.ThreadSafeIndexer<T>
- Type Parameters:
T- the type parameter.
Class ThreadSafeIndexer indexes objects.
ThreadSafeIndexer are thread-safe.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default initial capacity, which is 500. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newThreadSafeIndexerinstance with the default initial capacity.ThreadSafeIndexer(int initCapacity) Creates a newThreadSafeIndexerinstance with the specified initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the index of the specified object.intgetIndexIfIndexed(T object) Returns the index of the specified object, or returns-1if the specified object is not indexed.int[]getIndices(T[] objects) Returns an array of object indices corresponding to the specified object array.item(int index) Returns the object with the specified index.items()Returns an listed of all indexed objects.items(int[] indices) Returns a list of objects with the specified indices.intsize()Returns the number of indexed objects.toString()Returnsthis.items().toString().
-
Field Details
-
DEFAULT_INIT_CAPACITY
public static final int DEFAULT_INIT_CAPACITYThe default initial capacity, which is 500.- See Also:
-
-
Constructor Details
-
ThreadSafeIndexer
public ThreadSafeIndexer()Creates a newThreadSafeIndexerinstance with the default initial capacity.- See Also:
-
ThreadSafeIndexer
public ThreadSafeIndexer(int initCapacity) Creates a newThreadSafeIndexerinstance with the specified initial capacity.- Parameters:
initCapacity- the initial capacity- Throws:
IllegalArgumentException- ifinitCapacity < 1
-
-
Method Details
-
getIndex
Returns the index of the specified object. If the object is not yet indexed, the object will be indexed. Indices are assigned in consecutive order beginning with 0.- Parameters:
object- the object whose index will be retrieved- Returns:
- the index of the specified object
- Throws:
NullPointerException- ifobject==null
-
getIndices
Returns an array of object indices corresponding to the specified object array. If an object is not yet indexed, the object will be indexed. Object indices are assigned in increasing order starting with 0.- Parameters:
objects- an array of objects- Returns:
- an array of object identifier indices
- Throws:
IllegalArgumentException- if there is ajsatisfying(0 <= j && j < objects.length) && objects[j].isEmpty()NullPointerException- ifobjects == nullNullPointerException- if there is ajsatisfying(0 <= j && j < objects.length) && (objects[j] == null)
-
getIndexIfIndexed
Returns the index of the specified object, or returns-1if the specified object is not indexed.- Parameters:
object- an object- Returns:
- the index of the specified object, or
-1if the specified object is not indexed - Throws:
NullPointerException- ifobject == null.
-
size
public int size()Returns the number of indexed objects.- Returns:
- the number of indexed objects
-
item
Returns the object with the specified index.- Parameters:
index- an object index- Returns:
- the object with the specified index
- Throws:
IndexOutOfBoundsException- ifindex < 0 || index >= this.size()
-
items
Returns a list of objects with the specified indices.- Parameters:
indices- an array of object indices- Returns:
- a list of objects with the specified indices
- Throws:
IndexOutOfBoundsException- if there exists ajsatisfying(0 <= j && j < indices.length) && (indices[j] < 0 || indices[j] >= this.size())
-
items
Returns an listed of all indexed objects. The returned list will have sizethis.size(), and it will satisfythis.items().get(k).equals(this.item(k))==truefor0 <= k && k < this.size()- Returns:
- an array of objects
-
toString
Returnsthis.items().toString().
-