From: Florian Forster Date: Mon, 3 Aug 2009 09:56:26 +0000 (+0200) Subject: java bindings: GenericJMX: Add support for more numeric classes. X-Git-Tag: collectd-4.8.0~50^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7603c661cdeabe2068939486ed0a3e49aba129a3;p=collectd.git java bindings: GenericJMX: Add support for more numeric classes. --- 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 */