Module: javajava::util::Collection

Defined in:
lib/logstash/java_integration.rb

Instance Method Summary collapse

Instance Method Details

#&(other) ⇒ Object

support the Ruby intersection method on Java Collection



81
82
83
84
85
86
# File 'lib/logstash/java_integration.rb', line 81

def &(other)
  # transform self into a LinkedHashSet to remove duplicates and preserve order as defined by the Ruby Array intersection contract
  duped = Java::JavaUtil::LinkedHashSet.new(self)
  duped.retainAll(other)
  duped
end

#delete(o) ⇒ Object

support the Ruby Array delete method on a Java Collection



76
77
78
# File 'lib/logstash/java_integration.rb', line 76

def delete(o)
  self.removeAll([o]) ? o : block_given? ? yield : nil
end

#inspectObject



96
97
98
# File 'lib/logstash/java_integration.rb', line 96

def inspect
  "<#{self.class.name}:#{self.hashCode} #{self.to_a(&:inspect)}>"
end

#is_a?(clazz) ⇒ Boolean

have Collections objects like ArrayList report is_a?(Array) == true

Returns:

  • (Boolean)


70
71
72
73
# File 'lib/logstash/java_integration.rb', line 70

def is_a?(clazz)
  return true if clazz == Array
  super
end

#|(other) ⇒ Object

support the Ruby union method on Java Collection



89
90
91
92
93
94
# File 'lib/logstash/java_integration.rb', line 89

def |(other)
  # transform self into a LinkedHashSet to remove duplicates and preserve order as defined by the Ruby Array union contract
  duped = Java::JavaUtil::LinkedHashSet.new(self)
  duped.addAll(other)
  duped
end