|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.collections4.collection.AbstractCollectionDecorator<C>
org.apache.commons.collections4.collection.IndexedCollection<K,C>
K - the type of object in the index.C - the type of object in the collection.public class IndexedCollection<K,C>
An IndexedCollection is a Map-like view onto a Collection. It accepts a keyTransformer to define how the keys are converted from the values.
Modifications made to this decorator modify the index as well as the
decorated Collection. However, modifications to the underlying
Collection will not updated the index and it will get out of sync.
If modification to the decorated Collection is unavoidable, then a
call to reindex() will update the index to the current contents of
the Collection.
| Constructor Summary | |
|---|---|
IndexedCollection(Collection<C> coll,
Transformer<C,K> keyTransformer,
MultiMap<K,C> map,
boolean uniqueIndex)
Create a IndexedCollection. |
|
| Method Summary | ||
|---|---|---|
boolean |
add(C object)
|
|
boolean |
addAll(Collection<? extends C> coll)
|
|
void |
clear()
|
|
boolean |
contains(Object object)
|
|
boolean |
containsAll(Collection<?> coll)
|
|
C |
get(K key)
Get the element associated with the given key. |
|
static
|
nonUniqueIndexedCollection(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(Object object)
|
|
boolean |
removeAll(Collection<?> coll)
|
|
boolean |
retainAll(Collection<?> coll)
|
|
static
|
uniqueIndexedCollection(Collection<C> coll,
Transformer<C,K> keyTransformer)
Create an IndexedCollection for a unique index. |
|
Collection<C> |
values(K key)
Get all elements associated with the given key. |
|
| Methods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator |
|---|
decorated, equals, hashCode, isEmpty, iterator, setCollection, size, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public IndexedCollection(Collection<C> coll,
Transformer<C,K> keyTransformer,
MultiMap<K,C> map,
boolean uniqueIndex)
IndexedCollection.
coll - decorated CollectionkeyTransformer - Transformer for generating index keysmap - map to use as indexuniqueIndex - if the index shall enforce uniqueness of index keys| Method Detail |
|---|
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 constraintpublic boolean addAll(Collection<? extends C> coll)
addAll in interface Collection<C>addAll in class AbstractCollectionDecorator<C>public void clear()
clear in interface Collection<C>clear in class AbstractCollectionDecorator<C>public boolean contains(Object object)
Note: uses the index for fast lookup
contains in interface Collection<C>contains in class AbstractCollectionDecorator<C>public boolean containsAll(Collection<?> coll)
Note: uses the index for fast lookup
containsAll in interface 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 up
values(Object)public Collection<C> values(K key)
key - key to look up
contains(key) == falsepublic void reindex()
Collection.
public boolean remove(Object object)
remove in interface Collection<C>remove in class AbstractCollectionDecorator<C>public boolean removeAll(Collection<?> coll)
removeAll in interface Collection<C>removeAll in class AbstractCollectionDecorator<C>public boolean retainAll(Collection<?> coll)
retainAll in interface Collection<C>retainAll in class AbstractCollectionDecorator<C>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||