Class NullMap<K,V>

java.lang.Object
com.twelvemonkeys.util.NullMap<K,V>
All Implemented Interfaces:
Serializable, Map<K,V>

public final class NullMap<K,V> extends Object implements Map<K,V>, Serializable
An (immutable) empty Map, that supports all Map operations without throwing exceptions (in contrast to Collections.EMPTY_MAP that will throw exceptions on put/remove).

NOTE: This is not a general purpose Map implementation, as the put and putAll methods will not modify the map. Instances of this class will always be an empty map.

Version:
$Id: com/twelvemonkeys/util/NullMap.java#2 $
Author:
Harald Kuhr
See Also:
  • Constructor Details

    • NullMap

      public NullMap()
  • Method Details

    • size

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

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

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

      public final boolean containsKey(Object pKey)
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public final boolean containsValue(Object pValue)
      Specified by:
      containsValue in interface Map<K,V>
    • values

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

      public final void putAll(Map pMap)
      Specified by:
      putAll in interface Map<K,V>
    • entrySet

      public final Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
    • keySet

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

      public final V get(Object pKey)
      Specified by:
      get in interface Map<K,V>
    • remove

      public final V remove(Object pKey)
      Specified by:
      remove in interface Map<K,V>
    • put

      public final V put(Object pKey, Object pValue)
      Specified by:
      put in interface Map<K,V>
    • equals

      public boolean equals(Object pOther)
      Tests the given object for equality (wether it is also an empty Map). This is consistent with the standard Map implementations of the Java Collections Framework.
      Specified by:
      equals in interface Map<K,V>
      Overrides:
      equals in class Object
      Parameters:
      pOther - the object to compare with
      Returns:
      true if pOther is an empty Map, otherwise false
    • hashCode

      public int hashCode()
      Returns the hashCode of the empty map, 0. This is consistent with the standard Map implementations of the Java Collections Framework.
      Specified by:
      hashCode in interface Map<K,V>
      Overrides:
      hashCode in class Object
      Returns:
      0, always