Class ImmutableAbstractMap<K,V>
- Type Parameters:
K
- the key type of content of this MapV
- the value type of content of this Map
- All Implemented Interfaces:
Serializable
,ImmutableMap<K,
V>
- Direct Known Subclasses:
ImmutableHashMap
,ImmutableLinkedHashMap
,ImmutableTreeMap
Copyright (c) 2016-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.djutils.immutablecollections.ImmutableMap
ImmutableMap.ImmutableEntry<K,
V> -
Field Summary
Modifier and TypeFieldDescriptionprotected ImmutableCollection<V>
the cached values.protected final Immutable
COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection. -
Constructor Summary
ModifierConstructorDescriptionprotected
ImmutableAbstractMap
(Map<K, V> map, Immutable copyOrWrap) Construct an abstract immutable map. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
containsKey
(Object key) Returnstrue
if this map contains a mapping for the specified key.final boolean
containsValue
(Object value) Returnstrue
if this map maps one or more keys to the specified value.boolean
Force to redefine equals for the implementations of immutable collection classes.final V
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.Return the raw underlying map.int
hashCode()
Force to redefine hashCode for the implementations of immutable collection classes.final boolean
isEmpty()
Returnstrue
if this immutable collection contains no elements.final boolean
isWrap()
Return whether the internal storage is a wrapped pointer to the original map.final int
size()
Returns the number of elements in this immutable collection.values()
Returns aImmutableCollection
view of the values contained in this map.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.djutils.immutablecollections.ImmutableMap
entrySet, forEach, getOrDefault, isCopy, keySet, toMap, toString
-
Field Details
-
copyOrWrap
COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection. -
cachedValues
the cached values.
-
-
Constructor Details
-
ImmutableAbstractMap
Construct an abstract immutable map. Make sure that the argument is a safe copy of the map of the right type! Copying does not take place in the Abstract class!- Parameters:
map
- Map<K,V>; a safe copy of the map to use for the immutable mapcopyOrWrap
- Immutable; indicate whether the immutable is a copy or a wrap
-
-
Method Details
-
getUnderlyingMap
Return the raw underlying map.- Returns:
- Map<K, V>; the raw underlying map
-
size
public final int size()Description copied from interface:ImmutableMap
Returns the number of elements in this immutable collection. If this immutable collection contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Specified by:
size
in interfaceImmutableMap<K,
V> - Returns:
- the number of elements in this immutable collection
-
isEmpty
public final boolean isEmpty()Description copied from interface:ImmutableMap
Returnstrue
if this immutable collection contains no elements.- Specified by:
isEmpty
in interfaceImmutableMap<K,
V> - Returns:
true
if this immutable collection contains no elements
-
containsKey
Description copied from interface:ImmutableMap
Returnstrue
if this map contains a mapping for the specified key. More formally, returnstrue
if and only if this map contains a mapping for a keyk
such that(key==null ? k==null : key.equals(k))
. (There can be at most one such mapping.)- Specified by:
containsKey
in interfaceImmutableMap<K,
V> - Parameters:
key
- Object; key whose presence in this map is to be tested- Returns:
true
if this map contains a mapping for the specified key
-
containsValue
Description copied from interface:ImmutableMap
Returnstrue
if this map maps one or more keys to the specified value. More formally, returnstrue
if and only if this map contains at least one mapping to a valuev
such that(value==null ? v==null : value.equals(v))
. This operation will probably require time linear in the map size for most implementations of theMap
interface.- Specified by:
containsValue
in interfaceImmutableMap<K,
V> - Parameters:
value
- Object; value whose presence in this map is to be tested- Returns:
true
if this map maps one or more keys to the specified value
-
get
Description copied from interface:ImmutableMap
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.More formally, if this map contains a mapping from a key
k
to a valuev
such that(key==null ? k==null : key.equals(k))
, then this method returnsv
; otherwise it returnsnull
. (There can be at most one such mapping.)If this map permits null values, then 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 tonull
. ThecontainsKey
operation may be used to distinguish these two cases.- Specified by:
get
in interfaceImmutableMap<K,
V> - Parameters:
key
- Object; the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
null
if this map contains no mapping for the key
-
values
Description copied from interface:ImmutableMap
Returns aImmutableCollection
view of the values contained in this map.- Specified by:
values
in interfaceImmutableMap<K,
V> - Returns:
- an immutable collection view of the values contained in this map
-
isWrap
public final boolean isWrap()Description copied from interface:ImmutableMap
Return whether the internal storage is a wrapped pointer to the original map. If true, this means that anyone holding a pointer to this data structure can still change it. The users of the ImmutableMap itself can, however, not make any changes.- Specified by:
isWrap
in interfaceImmutableMap<K,
V> - Returns:
- boolean; whether the internal storage is a wrapped pointer to the original map
-
hashCode
public int hashCode()Description copied from interface:ImmutableMap
Force to redefine hashCode for the implementations of immutable collection classes. -
equals
Description copied from interface:ImmutableMap
Force to redefine equals for the implementations of immutable collection classes.
-