Class ListMap<K,​V>

  • Type Parameters:
    K - the class of keys for this map.
    V - the class of values for this map.
    All Implemented Interfaces:
    Map<K,​V>, SortedMap<K,​V>

    public final class ListMap<K,​V>
    extends Object
    implements SortedMap<K,​V>
    A SortedMap with ordering given by the ordering by which the keys are added. This is the Map corresponding with ListSet.

    Did not use AbstractMap, e.g. because keySet() shall return more than just a Set.

    Version:
    1.0
    Author:
    Ernst Reissner
    • Field Detail

      • keys

        private final ListSet<K> keys
        The set of keys of this ListMap.
      • values

        private final List<V> values
        The values of this map. The according keys are in keys.
      • valuesColl

        private final Collection<V> valuesColl
        The collection of values of this map returned by values(). Note that each ListMap has a single values collection.
      • keysSet

        private final SortedSet<K> keysSet
        The set of keys of this map returned by keySet(). Note that each ListMap has a single key set.
      • entrySet

        private final SortedSet<Map.Entry<K,​V>> entrySet
        The set of entries of this map returned by entrySet(). Note that each ListMap has a single entry set.
    • Constructor Detail

      • ListMap

        public ListMap()
        Creates an empty list map with key set 'ordered as added' as described by ListSet.sortedAsAdded().
      • ListMap

        public ListMap​(Map<K,​V> map)
        Creates an list map with the same key-value pairs as map and with ordering 'as added'. If no additional keys are added, this reflects the ordering given by iterating through the key set of map.
        See Also:
        map2keys(Map), map2values(Map)
      • ListMap

        private ListMap​(ListSet<K> keys,
                        List<V> values)
        Creates a list map defined by the given keys and values keys and values. A key and a value correspond iff their index coincides. Thus keys and values must have the same size. Note that the entries of keys differ pairwise, whereas this is not necessary for values.
        Parameters:
        keys - the set of keys as a ListSet.
        values - the collection of according values as a List with the same size as keys.
        Throws:
        IllegalArgumentException - if keys and values differ in size.
    • Method Detail

      • map2keys

        private static <K,​V> ListSet<K> map2keys​(Map<K,​V> map)
        Returns the key set of map as a ListSet with ordering 'ordered as added' as given by ListSet.sortedAsAdded(). This ordering reflects the ordering given by the iteration on the key set of map.
      • map2values

        private static <K,​V> List<V> map2values​(Map<K,​V> map)
        Returns the value collection of map as a List with ordering given by the iteration on the key set of map. Note that there is no documentation **** that this ordering is the same as the one of the value collection map#values(). ****
      • clear

        public void clear()
        Specified by:
        clear in interface Map<K,​V>
      • containsKey

        public boolean containsKey​(Object key)
        Specified by:
        containsKey in interface Map<K,​V>
      • get

        public V get​(Object key)
        Specified by:
        get in interface Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface Map<K,​V>
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface Map<K,​V>
      • putAll

        public void putAll​(Map<? extends K,​? extends V> other)
        Specified by:
        putAll in interface Map<K,​V>
      • remove

        public V remove​(Object key)
        Specified by:
        remove in interface Map<K,​V>
      • removeIdx

        private boolean removeIdx​(int idx)
      • size

        public int size()
        Specified by:
        size in interface Map<K,​V>
      • subMap

        ListMap<K,​V> subMap​(int fromIdx,
                                  int toIdx)
      • main

        public static void main​(String[] args)