Class ImmutableHashMap<K,​V>

java.lang.Object
org.djutils.immutablecollections.ImmutableAbstractMap<K,​V>
org.djutils.immutablecollections.ImmutableHashMap<K,​V>
Type Parameters:
K - the key type of content of this Map
V - the value type of content of this Map
All Implemented Interfaces:
Serializable, ImmutableMap<K,​V>

public class ImmutableHashMap<K,​V>
extends ImmutableAbstractMap<K,​V>
An immutable wrapper for a HashMap.

Copyright (c) 2016-2019 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
  • Constructor Details

    • ImmutableHashMap

      public ImmutableHashMap​(Map<K,​V> map)
      Parameters:
      map - Map<K,V>; the map to use for the immutable map.
    • ImmutableHashMap

      public ImmutableHashMap​(Map<K,​V> map, Immutable copyOrWrap)
      Parameters:
      map - Map<K,V>; the map to use for the immutable map.
      copyOrWrap - COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection
    • ImmutableHashMap

      public ImmutableHashMap​(ImmutableAbstractMap<K,​V> immutableMap)
      Parameters:
      immutableMap - ImmutableAbstractMap<K,V>; the map to use for the immutable map.
    • ImmutableHashMap

      public ImmutableHashMap​(ImmutableAbstractMap<K,​V> immutableMap, Immutable copyOrWrap)
      Parameters:
      immutableMap - ImmutableAbstractMap<K,V>; the map to use for the immutable map.
      copyOrWrap - COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection
  • Method Details

    • getMap

      protected final Map<K,​V> getMap()
      Prepare the map of the right type for use a subclass. Implement e.g. as follows:
       @Override
       protected HashMap<E> getMap()
       {
           return (HashMap<E>) super.getMap();
       }
       
      Overrides:
      getMap in class ImmutableAbstractMap<K,​V>
      Returns:
      the map of the right type for use a subclass
    • toMap

      public final Map<K,​V> toMap()
      Returns a modifiable copy of this immutable list.
      Returns:
      a modifiable copy of this immutable list.
    • keySet

      public final ImmutableSet<K> keySet()
      Returns a Set view of the keys contained in this map.
      Returns:
      an immutable set of the keys contained in this map
    • entrySet

      public ImmutableSet<ImmutableMap.ImmutableEntry<K,​V>> entrySet()
      Returns a Set view of the entries contained in this map.
      Returns:
      an immutable set of the entries contained in this map
    • toString

      public String toString()
      Force to redefine toString.
      Specified by:
      toString in interface ImmutableMap<K,​V>
      Overrides:
      toString in class Object
      Returns:
      String; a description of this immutable list