Top Description Methods
io.vertx.core.shareddata

public Interface LocalMap<K, V>

extends Map<K, V>
Known Direct Implementers
io.vertx.core.shareddata.impl.LocalMapImpl
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.GenIgnore, .VertxGen, java.util.Collection, .Map, .Set, java.util.function.BiConsumer, .BiFunction, .Function

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 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
Shareable

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Redeclares java.util.Map.clear.

Clear all entries in the map

public void
close()

Close and release the map

public V

Returns:

the new value associated with the specified key, or null if none
compute
(K
key with which the specified value is to be associated
key
,
BiFunction<? super K, ? super V, ? extends V>
the function to compute a value
remappingFunction
)

Redeclares as abstract: java.util.Map.compute.

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).

public V

Returns:

the current (existing or computed) value associated with the specified key, or null if the computed value is null
computeIfAbsent
(K
key with which the specified value is to be associated
key
,
Function<? super K, ? extends V>
the function to compute a value
mappingFunction
)

Redeclares as abstract: java.util.Map.computeIfAbsent.

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.

public V

Returns:

the new value associated with the specified key, or null if none
computeIfPresent
(K
key with which the specified value is to be associated
key
,
BiFunction<? super K, ? super V, ? extends V>
the function to compute a value
remappingFunction
)

Redeclares as abstract: java.util.Map.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.

public boolean

Returns:

true if this map contains a mapping for the specified key
containsKey
(Object
key whose presence in this map is to be tested
key
)

Redeclares java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean

Returns:

@{code true} if this map maps one or more keys to the specified value
containsValue
(Object
value whose presence in this map is to be tested
value
)

Redeclares java.util.Map.containsValue.

Returns @{code true} if this map maps one or more keys to the specified value.

public Set<Map.Entry<K, V>>

Returns:

a set view of the mappings contained in this map
entrySet
()

Redeclares java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public void
forEach(BiConsumer<? super K, ? super V>
The action to be performed for each entry
action
)

Redeclares as abstract: java.util.Map.forEach.

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.

public V

Returns:

the value, or null if none
get
(Object
the key
key
)

Redeclares java.util.Map.get.

Get a value from the map

public V

Returns:

the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key
getOrDefault
(Object
the key whose associated value is to be returned
key
,
V
the default mapping of the key
defaultValue
)

Redeclares as abstract: java.util.Map.getOrDefault.

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

public boolean

Returns:

true if there are zero entries in the map
isEmpty
()

Redeclares java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public Set<K>

Returns:

the set of keys in the map
keySet
()

Redeclares java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

public V

Returns:

the new value associated with the specified key, or null if no value is associated with the key
merge
(K
key with which the resulting value is to be associated
key
,
V
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 key
value
,
BiFunction<? super V, ? super V, ? extends V>
the function to recompute a value if present
remappingFunction
)

Redeclares as abstract: java.util.Map.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.

public V

Returns:

return the old value, or null if none
put
(K
the key
key
,
V
the value
value
)

Redeclares java.util.Map.put.

Put an entry in the map

public void
putAll(Map<? extends K, ? extends V>
mappings to be stored in this map
m
)

Redeclares java.util.Map.putAll.

Copies all of the mappings from the specified map to this map.

public V

Returns:

the old value or null, if none
putIfAbsent
(K
the key
key
,
V
the value
value
)

Redeclares as abstract: java.util.Map.putIfAbsent.

Put the entry only if there is no existing entry for that key

public V

Returns:

the old value
remove
(Object
the key
key
)

Redeclares java.util.Map.remove.

Remove an entry from the map

public boolean

Returns:

true if the value was removed
remove
(Object
key with which the specified value is associated
key
,
Object
value expected to be associated with the specified key
value
)

Redeclares as abstract: java.util.Map.remove.

Removes the entry for the specified key only if it is currently mapped to the specified value.

public boolean

Returns:

true if removed
removeIfPresent
(K
the key
key
,
V
the value
value
)

Remove the entry only if there is an entry with the specified key and value.

public V

Returns:

the old value
replace
(K
the key
key
,
V
the new value
value
)

Redeclares as abstract: java.util.Map.replace.

Replace the entry only if there is an existing entry with the key

public boolean

Returns:

true if the value was replaced
replace
(K
key with which the specified value is associated
key
,
V
value expected to be associated with the specified key
oldValue
,
V
value to be associated with the specified key
newValue
)

Redeclares as abstract: java.util.Map.replace.

Replaces the entry for the specified key only if currently mapped to the specified value.

public void
replaceAll(BiFunction<? super K, ? super V, ? extends V>
the function to apply to each entry
function
)

Redeclares as abstract: java.util.Map.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.

public boolean

Returns:

true if removed
replaceIfPresent
(K
the key
key
,
V
the old value
oldValue
,
V
the new value
newValue
)

Replace the entry only if there is an existing entry with the specified key and value.

public int

Returns:

the number of entries in the map
size
()

Redeclares java.util.Map.size.

Get the size of the map

public Collection<V>

Returns:

the set of values in the map
values
()

Redeclares java.util.Map.values.

Returns a Collection view of the values contained in this map.

Inherited from java.util.Map:
copyOfentryequalshashCodeofofofofofofofofofofofofEntries

Method Detail

clearback to summary
public void clear()

Redeclares java.util.Map.clear.

Clear all entries in the map

closeback to summary
public void close()

Close and release the map

computeback to summary
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)

Redeclares as abstract: java.util.Map.compute.

Attempts to compute a mapping for the specified key and its current mapped value (or 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.

Parameters
key:K

key with which the specified value is to be associated

remappingFunction:BiFunction<? super K, ? super V, ? extends V>

the function to compute a value

Returns:V

the new value associated with the specified key, or null if none

Annotations
@GenIgnore
@Override
computeIfAbsentback to summary
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction)

Redeclares as abstract: java.util.Map.computeIfAbsent.

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.

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.

Parameters
key:K

key with which the specified value is to be associated

mappingFunction:Function<? super K, ? extends V>

the function to compute a value

Returns:V

the current (existing or computed) value associated with the specified key, or null if the computed value is null

Annotations
@GenIgnore
@Override
computeIfPresentback to summary
public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)

Redeclares as abstract: java.util.Map.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.

Parameters
key:K

key with which the specified value is to be associated

remappingFunction:BiFunction<? super K, ? super V, ? extends V>

the function to compute a value

Returns:V

the new value associated with the specified key, or null if none

Annotations
@GenIgnore
@Override
containsKeyback to summary
public boolean containsKey(Object key)

Redeclares java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

Parameters
key:Object

key whose presence in this map is to be tested

Returns:boolean

true if this map contains a mapping for the specified key

Annotations
@Override
containsValueback to summary
public boolean containsValue(Object value)

Redeclares java.util.Map.containsValue.

Returns @{code true} if this map maps one or more keys to the specified value.

Parameters
value:Object

value whose presence in this map is to be tested

Returns:boolean

@{code true} if this map maps one or more keys to the specified value

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Redeclares java.util.Map.entrySet.

Returns a 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 (java.util.Map.Entry#setValue(Object) is not supported).

Returns:Set<Map.Entry<K, V>>

a set view of the mappings contained in this map

Annotations
@GenIgnore
@Override
forEachback to summary
public void forEach(BiConsumer<? super K, ? super V> action)

Redeclares as abstract: java.util.Map.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.

Parameters
action:BiConsumer<? super K, ? super V>

The action to be performed for each entry

Annotations
@GenIgnore
@Override
getback to summary
public V get(Object key)

Redeclares java.util.Map.get.

Get a value from the map

Parameters
key:Object

the key

Returns:V

the value, or null if none

getOrDefaultback to summary
public V getOrDefault(Object key, V defaultValue)

Redeclares as abstract: java.util.Map.getOrDefault.

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

Parameters
key:Object

the key whose associated value is to be returned

defaultValue:V

the default mapping of the key

Returns:V

the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Redeclares java.util.Map.isEmpty.

Doc from java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

Returns:boolean

true if there are zero entries in the map

keySetback to summary
public Set<K> keySet()

Redeclares java.util.Map.keySet.

Doc from java.util.Map.keySet.

Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:Set<K>

the set of keys in the map

Annotations
@GenIgnore
mergeback to summary
public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)

Redeclares as abstract: java.util.Map.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 is null. This method may be of use when combining multiple mapped values for a key.

Parameters
key:K

key with which the resulting value is to be associated

value:V

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 key

remappingFunction:BiFunction<? super V, ? super V, ? extends V>

the function to recompute a value if present

Returns:V

the new value associated with the specified key, or null if no value is associated with the key

Annotations
@GenIgnore
@Override
putback to summary
public V put(K key, V value)

Redeclares java.util.Map.put.

Put an entry in the map

Parameters
key:K

the key

value:V

the value

Returns:V

return the old value, or null if none

putAllback to summary
public void putAll(Map<? extends K, ? extends V> m)

Redeclares java.util.Map.putAll.

Copies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of calling 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.

Parameters
m:Map<? extends K, ? extends V>

mappings to be stored in this map

Annotations
@GenIgnore
@Override
putIfAbsentback to summary
public V putIfAbsent(K key, V value)

Redeclares as abstract: java.util.Map.putIfAbsent.

Put the entry only if there is no existing entry for that key

Parameters
key:K

the key

value:V

the value

Returns:V

the old value or null, if none

removeback to summary
public V remove(Object key)

Redeclares java.util.Map.remove.

Remove an entry from the map

Parameters
key:Object

the key

Returns:V

the old value

removeback to summary
public boolean remove(Object key, Object value)

Redeclares as abstract: java.util.Map.remove.

Removes the entry for the specified key only if it is currently mapped to the specified value.

Parameters
key:Object

key with which the specified value is associated

value:Object

value expected to be associated with the specified key

Returns:boolean

true if the value was removed

Annotations
@Override
@GenIgnore
removeIfPresentback to summary
public 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:K

the key

value:V

the value

Returns:boolean

true if removed

replaceback to summary
public V replace(K key, V value)

Redeclares as abstract: java.util.Map.replace.

Replace the entry only if there is an existing entry with the key

Parameters
key:K

the key

value:V

the new value

Returns:V

the old value

replaceback to summary
public boolean replace(K key, V oldValue, V newValue)

Redeclares as abstract: java.util.Map.replace.

Replaces the entry for the specified key only if currently mapped to the specified value.

Parameters
key:K

key with which the specified value is associated

oldValue:V

value expected to be associated with the specified key

newValue:V

value to be associated with the specified key

Returns:boolean

true if the value was replaced

Annotations
@Override
@GenIgnore
replaceAllback to summary
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)

Redeclares as abstract: java.util.Map.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.

Parameters
function:BiFunction<? super K, ? super V, ? extends V>

the function to apply to each entry

Annotations
@GenIgnore
@Override
replaceIfPresentback to summary
public 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:K

the key

oldValue:V

the old value

newValue:V

the new value

Returns:boolean

true if removed

sizeback to summary
public int size()

Redeclares java.util.Map.size.

Get the size of the map

Returns:int

the number of entries in the map

valuesback to summary
public Collection<V> values()

Redeclares java.util.Map.values.

Doc from java.util.Map.values.

Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Collection<V>

the set of values in the map

Annotations
@GenIgnore