From 7603c661cdeabe2068939486ed0a3e49aba129a3 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 3 Aug 2009 11:56:26 +0200 Subject: [PATCH] java bindings: GenericJMX: Add support for more numeric classes. --- .../collectd/java/GenericJMXConfValue.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bindings/java/org/collectd/java/GenericJMXConfValue.java b/bindings/java/org/collectd/java/GenericJMXConfValue.java index b81ceb7d..cdca02f3 100644 --- a/bindings/java/org/collectd/java/GenericJMXConfValue.java +++ b/bindings/java/org/collectd/java/GenericJMXConfValue.java @@ -27,6 +27,9 @@ import java.util.Set; import java.util.Iterator; import java.util.ArrayList; +import java.math.BigDecimal; +import java.math.BigInteger; + import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.openmbean.OpenType; @@ -61,6 +64,11 @@ class GenericJMXConfValue private String _instance_prefix; private boolean _is_table; + /** + * Converts a generic (OpenType) object to a number. + * + * Returns null if a conversion is not possible or not implemented. + */ private Number genericObjectToNumber (Object obj, int ds_type) /* {{{ */ { if (obj instanceof String) @@ -79,6 +87,14 @@ class GenericJMXConfValue return (null); } } + else if (obj instanceof Byte) + { + return (new Byte ((Byte) obj)); + } + else if (obj instanceof Short) + { + return (new Short ((Short) obj)); + } else if (obj instanceof Integer) { return (new Integer ((Integer) obj)); @@ -87,10 +103,22 @@ class GenericJMXConfValue { return (new Long ((Long) obj)); } + else if (obj instanceof Float) + { + return (new Float ((Float) obj)); + } else if (obj instanceof Double) { return (new Double ((Double) obj)); } + else if (obj instanceof BigDecimal) + { + return (BigDecimal.ZERO.add ((BigDecimal) obj)); + } + else if (obj instanceof BigInteger) + { + return (BigInteger.ZERO.add ((BigInteger) obj)); + } return (null); } /* }}} Number genericObjectToNumber */ -- 2.30.2