Interface ImmutableMap<K,V>

Type Parameters:
K - The type of the keys.
V - The type of the values.
All Known Implementing Classes:
ImmutableHashMap

public interface ImmutableMap<K,V>
Immutable map with a functional API.
Author:
ActiveViam
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if an entry with the given key is in the map.
    Give the list of entries from this map.
    default void
    forEach(BiConsumer<K,V> consumer)
    Executes a block of code for each key/value pair in this map.
    get(K key)
    Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
    default V
    getOrDefault(K key, V defaultValue)
    Gets a value from the map if the key exists or a default value instead.
    boolean
    Indicates if this map is empty.
    default boolean
    Indicates if this map is not empty.
    Give the list of keys from this map.
    <ValueT> ImmutableMap<K,ValueT>
    mapValues(BiFunction<K,V,ValueT> mapper)
    Create a new map by applying a mapper to all the values contained in this map.
    print(String label)
    Print content and return itself.
    put(K key, V value)
    Create a new map having the same values than this map plus a new value mapped to a given key.
    Create a new map having the same values than this map plus values from another map.
    remove(K key)
    Create a new map having the same content than this map minus a given key.
    int
    Give the size of this map.
    Create a read-only java util map with the same content than this map.
    default Properties
    Converts to a Properties instance.
    Give the list of values from this map.
  • Method Details

    • get

      V get(K key)
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
      Parameters:
      key - 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.
    • put

      ImmutableMap<K,V> put(K key, V value)
      Create a new map having the same values than this map plus a new value mapped to a given key.
      Parameters:
      key - The key whose value should be changed.
      value - The new value to use for the key.
      Returns:
      The map with the changed value.
    • putAll

      ImmutableMap<K,V> putAll(ImmutableMap<K,V> values)
      Create a new map having the same values than this map plus values from another map.
      Parameters:
      values - The value to add to the map, they take precedence.
      Returns:
      The map with the changed values.
    • remove

      ImmutableMap<K,V> remove(K key)
      Create a new map having the same content than this map minus a given key.
      Parameters:
      key - The key that should not be mapped in the new map.
      Returns:
      The resulting map.
    • mapValues

      <ValueT> ImmutableMap<K,ValueT> mapValues(BiFunction<K,V,ValueT> mapper)
      Create a new map by applying a mapper to all the values contained in this map.
      Type Parameters:
      ValueT - The output type of the mapper function.
      Parameters:
      mapper - The mapper function that will be called on each value of this map.
      Returns:
      The map with the mapped values.
    • entrySet

      ImmutableSet<Map.Entry<K,V>> entrySet()
      Give the list of entries from this map.
      Returns:
      The list of entries from this map.
    • keys

      ImmutableSet<K> keys()
      Give the list of keys from this map.
      Returns:
      The list of keys from this map.
    • values

      ImmutableSet<V> values()
      Give the list of values from this map.
      Returns:
      The list of values from this map.
    • size

      int size()
      Give the size of this map.
      Returns:
      The size of this map.
    • print

      ImmutableMap<K,V> print(String label)
      Print content and return itself. Used for debugging.
      Parameters:
      label - A prefix printed to be able to quickly distinguish different printed statements.
      Returns:
      Itself.
    • toMap

      Map<K,V> toMap()
      Create a read-only java util map with the same content than this map.
      Returns:
      The map.
    • isEmpty

      boolean isEmpty()
      Indicates if this map is empty.
      Returns:
      True if the map is empty.
    • forEach

      default void forEach(BiConsumer<K,V> consumer)
      Executes a block of code for each key/value pair in this map.
      Parameters:
      consumer - The code to execute for each key and value.
    • toProperties

      default Properties toProperties()
      Converts to a Properties instance.
      Returns:
      The properties.
    • isNotEmpty

      default boolean isNotEmpty()
      Indicates if this map is not empty.
      Returns:
      True if this map contains at least one key/value pair.
    • containsKey

      boolean containsKey(K key)
      Checks if an entry with the given key is in the map.
      Parameters:
      key - The key to check.
      Returns:
      true if the map contains an entry with the given key.
    • getOrDefault

      default V getOrDefault(K key, V defaultValue)
      Gets a value from the map if the key exists or a default value instead.
      Parameters:
      key - The key to retrieve.
      defaultValue - The value to return if the key is not in the map.
      Returns:
      The value associated with the key or the default value if the key cannot be found.