Class DecoratorIDedMappedList<K,​E extends IDed<K>>

  • All Implemented Interfaces:
    MappedList<K,​E>, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>

    public class DecoratorIDedMappedList<K,​E extends IDed<K>>
    extends ListDecorator<E>
    implements MappedList<K,​E>
    A list that allows quick lookup of IDed objects. This list will give unpredictable results if multiple objects with the same ID are added to the list.
    Author:
    Garret Wilson
    Implementation Specification:
    This list does not support null values.
    • Constructor Summary

      Constructors 
      Constructor Description
      DecoratorIDedMappedList​(java.util.Map<K,​E> map, java.util.List<E> list)
      Decorates the given list by mapping its values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, E element)  
      boolean add​(E o)  
      boolean addAll​(int index, java.util.Collection<? extends E> c)  
      boolean addAll​(java.util.Collection<? extends E> c)  
      void clear()  
      boolean containsKey​(java.lang.Object key)
      Returns true if this map contains a mapping for the specified key.
      E get​(java.lang.Object key)
      Returns the value to which this map maps the specified key.
      protected java.util.Map<K,​E> getMap()  
      E remove​(int index)  
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> c)  
      E removeKey​(java.lang.Object key)
      Removes the value from the list mapped to the given key value.
      boolean retainAll​(java.util.Collection<?> c)  
      E set​(int index, E element)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, replaceAll, size, sort, spliterator, subList, toArray, toArray
    • Constructor Detail

      • DecoratorIDedMappedList

        public DecoratorIDedMappedList​(java.util.Map<K,​E> map,
                                       java.util.List<E> list)
        Decorates the given list by mapping its values. Any values present in the map will be removed. Any values already present in the list will be mapped.
        Parameters:
        map - The map which stores the ID to list item associations.
        list - The list in which to store the list items.
        Throws:
        java.lang.IllegalArgumentException - if more than one item with the same ID exists in the list.
    • Method Detail

      • getMap

        protected java.util.Map<K,​E> getMap()
        Returns:
        The map associating IDs with list items.
      • add

        public boolean add​(E o)
        Specified by:
        add in interface java.util.Collection<K>
        Specified by:
        add in interface java.util.List<K>
        Overrides:
        add in class CollectionDecorator<E extends IDed<K>>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<K>
        Specified by:
        remove in interface java.util.List<K>
        Overrides:
        remove in class CollectionDecorator<E extends IDed<K>>
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface java.util.Collection<K>
        Specified by:
        addAll in interface java.util.List<K>
        Overrides:
        addAll in class CollectionDecorator<E extends IDed<K>>
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends E> c)
        Specified by:
        addAll in interface java.util.List<K>
        Overrides:
        addAll in class ListDecorator<E extends IDed<K>>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<K>
        Specified by:
        removeAll in interface java.util.List<K>
        Overrides:
        removeAll in class CollectionDecorator<E extends IDed<K>>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<K>
        Specified by:
        retainAll in interface java.util.List<K>
        Overrides:
        retainAll in class CollectionDecorator<E extends IDed<K>>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<K>
        Specified by:
        clear in interface java.util.List<K>
        Overrides:
        clear in class CollectionDecorator<E extends IDed<K>>
      • set

        public E set​(int index,
                     E element)
        Specified by:
        set in interface java.util.List<K>
        Overrides:
        set in class ListDecorator<E extends IDed<K>>
      • add

        public void add​(int index,
                        E element)
        Specified by:
        add in interface java.util.List<K>
        Overrides:
        add in class ListDecorator<E extends IDed<K>>
      • remove

        public E remove​(int index)
        Specified by:
        remove in interface java.util.List<K>
        Overrides:
        remove in class ListDecorator<E extends IDed<K>>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Description copied from interface: MappedList
        Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)
        Specified by:
        containsKey in interface MappedList<K,​E extends IDed<K>>
        Parameters:
        key - key whose presence in this map is to be tested.
        Returns:
        true if this map contains a mapping for the specified key.
      • get

        public E get​(java.lang.Object key)
        Description copied from interface: MappedList
        Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

        More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

        Specified by:
        get in interface MappedList<K,​E extends IDed<K>>
        Parameters:
        key - key whose associated value is to be returned.
        Returns:
        the value to which this map maps the specified key, or null if the map contains no mapping for this key.
        See Also:
        MappedList.containsKey(Object)
      • removeKey

        public E removeKey​(java.lang.Object key)
        Description copied from interface: MappedList
        Removes the value from the list mapped to the given key value.
        Specified by:
        removeKey in interface MappedList<K,​E extends IDed<K>>
        Parameters:
        key - The key whose mapping is to be removed from the map and whose corresponding value is to be removed from the list.
        Returns:
        previous value associated with specified key, or null if there was no mapping for key.