Package com.activeviam.collections
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 TypeMethodDescriptionbooleancontainsKey(K key) Checks if an entry with the given key is in the map.entrySet()Give the list of entries from this map.default voidforEach(BiConsumer<K, V> consumer) Executes a block of code for each key/value pair in this map.Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.default VgetOrDefault(K key, V defaultValue) Gets a value from the map if the key exists or a default value instead.booleanisEmpty()Indicates if this map is empty.default booleanIndicates if this map is not empty.keys()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 content and return itself.Create a new map having the same values than this map plus a new value mapped to a given key.putAll(ImmutableMap<K, V> values) Create a new map having the same values than this map plus values from another map.Create a new map having the same content than this map minus a given key.intsize()Give the size of this map.toMap()Create a read-only java util map with the same content than this map.default PropertiesConverts to a Properties instance.values()Give the list of values from this map.
-
Method Details
-
get
Returns the value to which the specified key is mapped, ornullif 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
nullif this map contains no mapping for the key.
-
put
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
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
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
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
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
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
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
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
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
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.
-