Interface LocalMap<K,V>
- All Superinterfaces:
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.
- Author:
- Tim Fox
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all entries in the mapvoidclose()Close and release the mapAttempts to compute a mapping for the specified key and its current mapped value (ornullif there is no current mapping).computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull.computeIfPresent(K key, 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.booleancontainsKey(Object key) Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object value) Returns @{code true} if this map maps one or more keys to the specified value.entrySet()Returns aSetview of the mappings contained in this map.voidforEach(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.Get a value from the mapgetOrDefault(Object key, V defaultValue) Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.booleanisEmpty()keySet()If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.Put an entry in the mapvoidCopies all of the mappings from the specified map to this map.putIfAbsent(K key, V value) Put the entry only if there is no existing entry for that keyRemove an entry from the mapbooleanRemoves the entry for the specified key only if it is currently mapped to the specified value.booleanremoveIfPresent(K key, V value) Remove the entry only if there is an entry with the specified key and value.Replace the entry only if there is an existing entry with the keybooleanReplaces the entry for the specified key only if currently mapped to the specified value.voidreplaceAll(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.booleanreplaceIfPresent(K key, V oldValue, V newValue) Replace the entry only if there is an existing entry with the specified key and value.intsize()Get the size of the mapvalues()
-
Method Details
-
get
-
put
-
remove
-
clear
-
size
-
isEmpty
-
putIfAbsent
-
removeIfPresent
Remove the entry only if there is an entry with the specified key and value.This method is the poyglot version of
remove(Object, Object).- Parameters:
key- the keyvalue- the value- Returns:
- true if removed
-
replaceIfPresent
Replace the entry only if there is an existing entry with the specified key and value.This method is the polyglot version of
replace(Object, Object, Object).- Parameters:
key- the keyoldValue- the old valuenewValue- the new value- Returns:
- true if removed
-
replace
-
close
void close()Close and release the map -
keySet
-
values
-
compute
Attempts to compute a mapping for the specified key and its current mapped value (ornullif 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. -
computeIfAbsent
If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull.If the function returns
nullno mapping is recorded. If the function itself throws an (unchecked) exception, the exception is rethrown, and no mapping is recorded.- Specified by:
computeIfAbsentin interfaceMap<K,V> - Parameters:
key- key with which the specified value is to be associatedmappingFunction- the function to compute a value- Returns:
- the current (existing or computed) value associated with the specified key, or null if the computed value is null
-
computeIfPresent
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.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.- Specified by:
computeIfPresentin interfaceMap<K,V> - Parameters:
key- key with which the specified value is to be associatedremappingFunction- the function to compute a value- Returns:
- the new value associated with the specified key, or null if none
-
containsKey
Returnstrueif this map contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMap<K,V> - Parameters:
key- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key
-
containsValue
Returns @{code true} if this map maps one or more keys to the specified value.- Specified by:
containsValuein interfaceMap<K,V> - Parameters:
value- value whose presence in this map is to be tested- Returns:
- @{code true} if this map maps one or more keys to the specified value
-
entrySet
Returns aSetview of the mappings contained in this map.Unlike the default
Mapimplementation, 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). -
forEach
Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.Exceptions thrown by the action are relayed to the caller.
-
getOrDefault
Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.- Specified by:
getOrDefaultin interfaceMap<K,V> - Parameters:
key- the key whose associated value is to be returneddefaultValue- the default mapping of the key- Returns:
- the value to which the specified key is mapped, or
defaultValueif this map contains no mapping for the key
-
merge
If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result isnull. This method may be of use when combining multiple mapped values for a key.- Specified by:
mergein interfaceMap<K,V> - Parameters:
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 present- Returns:
- the new value associated with the specified key, or null if no value is associated with the key
-
putAll
Copies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of callingput(k, v)on this map once for each mapping from keykto valuevin the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. -
remove
Removes the entry for the specified key only if it is currently mapped to the specified value. -
replace
Replaces the entry for the specified key only if currently mapped to the specified value. -
replaceAll
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. Exceptions thrown by the function are relayed to the caller.- Specified by:
replaceAllin interfaceMap<K,V> - Parameters:
function- the function to apply to each entry
-