Class IndexedCollection<K,C> 
java.lang.Object
org.apache.commons.collections4.collection.AbstractCollectionDecorator<C>
org.apache.commons.collections4.collection.IndexedCollection<K,C> 
- Type Parameters:
- K- the type of object in the index.
- C- the type of object in the collection.
- All Implemented Interfaces:
- Serializable,- Iterable<C>,- Collection<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 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.
 
- Since:
- 4.0
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionIndexedCollection(Collection<C> coll, Transformer<C, K> keyTransformer, MultiMap<K, C> map, boolean uniqueIndex) Create aIndexedCollection.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends C> coll) voidclear()booleanbooleancontainsAll(Collection<?> coll) Gets the element associated with the given key.static <K,C> IndexedCollection <K, C> nonUniqueIndexedCollection(Collection<C> coll, Transformer<C, K> keyTransformer) Create anIndexedCollectionfor a non-unique index.voidreindex()Clears the index and re-indexes the entire decoratedCollection.booleanbooleanremoveAll(Collection<?> coll) booleanbooleanretainAll(Collection<?> coll) static <K,C> IndexedCollection <K, C> uniqueIndexedCollection(Collection<C> coll, Transformer<C, K> keyTransformer) Create anIndexedCollectionfor a unique index.Gets all elements associated with the given key.Methods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecoratordecorated, isEmpty, iterator, setCollection, size, toArray, toArray, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collectionequals, hashCode, parallelStream, spliterator, stream
- 
Constructor Details- 
IndexedCollectionpublic IndexedCollection(Collection<C> coll, Transformer<C, K> keyTransformer, MultiMap<K, C> map, boolean uniqueIndex) Create aIndexedCollection.- Parameters:
- coll- decorated- Collection
- keyTransformer-- Transformerfor generating index keys
- map- map to use as index
- uniqueIndex- if the index shall enforce uniqueness of index keys
 
 
- 
- 
Method Details- 
nonUniqueIndexedCollectionpublic static <K,C> IndexedCollection<K,C> nonUniqueIndexedCollection(Collection<C> coll, Transformer<C, K> keyTransformer) Create anIndexedCollectionfor a non-unique index.- Type Parameters:
- K- the index object type.
- C- the collection type.
- Parameters:
- coll- the decorated- Collection.
- keyTransformer- the- Transformerfor generating index keys.
- Returns:
- the created IndexedCollection.
 
- 
uniqueIndexedCollectionpublic static <K,C> IndexedCollection<K,C> uniqueIndexedCollection(Collection<C> coll, Transformer<C, K> keyTransformer) Create anIndexedCollectionfor a unique index.If an element is added, which maps to an existing key, an IllegalArgumentExceptionwill be thrown.- Type Parameters:
- K- the index object type.
- C- the collection type.
- Parameters:
- coll- the decorated- Collection.
- keyTransformer- the- Transformerfor generating index keys.
- Returns:
- the created IndexedCollection.
 
- 
add- Specified by:
- addin interface- Collection<K>
- Overrides:
- addin class- AbstractCollectionDecorator<C>
- Throws:
- IllegalArgumentException- if the object maps to an existing key and the index enforces a uniqueness constraint
 
- 
addAll- Specified by:
- addAllin interface- Collection<K>
- Overrides:
- addAllin class- AbstractCollectionDecorator<C>
 
- 
clear- Specified by:
- clearin interface- Collection<K>
- Overrides:
- clearin class- AbstractCollectionDecorator<C>
 
- 
containsNote: uses the index for fast lookup - Specified by:
- containsin interface- Collection<K>
- Overrides:
- containsin class- AbstractCollectionDecorator<C>
 
- 
containsAllNote: uses the index for fast lookup - Specified by:
- containsAllin interface- Collection<K>
- Overrides:
- containsAllin class- AbstractCollectionDecorator<C>
 
- 
getGets the element associated with the given 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).- Parameters:
- key- key to look up
- Returns:
- element found
- See Also:
 
- 
reindexClears the index and re-indexes the entire decoratedCollection.
- 
remove- Specified by:
- removein interface- Collection<K>
- Overrides:
- removein class- AbstractCollectionDecorator<C>
 
- 
removeAll- Specified by:
- removeAllin interface- Collection<K>
- Overrides:
- removeAllin class- AbstractCollectionDecorator<C>
 
- 
removeIf- Specified by:
- removeIfin interface- Collection<K>
- Overrides:
- removeIfin class- AbstractCollectionDecorator<C>
- Since:
- 4.4
 
- 
retainAll- Specified by:
- retainAllin interface- Collection<K>
- Overrides:
- retainAllin class- AbstractCollectionDecorator<C>
 
- 
valuesGets all elements associated with the given key.- Parameters:
- key- key to look up
- Returns:
- a collection of elements found, or null if contains(key) == false
 
 
-