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(java.util.Collection<C> coll,
Transformer<C,K> keyTransformer,
MultiMap<K,C> map,
boolean uniqueIndex)
Create a
IndexedCollection . |
Modifier and Type | Method and Description |
---|---|
boolean |
add(C object) |
boolean |
addAll(java.util.Collection<? extends C> coll) |
void |
clear() |
boolean |
contains(java.lang.Object object) |
boolean |
containsAll(java.util.Collection<?> coll) |
C |
get(K key)
Get the element associated with the given key.
|
static <K,C> IndexedCollection<K,C> |
nonUniqueIndexedCollection(java.util.Collection<C> coll,
Transformer<C,K> keyTransformer)
Create an
IndexedCollection for a non-unique index. |
void |
reindex()
Clears the index and re-indexes the entire decorated
Collection . |
boolean |
remove(java.lang.Object object) |
boolean |
removeAll(java.util.Collection<?> coll) |
boolean |
retainAll(java.util.Collection<?> coll) |
static <K,C> IndexedCollection<K,C> |
uniqueIndexedCollection(java.util.Collection<C> coll,
Transformer<C,K> keyTransformer)
Create an
IndexedCollection for a unique index. |
java.util.Collection<C> |
values(K key)
Get all elements associated with the given key.
|
isEmpty, iterator, size, toArray, toArray, toString
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
public IndexedCollection(java.util.Collection<C> coll, Transformer<C,K> keyTransformer, MultiMap<K,C> map, boolean uniqueIndex)
IndexedCollection
.coll
- decorated Collection
keyTransformer
- Transformer
for generating index keysmap
- map to use as indexuniqueIndex
- if the index shall enforce uniqueness of index keyspublic static <K,C> IndexedCollection<K,C> uniqueIndexedCollection(java.util.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(java.util.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 java.util.Collection<C>
add
in class AbstractCollectionDecorator<C>
java.lang.IllegalArgumentException
- if the object maps to an existing key and the index
enforces a uniqueness constraintpublic boolean addAll(java.util.Collection<? extends C> coll)
addAll
in interface java.util.Collection<C>
addAll
in class AbstractCollectionDecorator<C>
public void clear()
clear
in interface java.util.Collection<C>
clear
in class AbstractCollectionDecorator<C>
public boolean contains(java.lang.Object object)
Note: uses the index for fast lookup
contains
in interface java.util.Collection<C>
contains
in class AbstractCollectionDecorator<C>
public boolean containsAll(java.util.Collection<?> coll)
Note: uses the index for fast lookup
containsAll
in interface java.util.Collection<C>
containsAll
in class AbstractCollectionDecorator<C>
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 upvalues(Object)
public java.util.Collection<C> values(K key)
key
- key to look upcontains(key) == false
public void reindex()
Collection
.public boolean remove(java.lang.Object object)
remove
in interface java.util.Collection<C>
remove
in class AbstractCollectionDecorator<C>
public boolean removeAll(java.util.Collection<?> coll)
removeAll
in interface java.util.Collection<C>
removeAll
in class AbstractCollectionDecorator<C>
public boolean retainAll(java.util.Collection<?> coll)
retainAll
in interface java.util.Collection<C>
retainAll
in class AbstractCollectionDecorator<C>
Copyright © 2010 - 2020 Adobe. All Rights Reserved