Class MapProxy<K,V>

java.lang.Object
eu.bandm.tools.util.nonnull.MapProxy<K,V>
All Implemented Interfaces:
Serializable, Map<K,V>
Direct Known Subclasses:
NonNullKeyMap.MyProxy, NonNullMap.MyProxy, NonNullValueMap.MyProxy

public abstract class MapProxy<K,V> extends Object implements Map<K,V>, Serializable
Implements a map by delegation to a peer object from the Java collection library.

Is used for nonNull maps, therefore the "put" methods (etc.) are implemented in the subclasses and left here abstract. This class implements more explicit delegations to the peer than minimally required by AbstractMap, for higher efficiency.

See Also:
  • Field Details

    • peer

      protected final Map<K,V> peer
      cf https://stackoverflow.com/questions/6433478/is-there-a-standard-java-list-implementation-that-doesnt-allow-adding-null-to-i
  • Constructor Details

    • MapProxy

      protected MapProxy(Map<K,V> peer)
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • asSorted

      public SortedMap<K,V> asSorted()
      Returns a sorted, unmodifiable view IFF the backing peer is a sorted map.
      Throws:
      UnsupportedOperationException - if the backing peer does not offer a sorted view.
    • 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>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Will be overridden for value checked maps. Java API doc says "[Map.entrySet()] does not support the add or addAll operations", so no checks are required on this level.
      Specified by:
      entrySet in interface Map<K,V>
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map<K,V>
      Overrides:
      equals in class Object
    • get

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

      public int hashCode()
      Specified by:
      hashCode in interface Map<K,V>
      Overrides:
      hashCode in class Object
    • isEmpty

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

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
    • remove

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

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

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>