Package org.rhq.core.domain.measurement.composite

Examples of org.rhq.core.domain.measurement.composite.MeasurementNumericValueAndUnits


            // The expected output is in Locale.US. Handle running the tests in a different default locale
            if (expected.contains(".") && (!Locale.getDefault().equals(Locale.US))) {
                Locale defaultLocale = Locale.getDefault();
                Locale.setDefault(Locale.US);
                MeasurementNumericValueAndUnits vu = MeasurementParser.parse(expected, expectedUnits);
                Locale.setDefault(defaultLocale);
                expected = MeasurementConverter.format(vu.getValue(), expectedUnits, false, null, 4);
            }

            assert actual.equals(expected) : "Test " + precisionScalingTestCount.get() + ": " + "Index " + i + ", "
                + "Expected " + expected + ", " + "Received " + actual + ", " + "Units " + units.getName();
        }
View Full Code Here


        validateScale(fromValue, fromUnits, toValue, toUnits);
        validateScale(toValue, toUnits, fromValue, fromUnits);
    }

    private void validateScale(double fromValue, MeasurementUnits fromUnits, double toValue, MeasurementUnits toUnits) {
        MeasurementNumericValueAndUnits valueAndUnits = new MeasurementNumericValueAndUnits(fromValue, fromUnits);
        try {
            double derived = MeasurementConverter.scale(valueAndUnits, toUnits);
            assert Math.abs(toValue - derived) < 1e-9 : "Scale conversion error: " +

            "From value '" + fromValue + "', " + "with units of '" + fromUnits.name() + "', " + "displayed as '"
View Full Code Here

    }

    private void validateFormatConvert(double passedValue, double expectedValue, MeasurementUnits units) {
        try {
            String intermediate = MeasurementConverter.format(passedValue, units, false);
            MeasurementNumericValueAndUnits results = MeasurementParser.parse(intermediate, units);

            assert (Math.abs(results.getValue() - expectedValue) < 1e-9 && results.getUnits() == units) : "double input was '"
                + passedValue
                + "', "
                + "units input was '"
                + units.name()
                + "', "
                +

                "intermediate string was '"
                + intermediate
                + "', "
                +

                "Expected value '"
                + expectedValue
                + "', "
                + "with units of '"
                + units.name()
                + "', "
                + "displayed as '"
                + units
                + "', "
                +

                "Received value '"
                + results.getValue()
                + "', "
                + "with units of '"
                + results.getUnits().getName()
                + "', " + "displayed as '" + results.getUnits() + "'";
        } catch (MeasurementConversionException mce) {
            assert false : "Error during conversion: " + mce.getMessage();
        }
    }
View Full Code Here

        validateConvert(value, value, intermediate, units);
    }

    private void validateConvert(double passedValue, double expectedValue, String intermediate, MeasurementUnits units) {
        try {
            MeasurementNumericValueAndUnits results = MeasurementParser.parse(intermediate, units);

            assert (Math.abs(results.getValue() - expectedValue) < 1e-9 && results.getUnits() == units) : "double input was '"
                + passedValue
                + "', "
                + "units input was '"
                + units.name()
                + "', "
                +

                "intermediate string was '"
                + intermediate
                + "', "
                +

                "Expected value '"
                + expectedValue
                + "', "
                + "with units of '"
                + units.name()
                + "', "
                + "displayed as '"
                + units
                + "', "
                +

                "Received value '"
                + results.getValue()
                + "', "
                + "with units of '"
                + results.getUnits().getName()
                + "', " + "displayed as '" + results.getUnits() + "'";
        } catch (MeasurementConversionException mce) {
            assert false : "Error during conversion: " + mce.getMessage();
        }
    }
View Full Code Here

    public void exportProperties(Subject subject, ConditionBean fromBean, AlertCondition toCondition) {
        MeasurementDefinition definition = definitionManager.getMeasurementDefinition(subject, fromBean.getMetricId());
        toCondition.setMeasurementDefinition(definition);

        if (fromBean.getThresholdType().equals(TYPE_ABS)) {
            MeasurementNumericValueAndUnits valueAndUnits = MeasurementParser.parse(fromBean.getAbsoluteValue(),
                definition.getUnits());

            toCondition.setCategory(AlertConditionCategory.THRESHOLD);
            toCondition.setThreshold(valueAndUnits.getValue());
            toCondition.setComparator(fromBean.getAbsoluteComparator());

        } else if (fromBean.getThresholdType().equals(TYPE_PERC)) {
            MeasurementNumericValueAndUnits threshold = MeasurementParser.parse(fromBean.getPercentage(),
                MeasurementUnits.PERCENTAGE);

            toCondition.setCategory(AlertConditionCategory.BASELINE);
            toCondition.setThreshold(threshold.getValue());
            toCondition.setComparator(fromBean.getPercentageComparator());
            toCondition.setOption(fromBean.getBaselineOption());

        } else {
            toCondition.setCategory(AlertConditionCategory.CHANGE);
View Full Code Here

        MeasurementDefinition definition = definitionManager.getMeasurementDefinition(subject, fromBean
            .getCallTimeMetricId());
        toCondition.setMeasurementDefinition(definition);

        if (fromBean.getThresholdType().equals(TYPE_ABS)) {
            MeasurementNumericValueAndUnits valueAndUnits = MeasurementParser.parse(fromBean.getCtAbsoluteValue(),
                definition.getUnits());

            toCondition.setThreshold(valueAndUnits.getValue());
            toCondition.setCategory(AlertConditionCategory.THRESHOLD);
            toCondition.setOption(fromBean.getCalltimeAbsOption());
            toCondition.setComparator(fromBean.getCalltimeComparator());
            toCondition.setName(fromBean.getCalltimeAbsPattern());

        } else if (fromBean.getThresholdType().equals(TYPE_CHG)) {
            MeasurementNumericValueAndUnits percentage = MeasurementParser.parse(fromBean.getCtPercentage(),
                MeasurementUnits.PERCENTAGE);

            toCondition.setThreshold(percentage.getValue());
            toCondition.setCategory(AlertConditionCategory.CHANGE);
            toCondition.setOption(fromBean.getCalltimeChgOption());
            toCondition.setName(fromBean.getCalltimeChgPattern());
            toCondition.setComparator(fromBean.getCalltimeChgOp());
        }
View Full Code Here

    public static MeasurementNumericValueAndUnits parse(String input, MeasurementUnits targetUnits)
        throws MeasurementConversionException {

        if (input == null) {
            return new MeasurementNumericValueAndUnits(Double.valueOf(0.0), targetUnits);
        }

        input = input.trim();

        if (input.length() == 0) {
            return new MeasurementNumericValueAndUnits(Double.valueOf(0.0), targetUnits);
        }

        int i = 0;

        // skip over the sign, we'll deal with that later
        if (input.startsWith("+") || input.startsWith("-")) {
            i = 1;
        }

        // find the end of the magnitude (i.e. the number itself)
        // note we allow for decimals - and we allow for either "." or "," as the decimal point for i18n purposes
        for (; i < input.length(); i++) {
            char ch = input.charAt(i);
            if (!(Character.isDigit(ch) || ch == '.' || ch == ',')) {
                break;
            }
        }

        String magnitude = input.substring(0, i);
        String units = "";

        if (i <= input.length()) {
            // gobble everything after the magnitude and consider it the units
            units = input.substring(i);
            units = units.trim();
        }

        MeasurementUnits fromUnits;
        if (units.equals("")) {
            /*
             * no units is valid, and we assume the passed targetUnits; however, we will
             * still need to check that the number is well-formed, so continue processing.
             */
            fromUnits = targetUnits;
        } else {
            fromUnits = MeasurementUnits.getUsingDisplayUnits(units, targetUnits.getFamily());

            if ((fromUnits == null) || (!fromUnits.isComparableTo(targetUnits))) {
                throw new MeasurementConversionException("The units in '" + input + "' were not valid, " + "expected '"
                    + targetUnits.getFamily() + "' units, received '" + units + "' units");
            }
        }

        try {
            if (magnitude.startsWith("+")) {
                magnitude = magnitude.substring(1);
            }

            Number convertedMagnitude = NumberFormat.getDecimalFormat().parse(magnitude);
            Double scaledMagnitude;

            // apply relative scale if applicable, otherwise perform standard scaling
            if (MeasurementUnits.Family.RELATIVE == targetUnits.getFamily()) {
                scaledMagnitude = MeasurementUnits.scaleDown(convertedMagnitude.doubleValue(), targetUnits);
            } else {
                MeasurementNumericValueAndUnits valueAndUnits = new MeasurementNumericValueAndUnits(convertedMagnitude
                    .doubleValue(), fromUnits);
                scaledMagnitude = MeasurementConverterClient.scale(valueAndUnits, targetUnits);
            }

            return new MeasurementNumericValueAndUnits(scaledMagnitude, targetUnits);
        } catch (Exception e) {
            throw new MeasurementConversionException("The magnitude in '" + input + "' did not parse correctly "
                + "as a valid, localized, stringified number ");
        }

View Full Code Here

        double[] durations = new double[] { from.getMinimum(), from.getMaximum(), from.getAverage() };
        String[] durationStrings = MeasurementConverterClient.formatToSignificantPrecision(durations,
            MeasurementUnits.MILLISECONDS, true);
        // total is the sum of all calls so we format it differently as min, max because it is
        // much higher number
        MeasurementNumericValueAndUnits total = MeasurementConverterClient.fit(from.getTotal(),
            MeasurementUnits.MILLISECONDS);
        String totalString = MeasurementConverterClient.format(from.getTotal(), MeasurementUnits.MILLISECONDS, true);

        ListGridRecord record = new ListGridRecord();
        record.setAttribute(FIELD_DESTINATION, from.getCallDestination());
        record.setAttribute(FIELD_REQUESTCOUNT, from.getCount());
        record.setAttribute(FIELD_MIN, durations[0]);
        record.setAttribute(FIELD_MAX, durations[1]);
        record.setAttribute(FIELD_AVG, durations[2]);
        record.setAttribute(FIELD_TOTAL, total.getValue());
        record.setAttribute(FIELD_MIN_STRING, durationStrings[0]);
        record.setAttribute(FIELD_MAX_STRING, durationStrings[1]);
        record.setAttribute(FIELD_AVG_STRING, durationStrings[2]);
        record.setAttribute(FIELD_TOTAL_STRING, totalString);
        return record;
View Full Code Here

    public static MeasurementValueAndUnits[] getMeasurementValueAndUnits(double[] metricValueDoubles, String units) {
        MeasurementValueAndUnits[] valueAndUnitsList = new MeasurementValueAndUnits[metricValueDoubles.length];

        int i = 0;
        for (Double metricValue : metricValueDoubles) {
            valueAndUnitsList[i] = new MeasurementNumericValueAndUnits(metricValue, MeasurementUnits.valueOf(units));
            i++;
        }

        return valueAndUnitsList;
    }
View Full Code Here

      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())
            dataValueAndUnits = MeasurementConversionUtility.fit(dataValue,
                units);
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.measurement.composite.MeasurementNumericValueAndUnits

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.