Example usage for java.lang Float compare

List of usage examples for java.lang Float compare

Introduction

In this page you can find the example usage for java.lang Float compare.

Prototype

public static int compare(float f1, float f2) 

Source Link

Document

Compares the two specified float values.

Usage

From source file:org.ejbca.extra.db.CardRenewalRequest.java

public void upgrade() {
    if (Float.compare(LATEST_VERSION, getVersion()) != 0) {
        data.put(VERSION, new Float(LATEST_VERSION));
    }
}

From source file:io.druid.query.aggregation.histogram.ApproximateHistogramAggregatorFactory.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }//from   w ww . j  a v  a 2  s. co  m
    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    ApproximateHistogramAggregatorFactory that = (ApproximateHistogramAggregatorFactory) o;

    if (Float.compare(that.lowerLimit, lowerLimit) != 0) {
        return false;
    }
    if (numBuckets != that.numBuckets) {
        return false;
    }
    if (resolution != that.resolution) {
        return false;
    }
    if (Float.compare(that.upperLimit, upperLimit) != 0) {
        return false;
    }
    if (fieldName != null ? !fieldName.equals(that.fieldName) : that.fieldName != null) {
        return false;
    }
    if (name != null ? !name.equals(that.name) : that.name != null) {
        return false;
    }

    return true;
}

From source file:eionet.cr.util.sesame.ResultCompareUtil.java

/**
 *
 * @param bs1/* w  w w . j av a  2s. co  m*/
 * @param bs2
 * @param bNodeMapping
 * @return
 */
private static boolean bindingSetsMatch(BindingSet bs1, BindingSet bs2, Map<BNode, BNode> bNodeMapping) {

    if (bs1.size() != bs2.size()) {
        return false;
    }

    for (Binding binding1 : bs1) {
        Value value1 = binding1.getValue();
        Value value2 = bs2.getValue(binding1.getName());

        if (value1 instanceof BNode && value2 instanceof BNode) {
            BNode mappedBNode = bNodeMapping.get(value1);

            if (mappedBNode != null) {
                // bNode 'value1' was already mapped to some other bNode
                if (!value2.equals(mappedBNode)) {
                    // 'value1' and 'value2' do not match
                    return false;
                }
            } else {
                // 'value1' was not yet mapped, we need to check if 'value2' is a
                // possible mapping candidate
                if (bNodeMapping.containsValue(value2)) {
                    // 'value2' is already mapped to some other value.
                    return false;
                }
            }
        } else {

            if (!StringUtils.equals(value1.stringValue(), value2.stringValue())) {
                return false;
            }
            // values are not (both) bNodes
            if (value1 instanceof Literal && value2 instanceof Literal) {
                // do literal value-based comparison for supported datatypes
                Literal leftLit = (Literal) value1;
                Literal rightLit = (Literal) value2;

                URI dt1 = leftLit.getDatatype();
                URI dt2 = rightLit.getDatatype();

                if (dt1 != null && dt2 != null && dt1.equals(dt2)
                        && XMLDatatypeUtil.isValidValue(leftLit.getLabel(), dt1)
                        && XMLDatatypeUtil.isValidValue(rightLit.getLabel(), dt2)) {
                    Integer compareResult = null;
                    if (dt1.equals(XMLSchema.DOUBLE)) {
                        compareResult = Double.compare(leftLit.doubleValue(), rightLit.doubleValue());
                    } else if (dt1.equals(XMLSchema.FLOAT)) {
                        compareResult = Float.compare(leftLit.floatValue(), rightLit.floatValue());
                    } else if (dt1.equals(XMLSchema.DECIMAL)) {
                        compareResult = leftLit.decimalValue().compareTo(rightLit.decimalValue());
                    } else if (XMLDatatypeUtil.isIntegerDatatype(dt1)) {
                        compareResult = leftLit.integerValue().compareTo(rightLit.integerValue());
                    } else if (dt1.equals(XMLSchema.BOOLEAN)) {
                        Boolean leftBool = Boolean.valueOf(leftLit.booleanValue());
                        Boolean rightBool = Boolean.valueOf(rightLit.booleanValue());
                        compareResult = leftBool.compareTo(rightBool);
                    } else if (XMLDatatypeUtil.isCalendarDatatype(dt1)) {
                        XMLGregorianCalendar left = leftLit.calendarValue();
                        XMLGregorianCalendar right = rightLit.calendarValue();

                        compareResult = left.compare(right);
                    }

                    if (compareResult != null) {
                        if (compareResult.intValue() != 0) {
                            return false;
                        }
                    } else if (!value1.equals(value2)) {
                        return false;
                    }
                } else if (!value1.equals(value2)) {
                    return false;
                }
            } else if (!value1.equals(value2)) {
                return false;
            }
        }
    }

    return true;
}

From source file:org.diorite.utils.math.DioriteRandomUtils.java

public static float getRandomFloat(final Random random, final float min, final float max)
        throws IllegalArgumentException {
    if (Float.compare(min, max) == 0) {
        return max;
    }// www .j  a  va  2  s.com
    Validate.isTrue(max > min, "Max can't be smaller than min!");
    return (random.nextFloat() * (max - min)) + min;
}

From source file:org.cesecore.certificates.ca.CvcCA.java

/** Implementation of UpgradableDataHashMap function upgrade. 
 *//*from  ww  w .j  a  v a  2 s .c  o  m*/
@Override
public void upgrade() {
    if (Float.compare(LATEST_VERSION, getVersion()) != 0) {
        // New version of the class, upgrade
        log.info("Upgrading CVCCA with version " + getVersion());

        // Put upgrade code here...

        // v1->v2 is only an upgrade in order to upgrade CA token
        // v2->v3 is a upgrade of X509CA that has to be adjusted here too, due to the common heritage
        if (data.get(CRLPERIOD) instanceof Integer) {
            setCRLPeriod(0L);
        }
        if (data.get(CRLISSUEINTERVAL) instanceof Integer) {
            setCRLIssueInterval(0L);
        }
        if (data.get(CRLOVERLAPTIME) instanceof Integer) {
            setCRLOverlapTime(0L);
        }
        if (data.get(DELTACRLPERIOD) instanceof Integer) {
            setDeltaCRLPeriod(0L);
        }

        // v4.
        // 'encodedValidity' MUST set to "" (Empty String) here. The initialization is done during post-upgrade of EJBCA 6.6.1.
        if (null == data.get(ENCODED_VALIDITY)) {
            setEncodedValidity(StringUtils.EMPTY);
        }

        data.put(VERSION, new Float(LATEST_VERSION));
    }
}

From source file:org.diorite.commons.math.DioriteRandomUtils.java

public static float getRandomFloat(Random random, float min, float max) throws IllegalArgumentException {
    if (Float.compare(min, max) == 0) {
        return max;
    }//  ww  w.  j a va  2 s  . c  om
    Validate.isTrue(max > min, "Max can't be smaller than min!");
    return (random.nextFloat() * (max - min)) + min;
}

From source file:org.diorite.TeleportData.java

@Override
public boolean equals(final Object o) {
    if (this == o) {
        return true;
    }//from ww w. ja va 2  s  . c o  m
    if (!(o instanceof TeleportData)) {
        return false;
    }

    final TeleportData that = (TeleportData) o;

    return (this.isPitchRelatvie == that.isPitchRelatvie) && (this.isXRelatvie == that.isXRelatvie)
            && (this.isYRelatvie == that.isYRelatvie) && (this.isYawRelatvie == that.isYawRelatvie)
            && (this.isZRelatvie == that.isZRelatvie) && (Float.compare(that.pitch, this.pitch) == 0)
            && (Double.compare(that.x, this.x) == 0) && (Double.compare(that.y, this.y) == 0)
            && (Float.compare(that.yaw, this.yaw) == 0) && (Double.compare(that.z, this.z) == 0);

}

From source file:com.frostwire.bittorrent.BTDownload.java

@Override
public int getProgress() {
    if (th == null || !th.isValid()) {
        return 0;
    }/*from   ww w  .j  a v a 2s.  c  om*/

    TorrentStatus ts = th.status();

    if (ts == null) { // this can't never happens
        return 0;
    }

    float fp = ts.progress();
    TorrentStatus.State state = ts.state();

    if (Float.compare(fp, 1f) == 0 && state != TorrentStatus.State.CHECKING_FILES) {
        return 100;
    }

    int p = (int) (fp * 100);
    if (p > 0 && state != TorrentStatus.State.CHECKING_FILES) {
        return Math.min(p, 100);
    }

    return 0;
}

From source file:ir.rasen.charsoo.controller.image_loader.core.decode.BaseImageDecoder.java

protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo,
        int rotation, boolean flipHorizontal) {
    Matrix m = new Matrix();
    // Scale to exact size if need
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
        ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
        float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(),
                decodingInfo.getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
        if (Float.compare(scale, 1f) != 0) {
            m.setScale(scale, scale);/*from   ww  w  .j av a  2  s .  com*/

            if (loggingEnabled) {
                L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
            }
        }
    }
    // Flip bitmap if need
    if (flipHorizontal) {
        m.postScale(-1, 1);

        if (loggingEnabled)
            L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
    }
    // Rotate bitmap if need
    if (rotation != 0) {
        m.postRotate(rotation);

        if (loggingEnabled)
            L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
    }

    Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(),
            subsampledBitmap.getHeight(), m, true);
    if (finalBitmap != subsampledBitmap) {
        subsampledBitmap.recycle();
    }
    return finalBitmap;
}

From source file:org.wso2.carbon.analytics.dataservice.core.indexing.sort.RecordSortUtils.java

private static int compareValues(AnalyticsSchema.ColumnType type, Object value1, Object value2)
        throws AnalyticsException {
    int compareInt;
    switch (type) {
    case STRING:/*www . ja  v  a2  s . co m*/
        compareInt = ((String) value1).compareTo(((String) value2));
        break;
    case INTEGER:
        compareInt = Integer.compare((Integer) value1, (Integer) value2);
        break;
    case LONG:
        compareInt = Long.compare((Long) value1, (Long) value2);
        break;
    case FLOAT:
        compareInt = Float.compare((Float) value1, (Float) value2);
        break;
    case DOUBLE:
        compareInt = Double.compare((Double) value1, (Double) value2);
        break;
    case BOOLEAN:
        compareInt = Boolean.compare((Boolean) value1, (Boolean) value2);
        break;
    default:
        throw new AnalyticsException("Cannot sort values of type: " + type);
    }
    return compareInt;
}