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

All Implemented Interfaces:
MappedList<K,E>, Iterable<E>, Collection<E>, 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 Details

    • DecoratorIDedMappedList

      public DecoratorIDedMappedList(Map<K,E> map, 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:
      IllegalArgumentException - if more than one item with the same ID exists in the list.
  • Method Details

    • getMap

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

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

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

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

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

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

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

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

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

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

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

      public boolean containsKey(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(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:
    • removeKey

      public E removeKey(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.