Class: Java::org.hornetq.utils::TypedProperties

Inherits:
Object
  • Object
show all
Defined in:
lib/hornetq/client/org_hornetq_utils_typed_properties.rb

Overview

Used by HornetQ to move around HashMap messages Ruby methods added to make it behave like a Ruby Hash

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Get a property



5
6
7
8
# File 'lib/hornetq/client/org_hornetq_utils_typed_properties.rb', line 5

def [](key)
  value = getProperty(key)
  (value.class == Java::org.hornetq.api.core::SimpleString) ? value.to_s : value
end

#[]=(key, val) ⇒ Object

Set a property

Currently supports Long, Double, Boolean

TODO: Not supported Byte, Bytes, Short, Int, FLoat, Char



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hornetq/client/org_hornetq_utils_typed_properties.rb', line 13

def []=(key,val)
  case
  when val.class == Fixnum # 1
    putLongProperty(key,val)
  when val.class == Float #1.1
    putDoubleProperty(key,val)
  when val.class == Bignum # 11111111111111111
    putLongProperty(key,val)
  when (val.class == TrueClass) || (val.class == FalseClass)
    putBooleanProperty(key,val)
  when val.class == NilClass
    setSimpleStringProperty(key,null)
  when val.class == Java::org.hornetq.api.core::SimpleString
    setSimpleStringProperty(key,val)
  else
    putSimpleStringProperty(key,val.to_s)
  end
end

#each_pair(&proc) ⇒ Object

Iterate through each key,value pair



33
34
35
36
37
38
39
# File 'lib/hornetq/client/org_hornetq_utils_typed_properties.rb', line 33

def each_pair(&proc)
  it = property_names.iterator
  while it.has_next
    key = it.next
    proc.call(key.to_string, self[key])
  end
end

#from_h(hash) ⇒ Object

Write Hash values into this TyedProperties instance



51
52
53
54
55
# File 'lib/hornetq/client/org_hornetq_utils_typed_properties.rb', line 51

def from_h(hash)
  hash.each_pair do |key,value|
    self[key] = value
  end
end

#inspectObject



57
58
59
# File 'lib/hornetq/client/org_hornetq_utils_typed_properties.rb', line 57

def inspect
  "#{self.class.name}: #{to_h.inspect}"
end

#to_hObject

Convert Properties to a Ruby Hash



42
43
44
45
46
47
48
# File 'lib/hornetq/client/org_hornetq_utils_typed_properties.rb', line 42

def to_h
  h = {}
  each_pair do |key, value| 
    h[key] = value
  end
  h
end