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



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

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



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

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

#inspectObject



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

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)


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

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

#|(other) ⇒ Object

support the Ruby union method on Java Collection



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

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