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

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

Introduction

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

Prototype

public double getMinimumDouble() 

Source Link

Document

Gets the minimum number in this range as a double.

This implementation uses the #getMinimumNumber() 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.//from w  w  w .j av a  2 s  . c  om
 */
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++;/*from   ww w .  j a  va 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]++;
            }
        }

    }

}