K - the type of object in the index.
C - the type of object in the collection.
public class IndexedCollection<K,C> extends AbstractCollectionDecorator<C>
Modifications made to this decorator modify the index as well as the decorated Collection. However, modifications to the underlying Collection will not update the index and it will get out of sync.
If modification of the decorated Collection is unavoidable, then a call to reindex() will update the index to the current contents of the Collection.
| Constructor and Description |
|---|
IndexedCollection(Collection
Create a
IndexedCollection.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(C object)
|
boolean |
addAll(Collection
|
void |
clear()
|
boolean |
contains(Object
|
boolean |
containsAll(Collection
|
C |
get(K key)
Get the element associated with the given key.
|
static <K |
nonUniqueIndexedCollection(Collection
Create an
IndexedCollection for a non-unique index.
|
void |
reindex()
Clears the index and re-indexes the entire decorated
Collection.
|
boolean |
remove(Object
|
boolean |
removeAll(Collection
|
boolean |
retainAll(Collection
|
static <K |
uniqueIndexedCollection(Collection
Create an
IndexedCollection for a unique index.
|
Collection |
values(K key)
Get all elements associated with the given key.
|
decorated, isEmpty, iterator, setCollection, size, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitequals, hashCode, parallelStream, removeIf, spliterator, streampublic IndexedCollection(Collection<C> coll, Transformer <C ,K> keyTransformer, MultiMap <K ,C> map, boolean uniqueIndex)
IndexedCollection.
coll - decorated
Collection
keyTransformer -
Transformer for generating index keys
map - map to use as index
uniqueIndex - if the index shall enforce uniqueness of index keys
public static <K,C> IndexedCollection <K ,C> uniqueIndexedCollection(Collection <C> coll, Transformer <C ,K> keyTransformer)
IndexedCollection for a unique index.
If an element is added, which maps to an existing key, an IllegalArgumentException will be thrown.
K - the index object type.
C - the collection type.
coll - the decorated
Collection.
keyTransformer - the
Transformer for generating index keys.
IndexedCollection.
public static <K,C> IndexedCollection <K ,C> nonUniqueIndexedCollection(Collection <C> coll, Transformer <C ,K> keyTransformer)
IndexedCollection for a non-unique index.
K - the index object type.
C - the collection type.
coll - the decorated
Collection.
keyTransformer - the
Transformer for generating index keys.
IndexedCollection.
public boolean add(C object)
add in interface
Collection<C>
add in class
AbstractCollectionDecorator<C>
IllegalArgumentException - if the object maps to an existing key and the index enforces a uniqueness constraint
public boolean addAll(Collection<? extends C> coll)
public void clear()
public boolean contains(Objectobject)
Note: uses the index for fast lookup
public boolean containsAll(Collection<?> coll)
Note: uses the index for fast lookup
public C get(K key)
In case of a non-unique index, this method will return the first value associated with the given key. To retrieve all elements associated with a key, use values(Object).
key - key to look up
values(Object)
public Collection<C> values(K key)
key - key to look up
contains(key) == false
public void reindex()
Collection.
public boolean remove(Objectobject)
public boolean removeAll(Collection<?> coll)
public boolean retainAll(Collection<?> coll)