Package com.twelvemonkeys.util
Class NullMap<K,V>
java.lang.Object
com.twelvemonkeys.util.NullMap<K,V>
- All Implemented Interfaces:
Serializable
,Map<K,
V>
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:
-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
clear()
final boolean
containsKey
(Object pKey) final boolean
containsValue
(Object pValue) entrySet()
boolean
Tests the given object for equality (wether it is also an emptyMap
).final V
int
hashCode()
Returns thehashCode
of the empty map,0
.final boolean
isEmpty()
keySet()
final V
final void
final V
final int
size()
final Collection<V>
values()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
NullMap
public NullMap()
-
-
Method Details
-
size
public final int size() -
clear
public final void clear() -
isEmpty
public final boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
values
-
putAll
-
entrySet
-
keySet
-
get
-
remove
-
put
-
equals
Tests the given object for equality (wether it is also an emptyMap
). This is consistent with the standardMap
implementations of the Java Collections Framework. -
hashCode
public int hashCode()Returns thehashCode
of the empty map,0
. This is consistent with the standardMap
implementations of the Java Collections Framework.
-