Class 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>


    public class IndexedCollection<K,C>
    extends AbstractCollectionDecorator<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:
    Serialized Form
    • Constructor Detail

    • Method Detail

      • addAll

        public boolean addAll(Collection<? extends C> coll)
      • clear

        public void clear()
      • contains

        public boolean contains(Object object)

        Note: uses the index for fast lookup

      • containsAll

        public boolean containsAll(Collection<?> coll)

        Note: uses the index for fast lookup

      • get

        public C get(K key)
        Get 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:
        values(Object)
      • values

        public Collection<C> values(K key)
        Get 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
      • reindex

        public void reindex()
        Clears the index and re-indexes the entire decorated Collection.
      • remove

        public boolean remove(Object object)
      • removeAll

        public boolean removeAll(Collection<?> coll)
      • retainAll

        public boolean retainAll(Collection<?> coll)