Example usage for org.apache.commons.lang.math Range getMaximumDouble

List of usage examples for org.apache.commons.lang.math Range getMaximumDouble

Introduction

In this page you can find the example usage for org.apache.commons.lang.math Range getMaximumDouble.

Prototype

public double getMaximumDouble() 

Source Link

Document

Gets the maximum number in this range as a double.

This implementation uses the #getMaximumNumber() method.

Usage

From source file:au.org.ala.delta.model.NumericRange.java

/**
 * @return the middle value if one exists, or the average of the normal
 * range if it doesn't.//  w w  w. j  a  v  a 2  s  .  co  m
 */
public double middle() {
    if (hasMiddleValue()) {
        return _middle.doubleValue();
    }
    Range normal = getNormalRange();
    return (normal.getMinimumDouble() + normal.getMaximumDouble()) / 2;

}

From source file:au.org.ala.delta.translation.print.SummaryPrinter.java

private void updateStats(Item item, CharacterStats stats) {

    Attribute attribute = item.getAttribute(stats.getCharacter());
    if (isInapplicable(attribute)) {
        stats.notApplicable++;//w  w w . ja v  a 2s  . com
    } else if (_dataSet.isUncoded(item, stats.getCharacter())) {
        stats.uncodedOrUnknown++;
    } else if (attribute.isVariable()) {
        stats.variable++;
    } else {
        stats.coded++;

        IdentificationKeyCharacter keyChar = stats.getKeyChar();
        if (keyChar == null || keyChar.getCharacterType().isText()) {
            return;
        }
        List<Integer> states = null;
        if (attribute instanceof NumericAttribute) {

            NumericAttribute numericAttribute = (NumericAttribute) attribute;
            states = keyChar.getPresentStates(numericAttribute);
            if (states.size() > 1) {
                stats.keyStatesVariable++;
            }
            List<NumericRange> values = numericAttribute.getNumericValue();
            double count = 0;
            double sum = 0;
            for (NumericRange value : values) {
                Range range;

                if (_context.getUseNormalValues(keyChar.getCharacterNumber())) {
                    range = value.getNormalRange();
                } else {
                    range = value.getFullRange();
                }
                double min = range.getMinimumDouble();
                if (stats.min > min) {
                    stats.min = min;
                    stats.minItem = item.getItemNumber();
                }

                double max = range.getMaximumDouble();
                if (stats.max < max) {
                    stats.max = max;
                    stats.maxItem = item.getItemNumber();
                }
                range = value.getNormalRange();

                if (value.hasMiddleValue()) {
                    count++;
                    sum += value.getMiddle().doubleValue();
                } else if (range.getMinimumDouble() == range.getMaximumDouble()) {
                    count++;
                    sum += range.getMinimumDouble();
                } else {
                    count += 2;
                    sum += range.getMinimumDouble();
                    sum += range.getMaximumDouble();
                }

            }
            if (count > 0) {
                stats.accumulate(sum / (double) count);
            }

            for (int state : states) {
                stats.keyStateDistribution[state - 1]++;
            }

        } else if (attribute instanceof MultiStateAttribute) {
            if (keyChar.getNumberOfKeyStates() > 0) {
                states = keyChar.getPresentStates((MultiStateAttribute) attribute);
                if (states.size() > 1) {
                    stats.keyStatesVariable++;
                }
                for (int state : states) {
                    stats.keyStateDistribution[state - 1]++;
                }
            }
            List<Integer> originalStates = ((MultiStateAttribute) attribute).getPresentStatesAsList();
            if (originalStates.size() > 1) {
                stats.variable++;
            }
            for (int state : originalStates) {
                stats.stateDistribution[state - 1]++;
            }
        }

    }

}