Interface LocalMap<K,V>
-
- All Superinterfaces:
Map<K,V>
public interface LocalMap<K,V> extends Map<K,V>
Local maps can be used to share data safely in a single Vert.x instance.By default the map allows immutable keys and values. Custom keys and values should implement
Shareableinterface. 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
Mapinterface. However some methods are only accessible in Java.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclear()Clear all entries in the mapvoidclose()Close and release the mapVcompute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)Attempts to compute a mapping for the specified key and its current mapped value (ornullif there is no current mapping).VcomputeIfAbsent(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.VcomputeIfPresent(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.Set<Map.Entry<K,V>>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.Vget(Object key)Get a value from the mapVgetOrDefault(Object key, V defaultValue)Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.booleanisEmpty()Set<K>keySet()Vmerge(K key, V value, 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.Vput(K key, V value)Put an entry in the mapvoidputAll(Map<? extends K,? extends V> m)Copies all of the mappings from the specified map to this map.VputIfAbsent(K key, V value)Put the entry only if there is no existing entry for that keyVremove(Object key)Remove an entry from the mapbooleanremove(Object key, Object value)Removes 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.Vreplace(K key, V value)Replace the entry only if there is an existing entry with the keybooleanreplace(K key, V oldValue, V newValue)Replaces 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 mapCollection<V>values()
-
-
-
Method Detail
-
size
int size()
Get the size of the map
-
isEmpty
boolean isEmpty()
-
putIfAbsent
V putIfAbsent(K key, V value)
Put the entry only if there is no existing entry for that key- Specified by:
putIfAbsentin interfaceMap<K,V>- Parameters:
key- the keyvalue- the value- Returns:
- the old value or null, if none
-
removeIfPresent
boolean removeIfPresent(K key, V value)
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
boolean replaceIfPresent(K key, V oldValue, V newValue)
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
V replace(K key, V value)
Replace the entry only if there is an existing entry with the key
-
close
void close()
Close and release the map
-
values
Collection<V> values()
-
compute
V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
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
V 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.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
V 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.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
boolean containsKey(Object key)
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
boolean containsValue(Object value)
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:
-
entrySet
Set<Map.Entry<K,V>> 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
void forEach(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.Exceptions thrown by the action are relayed to the caller.
-
getOrDefault
V getOrDefault(Object key, V defaultValue)
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
V merge(K key, V value, 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. 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
void putAll(Map<? extends K,? extends V> m)
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
boolean remove(Object key, Object value)
Removes the entry for the specified key only if it is currently mapped to the specified value.
-
replace
boolean replace(K key, V oldValue, V newValue)
Replaces the entry for the specified key only if currently mapped to the specified value.
-
replaceAll
void replaceAll(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. 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
-
-