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
public abstract class ImmutableAbstractMap<K,V> extends Object implements ImmutableMap<K,V>
Copyright (c) 2016-2020 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, Wouter Schakel
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.djutils.immutablecollections.ImmutableMap
ImmutableMap.ImmutableEntry<K,V> -
Field Summary
Fields Modifier and Type Field Description protected ImmutableCollection<V>cachedValuesthe cached values.protected ImmutablecopyOrWrapCOPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection. -
Constructor Summary
Constructors Modifier Constructor Description protectedImmutableAbstractMap(Map<K,V> map, Immutable copyOrWrap)Construct an abstract immutable map. -
Method Summary
Modifier and Type Method Description booleancontainsKey(Object key)Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object value)Returnstrueif this map maps one or more keys to the specified value.booleanequals(Object obj)Force to redefine equals for the implementations of immutable collection classes.Vget(Object key)Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.protected Map<K,V>getUnderlyingMap()Return the raw underlying map.inthashCode()Force to redefine hashCode for the implementations of immutable collection classes.booleanisEmpty()Returnstrueif this immutable collection contains no elements.booleanisWrap()Return whether the internal storage is a wrapped pointer to the original map.intsize()Returns the number of elements in this immutable collection.ImmutableCollection<V>values()Returns aImmutableCollectionview of the values contained in this map.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods 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()Returns the number of elements in this immutable collection. If this immutable collection contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Specified by:
sizein interfaceImmutableMap<K,V>- Returns:
- the number of elements in this immutable collection
-
isEmpty
public final boolean isEmpty()Returnstrueif this immutable collection contains no elements.- Specified by:
isEmptyin interfaceImmutableMap<K,V>- Returns:
trueif this immutable collection contains no elements
-
containsKey
Returnstrueif this map contains a mapping for the specified key. More formally, returnstrueif and only if this map contains a mapping for a keyksuch that(key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)- Specified by:
containsKeyin interfaceImmutableMap<K,V>- Parameters:
key- Object; key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key
-
containsValue
Returnstrueif this map maps one or more keys to the specified value. More formally, returnstrueif and only if this map contains at least one mapping to a valuevsuch that(value==null ? v==null : value.equals(v)). This operation will probably require time linear in the map size for most implementations of theMapinterface.- Specified by:
containsValuein interfaceImmutableMap<K,V>- Parameters:
value- Object; value whose presence in this map is to be tested- Returns:
trueif this map maps one or more keys to the specified value
-
get
Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch 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
nulldoes not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull. ThecontainsKeyoperation may be used to distinguish these two cases.- Specified by:
getin 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
nullif this map contains no mapping for the key
-
values
Returns aImmutableCollectionview of the values contained in this map.- Specified by:
valuesin interfaceImmutableMap<K,V>- Returns:
- an immutable collection view of the values contained in this map
-
isWrap
public final boolean isWrap()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:
isWrapin interfaceImmutableMap<K,V>- Returns:
- boolean; whether the internal storage is a wrapped pointer to the original map
-
hashCode
public int hashCode()Force to redefine hashCode for the implementations of immutable collection classes. -
equals
Force to redefine equals for the implementations of immutable collection classes.
-