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

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

Introduction

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

Prototype

public float getMinimumFloat() 

Source Link

Document

Gets the minimum number in this range as a float.

This implementation uses the #getMinimumNumber() method.

Usage

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);/*from  w w  w  .  j a  v a 2s. c  o  m*/

        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;
}