Class: Vertx::LocalMap

Inherits:
Object
  • Object
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.

Your own objects can be marked as immutable by implementing the Nil interface. Since the version 3.4, this class extends the interface. However some methods are only accessible in Java.

Instance Method Summary (collapse)

Instance Method Details

- (void) clear

This method returns an undefined value.

Clear all entries in the map

Raises:

  • (ArgumentError)


58
59
60
61
62
63
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 58

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)


126
127
128
129
130
131
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 126

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

- (true, false) contains_key?(key = nil)

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

Parameters:

  • key (Object) (defaults to: nil)
    key whose presence in this map is to be tested

Returns:

  • (true, false)
    true if this map contains a mapping for the specified key

Raises:

  • (ArgumentError)


136
137
138
139
140
141
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 136

def contains_key?(key=nil)
  if ::Vertx::Util::unknown_type.accept?(key) && !block_given?
    return @j_del.java_method(:containsKey, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(key))
  end
  raise ArgumentError, "Invalid arguments when calling contains_key?(#{key})"
end

- (true, false) contains_value?(value = nil)

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

Parameters:

  • value (Object) (defaults to: nil)
    value whose presence in this map is to be tested

Returns:

  • (true, false)
    @true if this map maps one or more keys to the specified value

Raises:

  • (ArgumentError)


146
147
148
149
150
151
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 146

def contains_value?(value=nil)
  if ::Vertx::Util::unknown_type.accept?(value) && !block_given?
    return @j_del.java_method(:containsValue, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(value))
  end
  raise ArgumentError, "Invalid arguments when calling contains_value?(#{value})"
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)


73
74
75
76
77
78
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 73

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)


31
32
33
34
35
36
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 31

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

- (Object) get_or_default(key = nil, defaultValue = nil)

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

Parameters:

  • key (Object) (defaults to: nil)
    the key whose associated value is to be returned
  • defaultValue (Object) (defaults to: nil)
    the default mapping of the key

Returns:

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

Raises:

  • (ArgumentError)


157
158
159
160
161
162
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 157

def get_or_default(key=nil,defaultValue=nil)
  if ::Vertx::Util::unknown_type.accept?(key) && @j_arg_V.accept?(defaultValue) && !block_given?
    return @j_arg_V.wrap(@j_del.java_method(:getOrDefault, [Java::java.lang.Object.java_class,Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(key),@j_arg_V.unwrap(defaultValue)))
  end
  raise ArgumentError, "Invalid arguments when calling get_or_default(#{key},#{defaultValue})"
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)


41
42
43
44
45
46
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 41

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)


83
84
85
86
87
88
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 83

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)


50
51
52
53
54
55
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 50

def remove(key=nil)
  if ::Vertx::Util::unknown_type.accept?(key) && !block_given?
    return @j_arg_V.wrap(@j_del.java_method(:remove, [Java::java.lang.Object.java_class]).call(::Vertx::Util::Utils.to_object(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.

This method is the poyglot version of #remove.

Parameters:

  • key (Object) (defaults to: nil)
    the key
  • value (Object) (defaults to: nil)
    the value

Returns:

  • (true, false)
    true if removed

Raises:

  • (ArgumentError)


95
96
97
98
99
100
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 95

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)


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

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.

This method is the polyglot version of #replace.

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)


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

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)


66
67
68
69
70
71
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/local_map.rb', line 66

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