public interface LocalMap<K,V> extends Map<K,V>
By default the map allows immutable keys and values.
Custom keys and values should implement Shareable
interface. The map returns their copies.
This ensures there is no shared access to mutable state from different threads (e.g. different event loops) in the Vert.x instance, and means you don't have to protect access to that state using synchronization or locks.
Since the version 3.4, this class extends the Map
interface. However some methods are only accessible in Java.
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear all entries in the map
|
void |
close()
Close and release the map
|
V |
compute(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
Attempts to compute a mapping for the specified key and its current
mapped value (or
null if there is no current mapping). |
V |
computeIfAbsent(K key,
java.util.function.Function<? super K,? extends V> mappingFunction)
If the specified key is not already associated with a value (or is mapped
to
null ), attempts to compute its value using the given mapping
function and enters it into this map unless null . |
V |
computeIfPresent(K key,
java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
If the value for the specified key is present and non-null, attempts to
compute a new mapping given the key and its current mapped value.
|
boolean |
containsKey(Object key)
Returns
true if this map contains a mapping for the specified
key. |
boolean |
containsValue(Object value)
Returns @{code true} if this map maps one or more keys to the
specified value.
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a
Set view of the mappings contained in this map. |
void |
forEach(java.util.function.BiConsumer<? super K,? super V> action)
Performs the given action for each entry in this map until all entries
have been processed or the action throws an exception.
|
V |
get(Object key)
Get a value from the map
|
V |
getOrDefault(Object key,
V defaultValue)
Returns the value to which the specified key is mapped, or
defaultValue if this map contains no mapping for the key. |
boolean |
isEmpty() |
Set<K> |
keySet() |
V |
merge(K key,
V value,
java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
If the specified key is not already associated with a value or is
associated with null, associates it with the given non-null value.
|
V |
put(K key,
V value)
Put an entry in the map
|
void |
putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this map.
|
V |
putIfAbsent(K key,
V value)
Put the entry only if there is no existing entry for that key
|
V |
remove(Object key)
Remove an entry from the map
|
boolean |
remove(Object key,
Object value)
Removes the entry for the specified key only if it is currently
mapped to the specified value.
|
boolean |
removeIfPresent(K key,
V value)
Remove the entry only if there is an entry with the specified key and value.
|
V |
replace(K key,
V value)
Replace the entry only if there is an existing entry with the key
|
boolean |
replace(K key,
V oldValue,
V newValue)
Replaces the entry for the specified key only if currently
mapped to the specified value.
|
void |
replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)
Replaces each entry's value with the result of invoking the given
function on that entry until all entries have been processed or the
function throws an exception.
|
boolean |
replaceIfPresent(K key,
V oldValue,
V newValue)
Replace the entry only if there is an existing entry with the specified key and value.
|
int |
size()
Get the size of the map
|
Collection<V> |
values() |
int size()
boolean isEmpty()
V putIfAbsent(K key, V value)
putIfAbsent
in interface Map<K,V>
key
- the keyvalue
- the valueboolean removeIfPresent(K key, V value)
This method is the poyglot version of remove(Object, Object)
.
key
- the keyvalue
- the valueboolean replaceIfPresent(K key, V oldValue, V newValue)
This method is the polyglot version of replace(Object, Object, Object)
.
key
- the keyoldValue
- the old valuenewValue
- the new valuevoid close()
Collection<V> values()
V compute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
null
if there is no current mapping).
If the function returns null
, the mapping is removed (or
remains absent if initially absent). If the function itself throws an
(unchecked) exception, the exception is rethrown, and the current mapping
is left unchanged.
V computeIfAbsent(K key, java.util.function.Function<? super K,? extends V> mappingFunction)
null
), attempts to compute its value using the given mapping
function and enters it into this map unless null
.
If the function returns null
no mapping is recorded. If
the function itself throws an (unchecked) exception, the
exception is rethrown, and no mapping is recorded.
computeIfAbsent
in interface Map<K,V>
key
- key with which the specified value is to be associatedmappingFunction
- the function to compute a valueV computeIfPresent(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)
If the function returns null
, the mapping is removed. If the
function itself throws an (unchecked) exception, the exception is
rethrown, and the current mapping is left unchanged.
computeIfPresent
in interface Map<K,V>
key
- key with which the specified value is to be associatedremappingFunction
- the function to compute a valueboolean containsKey(Object key)
true
if this map contains a mapping for the specified
key.containsKey
in interface Map<K,V>
key
- key whose presence in this map is to be testedtrue
if this map contains a mapping for the specified keyboolean containsValue(Object value)
containsValue
in interface Map<K,V>
value
- value whose presence in this map is to be testedSet<Map.Entry<K,V>> entrySet()
Set
view of the mappings contained in this map.
Unlike the default Map
implementation, the set is not backed by the map. So changes
made to the map are not reflected in the set. Entries added or remove to the set are not reflected to the map.
In addition, the entries are not modifiable (Map.Entry.setValue(Object)
is not supported).
void forEach(java.util.function.BiConsumer<? super K,? super V> action)
Exceptions thrown by the action are relayed to the caller.
V getOrDefault(Object key, V defaultValue)
defaultValue
if this map contains no mapping for the key.getOrDefault
in interface Map<K,V>
key
- the key whose associated value is to be returneddefaultValue
- the default mapping of the keydefaultValue
if this map contains no mapping
for the keyV merge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
null
. This
method may be of use when combining multiple mapped values for a key.merge
in interface Map<K,V>
key
- key with which the resulting value is to be associatedvalue
- the non-null value to be merged with the existing value
associated with the key or, if no existing value or a null value
is associated with the key, to be associated with the keyremappingFunction
- the function to recompute a value if presentvoid putAll(Map<? extends K,? extends V> m)
put(k, v)
on this map once for each mapping from key k
to value
v
in the specified map. The behavior of this operation is undefined if the specified map is modified
while the operation is in progress.boolean remove(Object key, Object value)
boolean replace(K key, V oldValue, V newValue)
void replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)
replaceAll
in interface Map<K,V>
function
- the function to apply to each entryCopyright © 2024 Eclipse. All rights reserved.