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

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

Introduction

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

Prototype

public boolean overlapsRange(Range range) 

Source Link

Document

Tests whether the specified range overlaps with this range using float comparison.

null is handled and returns false.

Usage

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

private static boolean doCompareRealForTaxa(List<RealAttribute> attrs, boolean matchUnknowns,
        boolean matchInapplicables, MatchType matchType) {
    // sort attributes in ascending order according to range length
    Map<Attribute, Double> attrRangeLengths = new HashMap<Attribute, Double>();

    for (RealAttribute attr : attrs) {
        FloatRange range = attr.getPresentRange();
        attrRangeLengths.put(attr, (double) (range.getMaximumFloat() - range.getMinimumFloat()));
    }/*from   ww  w. j  a  va2 s.co  m*/

    Collections.sort(attrs, new AttributeValueSizeComparator(attrRangeLengths));

    if (matchType == MatchType.EXACT || matchType == MatchType.SUBSET) {
        boolean diff = false;

        for (int i = 0; i < attrs.size() - 1; i++) {

            RealAttribute a1 = attrs.get(i);
            RealAttribute a2 = attrs.get(i + 1);
            diff = !compareReal(a1, a2, matchUnknowns, matchInapplicables, matchType);

            if (diff) {
                break;
            }
        }

        return !diff;
    } else {
        // overlap - taxa must have at least one point in common
        // progressively calculate area of overlap
        int numAttrs = attrs.size();

        for (int i = 0; i < numAttrs; i++) {
            RealAttribute a1 = attrs.get(i);
            FloatRange a1Range = a1.getPresentRange();

            for (int j = i + 1; j < numAttrs; j++) {
                boolean overlap = false;

                RealAttribute a2 = attrs.get(j);
                FloatRange a2Range = a2.getPresentRange();

                overlap = a2Range.overlapsRange(a1Range);

                if (!overlap) {
                    return false;
                }
            }
        }
        return true;
    }
}

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

private static boolean doCompareRange(FloatRange attr1Range, FloatRange attr2Range, boolean attr1Unknown,
        boolean attr2Unknown, boolean attr1Inapplicable, boolean attr2Inapplicable, boolean matchUnknowns,
        boolean matchInapplicables, MatchType matchType) {

    // If both attributes are unknown or inapplicable this is considered a
    // match. Otherwise, the return value depends on setting for
    // matchInapplicable or matchUnknown.
    if ((attr1Unknown || attr1Inapplicable) && (attr2Unknown || attr2Inapplicable)) {
        return true;
    }//from  w  w  w  .j  a  v  a2 s.  co  m

    if ((attr1Unknown && attr1Inapplicable) || (attr2Unknown && attr2Inapplicable)) {
        return matchInapplicables;
    }

    if ((attr1Unknown && !attr1Inapplicable) || (attr2Unknown && !attr2Inapplicable)) {
        return matchUnknowns;
    }

    boolean match = false;

    switch (matchType) {
    case EXACT:
        match = attr1Range.equals(attr2Range);
        break;
    case SUBSET:
        // is the first a subset of the second
        match = attr2Range.containsRange(attr1Range);
        break;
    case OVERLAP:
        match = attr1Range.overlapsRange(attr2Range);
        break;
    default:
        throw new RuntimeException(String.format("Unrecognized match type %s", matchType.toString()));
    }

    return match;
}