Class: Vertx::SharedData::SharedSet

Inherits:
Object
  • Object
show all
Defined in:
lib/vertx/shared_data.rb

Instance Method Summary collapse

Constructor Details

#initialize(j_set) ⇒ SharedSet

Returns a new instance of SharedSet.



121
122
123
# File 'lib/vertx/shared_data.rb', line 121

def initialize(j_set)
  @j_set = j_set
end

Instance Method Details

#==(other) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/vertx/shared_data.rb', line 125

def ==(other)
  if other.is_a?(SharedSet)
    @j_set.equal?(other._to_java_set)
  else
    false
  end
end

#_to_java_setObject



208
209
210
# File 'lib/vertx/shared_data.rb', line 208

def _to_java_set
  @j_set
end

#add(obj) ⇒ SharedSet

Add an object to the set

Parameters:

  • obj. (Object)

    The object to add

Returns:



136
137
138
139
140
# File 'lib/vertx/shared_data.rb', line 136

def add(obj)
  obj = SharedData.check_obj(obj)
  @j_set.add(obj)
  self
end

#add?(obj) ⇒ SharedSet

Add an object to the set

Parameters:

  • obj. (Object)

    The object to add

Returns:

  • (SharedSet)

    self if the object is not already in the set, otherwise nil



145
146
147
148
149
150
151
152
153
# File 'lib/vertx/shared_data.rb', line 145

def add?(obj)
  obj = SharedData.check_obj(obj)
  if !@j_set.contains(obj)
    @j_set.add(obj)
    self
  else
    nil
  end
end

#clearObject

Clear the set



156
157
158
# File 'lib/vertx/shared_data.rb', line 156

def clear
  @j_set.clear
end

#delete(obj) ⇒ Object

Delete an object from the set

Parameters:

  • obj. (Object)

    The object to delete



162
163
164
# File 'lib/vertx/shared_data.rb', line 162

def delete(obj)
  @j_set.remove(obj)
end

#delete?(obj) ⇒ SharedSet

Delete an object from the set

Parameters:

  • obj. (Object)

    The object to delete

Returns:

  • (SharedSet)

    self if the object was in the set before the remove, nil otherwise.



169
170
171
172
173
174
175
176
# File 'lib/vertx/shared_data.rb', line 169

def delete?(obj)
  if @j_set.contains(obj)
    @j_set.remove(obj)
    self
  else
    nil
  end
end

#each(&block) ⇒ Object

Call the block for every element of the set

Parameters:

  • block. (Blovk)

    The block to call.



180
181
182
183
184
185
186
187
# File 'lib/vertx/shared_data.rb', line 180

def each(&block)
  iter = @j_set.iterator
  while iter.hasNext do
    obj = iter.next
    obj = Buffer.new(obj) if obj.is_a? org.vertx.java.core.buffer.Buffer
    block.call(obj)
  end
end

#empty?Boolean

Returns true if the set is empty.

Returns:

  • (Boolean)

    true if the set is empty



190
191
192
# File 'lib/vertx/shared_data.rb', line 190

def empty?
  @j_set.isEmpty
end

#include?(obj) ⇒ Boolean

Does the set contain an element?

Parameters:

  • obj, (Object)

    the object to check if the set contains

Returns:

  • (Boolean)

    true if the object is contained in the set



197
198
199
200
# File 'lib/vertx/shared_data.rb', line 197

def include?(obj)
  obj = obj._to_java_buffer if obj.is_a? Buffer
  @j_set.contains(obj)
end

#sizeFixNum

Returns The number of elements in the set.

Returns:

  • (FixNum)

    The number of elements in the set



203
204
205
# File 'lib/vertx/shared_data.rb', line 203

def size
  @j_set.size
end