Class LocalMap<K,V>

java.lang.Object
io.vertx.mutiny.core.shareddata.LocalMap<K,V>
All Implemented Interfaces:
MutinyDelegate

public class LocalMap<K,V> extends Object implements MutinyDelegate
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.

NOTE: This class has been automatically generated from the original non Mutiny-ified interface.

Author:
Tim Fox
See Also:
  • Shareable
  • LocalMap
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final TypeArg<LocalMap>
     
    final TypeArg<K>
     
    final TypeArg<V>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    LocalMap(io.vertx.core.shareddata.LocalMap<K,V> delegate)
    Create a new instance of LocalMap delegating to the given (non-null) instance of LocalMap.
    LocalMap(io.vertx.core.shareddata.LocalMap<K,V> delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
     
    LocalMap(Object delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear all entries in the map
    void
    Close and release the map
    boolean
    Returns true if this map contains a mapping for the specified key.
    boolean
    Returns @{code true} if this map maps one or more keys to the specified value.
    boolean
     
    get(Object key)
    Get a value from the map
    io.vertx.core.shareddata.LocalMap<K,V>
    Get the delegate instance.
    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.
    int
     
    boolean
     
    static <K, V> LocalMap<K,V>
    newInstance(io.vertx.core.shareddata.LocalMap<K,V> delegate)
    Creates a new instance of the LocalMap.
    static <K, V> LocalMap<K,V>
    newInstance(io.vertx.core.shareddata.LocalMap<K,V> delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
    Creates a new instance of the LocalMap.
    put(K key, V value)
    Put an entry in the map
    putIfAbsent(K key, V value)
    Put the entry only if there is no existing entry for that key
    Remove an entry from the map
    boolean
    removeIfPresent(K key, V value)
    Remove the entry only if there is an entry with the specified key and value.
    replace(K key, V value)
    Replace the entry only if there is an existing entry with the key
    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
    Get the size of the map
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • __TYPE_ARG

      public static final TypeArg<LocalMap> __TYPE_ARG
    • __typeArg_0

      public final TypeArg<K> __typeArg_0
    • __typeArg_1

      public final TypeArg<V> __typeArg_1
  • Constructor Details

    • LocalMap

      public LocalMap(io.vertx.core.shareddata.LocalMap<K,V> delegate)
      Create a new instance of LocalMap delegating to the given (non-null) instance of LocalMap.
    • LocalMap

      public LocalMap(io.vertx.core.shareddata.LocalMap<K,V> delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
    • LocalMap

      public LocalMap(Object delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
  • Method Details

    • getDelegate

      public io.vertx.core.shareddata.LocalMap<K,V> getDelegate()
      Get the delegate instance.

      This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.

      Specified by:
      getDelegate in interface MutinyDelegate
      Returns:
      the delegate instance
    • get

      public V get(Object key)
      Get a value from the map
      Parameters:
      key - the key
      Returns:
      the value, or null if none
    • put

      public V put(K key, V value)
      Put an entry in the map
      Parameters:
      key - the key
      value - the value
      Returns:
      return the old value, or null if none
    • remove

      public V remove(Object key)
      Remove an entry from the map
      Parameters:
      key - the key
      Returns:
      the old value
    • clear

      public void clear()
      Clear all entries in the map
    • size

      public int size()
      Get the size of the map
      Returns:
      the number of entries in the map
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if there are zero entries in the map
    • putIfAbsent

      public V putIfAbsent(K key, V value)
      Put the entry only if there is no existing entry for that key
      Parameters:
      key - the key
      value - the value
      Returns:
      the old value or null, if none
    • removeIfPresent

      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 - the key
      value - the value
      Returns:
      true if removed
    • replaceIfPresent

      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 - the key
      oldValue - the old value
      newValue - the new value
      Returns:
      true if removed
    • replace

      public V replace(K key, V value)
      Replace the entry only if there is an existing entry with the key
      Parameters:
      key - the key
      value - the new value
      Returns:
      the old value
    • close

      public void close()
      Close and release the map
    • containsKey

      public boolean containsKey(Object key)
      Returns true if this map contains a mapping for the specified key.
      Parameters:
      key - key whose presence in this map is to be tested
      Returns:
      true if this map contains a mapping for the specified key
    • containsValue

      public boolean containsValue(Object value)
      Returns @{code true} if this map maps one or more keys to the specified value.
      Parameters:
      value - value whose presence in this map is to be tested
      Returns:
    • getOrDefault

      public 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.
      Parameters:
      key - the key whose associated value is to be returned
      defaultValue - the default mapping of the key
      Returns:
      the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key
    • newInstance

      public static <K, V> LocalMap<K,V> newInstance(io.vertx.core.shareddata.LocalMap<K,V> delegate)
      Creates a new instance of the LocalMap.
    • newInstance

      public static <K, V> LocalMap<K,V> newInstance(io.vertx.core.shareddata.LocalMap<K,V> delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
      Creates a new instance of the LocalMap.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object