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:Main.java

public static void main(String[] args) {
    float f1 = 5.5f;
    float f2 = 5.4f;
    int i1 = Float.compare(f1, f2);
    if (i1 > 0) {
        System.out.println(">");
    } else if (i1 < 0) {
        System.out.println("<");
    } else {/*from  w  w w.j a  v a  2s  .c  o  m*/
        System.out.println("=");
    }

    Float fObj1 = new Float("5.5");
    Float fObj2 = new Float("5.4");
    int i2 = fObj1.compareTo(fObj2);
    if (i2 > 0) {
        System.out.println(">");
    } else if (i2 < 0) {
        System.out.println("<");
    } else {
        System.out.println("=");
    }
}

From source file:Main.java

public static void main(String[] args) {
    Float floatObject1 = new Float("10.0001");
    Float floatObject2 = new Float("10.0002");

    System.out.println(Float.compare(floatObject1, floatObject2));

}

From source file:Main.java

public static boolean isZero(float f) {
    return Float.compare(Math.abs(f), EPSILON) < 0;
}

From source file:Main.java

/**
 * Returns the indices that would sort an array.
 * @param array Array./*from w  w w  .j  ava  2s .  co  m*/
 * @param ascending Ascending order.
 * @return Array of indices.
 */
public static int[] Argsort(final float[] array, final boolean ascending) {
    Integer[] indexes = new Integer[array.length];
    for (int i = 0; i < indexes.length; i++) {
        indexes[i] = i;
    }
    Arrays.sort(indexes, new Comparator<Integer>() {
        @Override
        public int compare(final Integer i1, final Integer i2) {
            return (ascending ? 1 : -1) * Float.compare(array[i1], array[i2]);
        }
    });
    return asArray(indexes);
}

From source file:org.mrgeo.aggregators.MinAggregator.java

@Override
public float aggregate(float[] values, float nodata) {
    Float min = Float.MAX_VALUE;
    for (int i = 0; i < values.length; i++) {
        if (Float.compare(values[i], nodata) != 0)
            min = Math.min(min, values[i]);
    }/*from   w  w  w  .j a  v a  2 s.c o m*/
    return (min == Float.MAX_VALUE) ? nodata : min;
}

From source file:org.mrgeo.aggregators.MaxAggregator.java

@Override
public float aggregate(float[] values, float nodata) {
    Float max = -Float.MAX_VALUE;
    for (int i = 0; i < values.length; i++) {
        if (Float.compare(values[i], nodata) != 0)
            max = Math.max(max, values[i]);
    }/* w w  w . j a v a2s. c om*/
    return (max == -Float.MAX_VALUE) ? nodata : max;
}

From source file:org.mrgeo.aggregators.SumAggregator.java

@Override
public float aggregate(float[] values, float nodata) {
    float sum = 0;
    int count = 0;
    for (int i = 0; i < values.length; i++) {
        if (Float.compare(values[i], nodata) != 0) {
            sum += values[i];/*from www  .java 2 s. c  o m*/
            count++;
        }
    }
    return (count == 0) ? nodata : sum;
}

From source file:org.mrgeo.aggregators.NearestAggregator.java

@Override
public float aggregate(float[] values, float nodata) {
    boolean data0 = Float.compare(values[0], nodata) != 0;
    boolean data1 = Float.compare(values[1], nodata) != 0;
    boolean data2 = Float.compare(values[2], nodata) != 0;
    boolean data3 = Float.compare(values[3], nodata) != 0;

    if (data0)//from w w w.  ja v a 2  s .c o  m
        return values[0];
    if (data1)
        return values[1];
    if (data3)
        return values[3];
    if (data2)
        return values[2];

    return nodata;
}

From source file:org.mrgeo.aggregators.ModeAggregator.java

@Override
public float aggregate(float[] values, float nodata) {
    HashMap<Float, Integer> freqs = new HashMap<Float, Integer>();

    for (float val : values) {
        if (Float.compare(val, nodata) != 0) {
            Integer freq = freqs.get(val);
            freqs.put(val, (freq == null ? 1 : freq + 1));
        }//from   w  w  w.j  av  a2s  .  co m
    }

    float mode = nodata;
    int maxFreq = 0;

    for (Map.Entry<Float, Integer> entry : freqs.entrySet()) {
        int freq = entry.getValue();
        if (freq > maxFreq) {
            maxFreq = freq;
            mode = entry.getKey();
        }
    }

    return mode;
}

From source file:io.fouad.jtb.core.beans.Location.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    Location location = (Location) o;

    if (Float.compare(location.longitude, longitude) != 0)
        return false;
    return Float.compare(location.latitude, latitude) == 0;

}