Class List Method List File List

# Class: Vertx::LocalMap

Inherits:
  Object
  - Object
  - Vertx::LocalMap
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb

## Overview

Local maps can be used to share data safely in a single Vert.x instance.

The map only allows immutable keys and values in the map, OR certain mutable objects such as Buffer instances which will be copied when they are added to the map.

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.

## Instance Method Summary (collapse)

- - (void) clear
  Clear all entries in the map.
- - (void) close
  Close and release the map.
- - (true, false) empty?
  True if there are zero entries in the map.
- - (Object) get(key = nil)
  Get a value from the map.
- - (Object) put(key = nil, value = nil)
  Put an entry in the map.
- - (Object) put_if_absent(key = nil, value = nil)
  Put the entry only if there is no existing entry for that key.
- - (Object) remove(key = nil)
  Remove an entry from the map.
- - (true, false) remove_if_present?(key = nil, value = nil)
  Remove the entry only if there is an entry with the specified key and value.
- - (Object) replace(key = nil, value = nil)
  Replace the entry only if there is an existing entry with the key.
- - (true, false) replace_if_present?(key = nil, oldValue = nil, newValue = nil)
  Replace the entry only if there is an existing entry with the specified key and value.
- - (Fixnum) size
  Get the size of the map.

## Instance Method Details

### - (`void`) clear

This method returns an undefined value.

Clear all entries in the map

Raises:

- (`ArgumentError`)

    54
    55
    56
    57
    58
    59
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 54

    def clear
      if !block_given?
        return @j_del.java_method(:clear, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling clear()"
    end

### - (`void`) close

This method returns an undefined value.

Close and release the map

Raises:

- (`ArgumentError`)

    118
    119
    120
    121
    122
    123
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 118

    def close
      if !block_given?
        return @j_del.java_method(:close, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling close()"
    end

### - (`true`, `false`) empty?

Returns true if there are zero entries in the map

Returns:

- (`true`, `false`) —
  true if there are zero entries in the map

Raises:

- (`ArgumentError`)

    69
    70
    71
    72
    73
    74
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 69

    def empty?
      if !block_given?
        return @j_del.java_method(:isEmpty, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling empty?()"
    end

### - (`Object`) get(key = nil)

Get a value from the map

Parameters:

- key (`Object`) (defaults to: `nil`) —
  the key

Returns:

- (`Object`) —
  the value, or null if none

Raises:

- (`ArgumentError`)

    27
    28
    29
    30
    31
    32
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 27

    def get(key=nil)
      if @j_arg_K.accept?(key) && !block_given?
        return @j_arg_V.wrap(@j_del.java_method(:get, [Java::java.lang.Object.java_class]).call(@j_arg_K.unwrap(key)))
      end
      raise ArgumentError, "Invalid arguments when calling get(#{key})"
    end

### - (`Object`) put(key = nil, value = nil)

Put an entry in the map

Parameters:

- key (`Object`) (defaults to: `nil`) —
  the key
- value (`Object`) (defaults to: `nil`) —
  the value

Returns:

- (`Object`) —
  return the old value, or null if none

Raises:

- (`ArgumentError`)

    37
    38
    39
    40
    41
    42
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 37

    def put(key=nil,value=nil)
      if @j_arg_K.accept?(key) && @j_arg_V.accept?(value) && !block_given?
        return @j_arg_V.wrap(@j_del.java_method(:put, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(@j_arg_K.unwrap(key),@j_arg_V.unwrap(value)))
      end
      raise ArgumentError, "Invalid arguments when calling put(#{key},#{value})"
    end

### - (`Object`) put_if_absent(key = nil, value = nil)

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

Parameters:

- key (`Object`) (defaults to: `nil`) —
  the key
- value (`Object`) (defaults to: `nil`) —
  the value

Returns:

- (`Object`) —
  the old value or null, if none

Raises:

- (`ArgumentError`)

    79
    80
    81
    82
    83
    84
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 79

    def put_if_absent(key=nil,value=nil)
      if @j_arg_K.accept?(key) && @j_arg_V.accept?(value) && !block_given?
        return @j_arg_V.wrap(@j_del.java_method(:putIfAbsent, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(@j_arg_K.unwrap(key),@j_arg_V.unwrap(value)))
      end
      raise ArgumentError, "Invalid arguments when calling put_if_absent(#{key},#{value})"
    end

### - (`Object`) remove(key = nil)

Remove an entry from the map

Parameters:

- key (`Object`) (defaults to: `nil`) —
  the key

Returns:

- (`Object`) —
  the old value

Raises:

- (`ArgumentError`)

    46
    47
    48
    49
    50
    51
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 46

    def remove(key=nil)
      if @j_arg_K.accept?(key) && !block_given?
        return @j_arg_V.wrap(@j_del.java_method(:remove, [Java::java.lang.Object.java_class]).call(@j_arg_K.unwrap(key)))
      end
      raise ArgumentError, "Invalid arguments when calling remove(#{key})"
    end

### - (`true`, `false`) remove_if_present?(key = nil, value = nil)

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

Parameters:

- key (`Object`) (defaults to: `nil`) —
  the key
- value (`Object`) (defaults to: `nil`) —
  the value

Returns:

- (`true`, `false`) —
  true if removed

Raises:

- (`ArgumentError`)

    89
    90
    91
    92
    93
    94
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 89

    def remove_if_present?(key=nil,value=nil)
      if @j_arg_K.accept?(key) && @j_arg_V.accept?(value) && !block_given?
        return @j_del.java_method(:removeIfPresent, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(@j_arg_K.unwrap(key),@j_arg_V.unwrap(value))
      end
      raise ArgumentError, "Invalid arguments when calling remove_if_present?(#{key},#{value})"
    end

### - (`Object`) replace(key = nil, value = nil)

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

Parameters:

- key (`Object`) (defaults to: `nil`) —
  the key
- value (`Object`) (defaults to: `nil`) —
  the new value

Returns:

- (`Object`) —
  the old value

Raises:

- (`ArgumentError`)

    110
    111
    112
    113
    114
    115
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 110

    def replace(key=nil,value=nil)
      if @j_arg_K.accept?(key) && @j_arg_V.accept?(value) && !block_given?
        return @j_arg_V.wrap(@j_del.java_method(:replace, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(@j_arg_K.unwrap(key),@j_arg_V.unwrap(value)))
      end
      raise ArgumentError, "Invalid arguments when calling replace(#{key},#{value})"
    end

### - (`true`, `false`) replace_if_present?(key = nil, oldValue = nil, newValue = nil)

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

Parameters:

- key (`Object`) (defaults to: `nil`) —
  the key
- oldValue (`Object`) (defaults to: `nil`) —
  the old value
- newValue (`Object`) (defaults to: `nil`) —
  the new value

Returns:

- (`true`, `false`) —
  true if removed

Raises:

- (`ArgumentError`)

    100
    101
    102
    103
    104
    105
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 100

    def replace_if_present?(key=nil,oldValue=nil,newValue=nil)
      if @j_arg_K.accept?(key) && @j_arg_V.accept?(oldValue) && @j_arg_V.accept?(newValue) && !block_given?
        return @j_del.java_method(:replaceIfPresent, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(@j_arg_K.unwrap(key),@j_arg_V.unwrap(oldValue),@j_arg_V.unwrap(newValue))
      end
      raise ArgumentError, "Invalid arguments when calling replace_if_present?(#{key},#{oldValue},#{newValue})"
    end

### - (`Fixnum`) size

Get the size of the map

Returns:

- (`Fixnum`) —
  the number of entries in the map

Raises:

- (`ArgumentError`)

    62
    63
    64
    65
    66
    67
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 62

    def size
      if !block_given?
        return @j_del.java_method(:size, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling size()"
    end