Example usage for org.apache.commons.lang.math FloatRange FloatRange

List of usage examples for org.apache.commons.lang.math FloatRange FloatRange

Introduction

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

Prototype

public FloatRange(Number number) 

Source Link

Document

Constructs a new FloatRange using the specified number as both the minimum and maximum in this range.

Usage

From source file:au.org.ala.delta.intkey.ui.RealInputDialog.java

@Override
void handleBtnOKClicked() {
    String inputTxt = _txtInput.getText();
    if (inputTxt.length() > 0) {
        try {//from   www. j av a2  s.c o  m
            _inputData = ParsingUtils.parseRealCharacterValue(inputTxt);
            setVisible(false);
        } catch (IllegalArgumentException ex) {
            JOptionPane.showMessageDialog(this, validationErrorMessage, validationErrorTitle,
                    JOptionPane.ERROR_MESSAGE);
        }
    } else {
        // return a float range with negative infinity. This represents
        // "no values selected".
        _inputData = new FloatRange(Float.NEGATIVE_INFINITY);
        setVisible(false);
    }
}

From source file:au.org.ala.delta.translation.intkey.IntkeyItemsFileWriter.java

private Set<Float> writeRealAttributes(int filteredCharNumber, Character realChar, boolean wasInteger) {
    int unfilteredCharNumber = realChar.getCharacterId();
    boolean useNormalValues = _context.getUseNormalValues(unfilteredCharNumber);

    List<FloatRange> values = new ArrayList<FloatRange>();
    BitSet inapplicableBits = new BitSet();

    Iterator<FilteredItem> items = _dataSet.filteredItems();
    while (items.hasNext()) {
        FilteredItem item = items.next();
        NumericAttribute attribute = (NumericAttribute) _dataSet.getAttribute(item.getItem().getItemNumber(),
                unfilteredCharNumber);//w ww .  j  a  v  a 2s . c om

        if (attribute == null || attribute.isCodedUnknown() || attribute.isInapplicable()
                || attribute.isVariable()) {
            FloatRange range = new FloatRange(Float.MAX_VALUE);
            values.add(range);
            if (isInapplicable(attribute)) {
                inapplicableBits.set(item.getItemNumber() - 1);
            }
            continue;
        }
        List<NumericRange> ranges = attribute.getNumericValue();
        // This can happen if the attribute has a comment but no value.
        if (ranges.isEmpty()) {
            FloatRange range = new FloatRange(-Float.MAX_VALUE);
            values.add(range);
            if (isInapplicable(attribute)) {
                inapplicableBits.set(item.getItemNumber() - 1);
            }
            continue;
        }
        Range useRange;
        float min = Float.MAX_VALUE;
        float max = -Float.MAX_VALUE;
        for (NumericRange range : ranges) {
            if (_context.hasAbsoluteError(unfilteredCharNumber)) {
                range.setAbsoluteError(_context.getAbsoluteError(unfilteredCharNumber));
            } else if (_context.hasPercentageError(unfilteredCharNumber)) {
                range.setPercentageError(_context.getPercentageError(unfilteredCharNumber));
            }
            if (useNormalValues) {
                useRange = range.getNormalRange();
            } else {
                useRange = range.getFullRange();
            }
            min = Math.min(min, useRange.getMinimumFloat());
            max = Math.max(max, useRange.getMaximumFloat());

        }

        FloatRange floatRange = new FloatRange(min, max);
        values.add(floatRange);
    }

    Set<Float> floats = new HashSet<Float>();
    for (FloatRange range : values) {
        if (range.getMinimumFloat() != Float.MAX_VALUE && range.getMinimumFloat() != -Float.MAX_VALUE) {
            floats.add(range.getMinimumFloat());
        } else {
            if (range.getMinimumFloat() == -Float.MAX_VALUE && !wasInteger) {
                floats.add(0f); // For CONFOR compatibility, seems wrong.
            }
        }
        if (range.getMaximumFloat() != Float.MAX_VALUE && range.getMinimumFloat() != -Float.MAX_VALUE) {
            floats.add(range.getMaximumFloat());
        } else {
            if (range.getMinimumFloat() == -Float.MAX_VALUE && !wasInteger) {
                floats.add(1.0f); // For CONFOR compatibility, seems wrong.
            }
        }
    }
    List<Float> boundaries = new ArrayList<Float>(floats);
    Collections.sort(boundaries);
    _itemsFile.writeAttributeFloats(filteredCharNumber, inapplicableBits, values, boundaries);

    return floats;
}