public class ObjectIndexer<T> extends Object implements Indexer<T>, Serializable
0
.HashIndexer
,
Serialized FormConstructor and Description |
---|
ObjectIndexer()
Creates an empty
ObjectIndexer with no mappings. |
ObjectIndexer(Collection<? extends T> items)
Creates an
ObjectIndexer with indices for all of the provided items. |
ObjectIndexer(Indexer<? extends T> indexed)
Creates an
ObjectIndexer with indices for all of the provided items. |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all of the item-index mappings.
|
boolean |
contains(T item)
Returns
true if the item has a corresponding index |
int |
find(T item)
Returns the index for the item or a negative value corresponding to the
index the object would have been assigned if it had been added.
|
int |
highestIndex()
Returns the highest index to which any element is mapped.
|
int |
index(T item)
Adds the item and creates an index for it, returning that index.
|
boolean |
indexAll(Collection<T> items)
Adds an index for each item in the collection if it did not already
exist, returning
true if at least one new index was added. |
Set<T> |
items()
Returns an unmodifiable view of the items currently mapped to indices
|
Iterator<Map.Entry<T,Integer>> |
iterator()
Returns an iterator over all the objects and their corresponding indices.
|
T |
lookup(int index)
Returns the element to which this index is mapped or
null if the
index has not been mapped |
Map<Integer,T> |
mapping()
Returns an unmodifiable view from each index to the object mapped to that
index.
|
int |
size()
Returns the number of items that are mapped to indices.
|
String |
toString() |
public ObjectIndexer()
ObjectIndexer
with no mappings.public ObjectIndexer(Collection<? extends T> items)
ObjectIndexer
with indices for all of the provided items.public void clear()
public boolean contains(T item)
true
if the item has a corresponding indexpublic int find(T item)
public int highestIndex()
highestIndex
in interface Indexer<T>
public int index(T item)
public boolean indexAll(Collection<T> items)
true
if at least one new index was added.public Iterator<Map.Entry<T,Integer>> iterator()
remove
. The returned iterator does not support remove
.public T lookup(int index)
null
if the
index has not been mappedpublic Map<Integer,T> mapping()
public int size()
Copyright © 2012. All Rights Reserved.