Author: ips
Date: 2009-05-07 16:47:41 -0400 (Thu, 07 May 2009)
New Revision: 404
Added:
trunk/core/src/main/java/org/jboss/on/embedded/bean/MeasurementIntegerValueAndUnits.java
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/bean/MeasurementUtils.java
Log:
don't print fractional digit for metrics that have no units, e.g. counters
(
https://jira.jboss.org/jira/browse/EMBJOPR-173)
Added:
trunk/core/src/main/java/org/jboss/on/embedded/bean/MeasurementIntegerValueAndUnits.java
===================================================================
---
trunk/core/src/main/java/org/jboss/on/embedded/bean/MeasurementIntegerValueAndUnits.java
(rev 0)
+++
trunk/core/src/main/java/org/jboss/on/embedded/bean/MeasurementIntegerValueAndUnits.java 2009-05-07
20:47:41 UTC (rev 404)
@@ -0,0 +1,43 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.jboss.on.embedded.bean;
+
+import org.rhq.core.domain.measurement.MeasurementUnits;
+import org.rhq.core.domain.measurement.composite.MeasurementNumericValueAndUnits;
+import org.rhq.core.domain.measurement.util.MeasurementConverter;
+
+/**
+ * A subclass of {@link MeasurementNumericValueAndUnits) that overrides toString() to
display the value as an integer
+ * (e.g. "42"), rather than a double (e.g. "42.0").
+ *
+ * @author Ian Springer
+ */
+public class MeasurementIntegerValueAndUnits extends MeasurementNumericValueAndUnits
+{
+ public MeasurementIntegerValueAndUnits(Double value, MeasurementUnits units)
+ {
+ super(value, units);
+ }
+
+ @Override
+ public String toString()
+ {
+ return MeasurementConverter.format(getValue(), getUnits(), true, 0, 0);
+ }
+}
Property changes on:
trunk/core/src/main/java/org/jboss/on/embedded/bean/MeasurementIntegerValueAndUnits.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Author Id Revision HeadURL
Name: svn:eol-style
+ LF
Modified: trunk/core/src/main/java/org/jboss/on/embedded/bean/MeasurementUtils.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/bean/MeasurementUtils.java 2009-05-07
20:46:10 UTC (rev 403)
+++ trunk/core/src/main/java/org/jboss/on/embedded/bean/MeasurementUtils.java 2009-05-07
20:47:41 UTC (rev 404)
@@ -56,7 +56,7 @@
private ResourceListItem resource;
/**
- * this resource's resource type
+ * this resource's type
*/
private ResourceType resourceType;
@@ -186,7 +186,11 @@
{
double dataValue = (Double)
measurementDisplay.getMeasurementData().getValue();
MeasurementUnits units =
measurementDisplay.getMeasurementDefinition().getUnits();
- MeasurementNumericValueAndUnits dataValueAndUnits =
MeasurementConverter.fit(dataValue, units);
+ MeasurementNumericValueAndUnits dataValueAndUnits;
+ if (units == MeasurementUnits.NONE)
+ dataValueAndUnits = new MeasurementIntegerValueAndUnits(dataValue,
units);
+ else
+ dataValueAndUnits = MeasurementConverter.fit(dataValue, units);
measurementDisplay.setMeasurementValueAndUnits(dataValueAndUnits);
}
catch (MeasurementConversionException mce)