Package org.rhq.core.domain.measurement

Examples of org.rhq.core.domain.measurement.MeasurementUnits


    // TODO: send in the current Locale
    if (measurementDisplay.getMeasurementData().getValue() instanceof Double) {
      try {
        double dataValue = (Double) measurementDisplay
            .getMeasurementData().getValue();
        MeasurementUnits units = measurementDisplay
            .getMeasurementDefinition().getUnits();
        MeasurementNumericValueAndUnits dataValueAndUnits;
        if (units == MeasurementUnits.NONE) {
          Double dbl = Double.valueOf(dataValue);
          if (dataValue != dbl.intValue())
View Full Code Here


        return nf;
    }

    public static Double scale(MeasurementNumericValueAndUnits origin, MeasurementUnits targetUnits)
            throws MeasurementConversionException {
        MeasurementUnits originUnits = origin.getUnits();
        Double originValue = origin.getValue();

        return originValue * MeasurementUnits.calculateOffset(originUnits, targetUnits);
    }
View Full Code Here

        if (origin < 0) {
            wasNegative = true;
            origin = -origin;
        }

        MeasurementUnits baseUnit = targetUnits.getBaseUnits();
        MeasurementNumericValueAndUnits valueAndUnits = new MeasurementNumericValueAndUnits(origin, baseUnit);

        Double results = scale(valueAndUnits, targetUnits);
        if (wasNegative) {
            results = -results;
View Full Code Here

    public static String[] formatToSignificantPrecision(double[] values, MeasurementUnits targetUnits, boolean bestFit) {
        if ((null == values) || (values.length == 0)) {
            return null;
        }

        MeasurementUnits originalUnits = targetUnits;

        /*
        * in the overwhelming majority of cases, you're going to want to apply a bestFit
        * to the passed data, but it's not required; it's perfectly possible to allow a
        * list of doubles to be formatted without being fit, in which case the targetUnits
        * will be part of the formatted display for each result element
        */
        if (bestFit) {
            // find bestFit units by taking the average
            Double average = 0.0;

            for (int i = 0, sz = values.length; i < sz; i++) {
                /*
                * adding fractional amount iterative leads to greater
                * error, but prevents overflow on large data sets
                */
                average += (values[i] / sz);
            }

            MeasurementNumericValueAndUnits fittedAverage = fit(average, targetUnits);
            //noinspection UnnecessaryLocalVariable
            MeasurementUnits fittedUnits = fittedAverage.getUnits();

            /*
            * and change the local reference to targetUnits, so that the same logic
            * can be used both for the bestFit and non-bestFit computations
            */
 
View Full Code Here

        return format(formatted, targetUnits);
    }

    public static String scaleAndFormat(Double origin, MeasurementSchedule targetSchedule, boolean bestFit)
            throws MeasurementConversionException {
        MeasurementUnits targetUnits = targetSchedule.getDefinition().getUnits();

        return scaleAndFormat(origin, targetUnits, bestFit, null, null);
    }
View Full Code Here

    }

    public static String scaleAndFormat(Double origin, MeasurementUnits targetUnits, boolean bestFit,
                                        Integer minimumFractionDigits, Integer maximumFractionDigits) throws MeasurementConversionException {

        MeasurementUnits baseUnits = targetUnits.getBaseUnits();
        MeasurementNumericValueAndUnits valueAndUnits = new MeasurementNumericValueAndUnits(origin, baseUnits);
        Double scaledMagnitude = scale(valueAndUnits, targetUnits);

        return format(scaledMagnitude, targetUnits, bestFit);
    }
View Full Code Here

            if (nextOrdinal == maxOrdinal) {
                // we could theoretically get bigger, but we don't have any units to represent that
                break;
            }

            MeasurementUnits biggerUnits = MeasurementUnits.values()[nextOrdinal];
            if (biggerUnits.getFamily() != currentValueAndUnits.getUnits().getFamily()) {
                // we're as big as we can get, break out of the loop so we can return
                break;
            }

            Double smallerValue = scale(currentValueAndUnits, biggerUnits);

            nextValueAndUnits = new MeasurementNumericValueAndUnits(smallerValue, biggerUnits);
        } while (nextValueAndUnits.getValue() > 1.0);

        // next, make the value bigger if it's too small
        int minOrdinal = (lowUnits != null) ? (lowUnits.ordinal() - 1) : -1;

        while (currentValueAndUnits.getValue() < 1.0) {
            int nextOrdinal = currentValueAndUnits.getUnits().ordinal() - 1;
            if (nextOrdinal == minOrdinal) {
                // we could theoretically get smaller, but we don't have any units to represent that
                break;
            }

            MeasurementUnits smallerUnits = MeasurementUnits.values()[nextOrdinal];
            if (smallerUnits.getFamily() != currentValueAndUnits.getUnits().getFamily()) {
                // we're as small as we can get, break out of the loop so we can return
                break;
            }

            Double biggerValue = scale(currentValueAndUnits, smallerUnits);
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.measurement.MeasurementUnits

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.