Example usage for com.google.common.primitives Floats compare

List of usage examples for com.google.common.primitives Floats compare

Introduction

In this page you can find the example usage for com.google.common.primitives Floats compare.

Prototype

public static int compare(float a, float b) 

Source Link

Document

Compares the two specified float values using Float#compare(float,float) .

Usage

From source file:net.bafeimao.umbrella.support.util.Numbers.java

public static int compare(Object a, Object b) {

    if (!a.getClass().equals(b.getClass())) {
        throw new IllegalArgumentException("class type not the same");
    }//from   ww  w. j  a  v  a 2s  . c  o m

    // TODO use instanceof instead
    Class<?> clazz = a.getClass();

    int result = 0;

    if (clazz.equals(Double.class)) {
        result = Doubles.compare((Double) a, (Double) b);
    } else if (clazz.equals(Float.class)) {
        result = Floats.compare((Float) a, (Float) b);
    } else if (clazz.equals(Long.class)) {
        result = Longs.compare((Long) b, (Long) b);
    } else if (clazz.equals(Integer.class)) {
        result = Ints.compare((Integer) a, (Integer) b);
    } else if (clazz.equals(Short.class)) {
        result = Shorts.compare((Short) a, (Short) b);
    } else if (clazz.equals(Byte.class)) {
        result = Shorts.compare((Short) a, (Short) b);
    }

    return result;
}

From source file:task3.Task3.java

static Book getMaxPrice(List<Book> books) {
    Ordering<Book> o = new Ordering<Book>() {
        @Override/*from   w w  w .j  ava 2 s  .com*/
        public int compare(Book left, Book right) {
            return Floats.compare(left.getPrice(), right.getPrice());
        }
    };
    return o.max(books);
}

From source file:io.druid.query.groupby.having.HavingSpecMetricComparator.java

static int compare(Row row, String aggregationName, Number value) {
    Object metricValueObj = row.getRaw(aggregationName);
    if (metricValueObj != null) {
        if (metricValueObj instanceof Long) {
            long l = ((Long) metricValueObj).longValue();
            return Longs.compare(l, value.longValue());
        } else if (metricValueObj instanceof String) {
            String metricValueStr = (String) metricValueObj;
            if (LONG_PAT.matcher(metricValueStr).matches()) {
                long l = row.getLongMetric(aggregationName);
                return Longs.compare(l, value.longValue());
            }//from   w ww  .j  ava 2 s.co m
        }
    }

    float f = row.getFloatMetric(aggregationName);
    return Floats.compare(f, value.floatValue());
}

From source file:org.n52.iceland.util.Comparables.java

public static int compare(float a, float b) {
    return Floats.compare(a, b);
}

From source file:com.greplin.interval.FloatInterval.java

@Override
public int compareTo(final FloatInterval other) {
    return Floats.compare(this.start, other.start);
}

From source file:org.apache.tajo.tuple.memory.OffHeapRowBlockUtils.java

public static final int compareColumn(UnSafeTuple tuple1, UnSafeTuple tuple2, int index,
        TajoDataTypes.Type type, boolean ascending, boolean nullFirst) {
    final boolean n1 = tuple1.isBlankOrNull(index);
    final boolean n2 = tuple2.isBlankOrNull(index);
    if (n1 && n2) {
        return 0;
    }/*from   ww  w . ja va2 s  .  co m*/

    if (n1 ^ n2) {
        return nullFirst ? (n1 ? -1 : 1) : (n1 ? 1 : -1);
    }

    int compare;
    switch (type) {
    case BOOLEAN:
        compare = Booleans.compare(tuple1.getBool(index), tuple2.getBool(index));
        break;
    case BIT:
        compare = tuple1.getByte(index) - tuple2.getByte(index);
        break;
    case INT1:
    case INT2:
        compare = Shorts.compare(tuple1.getInt2(index), tuple2.getInt2(index));
        break;
    case DATE:
    case INT4:
        compare = Ints.compare(tuple1.getInt4(index), tuple2.getInt4(index));
        break;
    case TIME:
    case TIMESTAMP:
    case INT8:
        compare = Longs.compare(tuple1.getInt8(index), tuple2.getInt8(index));
        break;
    case FLOAT4:
        compare = Floats.compare(tuple1.getFloat4(index), tuple2.getFloat4(index));
        break;
    case FLOAT8:
        compare = Doubles.compare(tuple1.getFloat8(index), tuple2.getFloat8(index));
        break;
    case CHAR:
    case TEXT:
    case BLOB:
        compare = UnSafeTupleBytesComparator.compare(tuple1.getFieldAddr(index), tuple2.getFieldAddr(index));
        break;
    default:
        throw new TajoRuntimeException(new UnsupportedException("unknown data type '" + type.name() + "'"));
    }
    return ascending ? compare : -compare;
}

From source file:org.caleydo.view.domino.internal.data.ProjectedDataValues.java

@Override
public int compare(EDimension dim, int a, int b, ITypedCollection otherData) {
    if (dim == this.along)
        return 0;
    return Floats.compare(getNormalized(a), getNormalized(b));
}

From source file:org.caleydo.view.domino.internal.data.ADataDomainDataValues.java

@Override
public int compare(EDimension dim, int a, int b, ITypedCollection otherData) {
    switch (otherData.size()) {
    case 0:/*  w  w  w .jav a 2  s. com*/
        return a - b;
    case 1:
        Integer other = otherData.iterator().next();
        return Floats.compare(getNormalized(dim, a, other), getNormalized(dim, b, other));
    default:
        //
        float a_sum = getCached(dim, a, otherData);
        float b_sum = getCached(dim, b, otherData);
        return Floats.compare(a_sum, b_sum);
    }
}

From source file:net.awairo.mcmod.spawnchecker.presetmode.spawncheck.CopiedLogics.java

/**
 * ????.//  w  ww.ja va 2s .  c  o  m
 * 
 * <p>
 * ???????
 * ???????????
 * ?????????????????????
 * ???????????????????????????????
 * ???????????????????????????
 * </p>
 * 
 * @param x x
 * @param y y
 * @param z z
 * @return true ???????
 */
public boolean canSpawnByLightBrightness(int x, int y, int z) {
    int skyLightValue = getSavedLightValue(EnumSkyBlock.Sky, x, y, z);

    // 15??????
    if (skyLightValue < 15) {
        return Floats.compare(config.spawnableMaxLightValue, getLightBrightness(x, y, z)) >= 0;
    }

    // ????????
    final int time = (int) (game.theWorld.getWorldTime() % 24000L);

    // 10???????
    // ????????????165???????????
    final int adjustmentDivisor = 165;

    // TODO: ?(1700)?(1650)????
    final int dusk = 12000;
    final int sunset = 13650;
    final int sunrise = 22300;

    // ??lightValue -4 ????
    int lightValueMinus4;

    if (time < dusk) {
        // 
        lightValueMinus4 = 10;
    } else if (time < sunset) {
        // ????? (01650)/ adjustmentDivisor
        lightValueMinus4 = (sunset - time) / adjustmentDivisor;
    } else if (time < sunrise) {
        // 
        lightValueMinus4 = 0;
    } else {
        // ?????? (01700)/ adjustmentDivisor
        lightValueMinus4 = (time - sunrise) / adjustmentDivisor;
    }

    // ???10????????-5?????????
    // ??????
    lightValueMinus4 = Math.max(lightValueMinus4, getSavedLightValue(EnumSkyBlock.Block, x, y, z) - 5);
    float brightness = getLightBrightness(lightValueMinus4);
    return Floats.compare(config.spawnableMaxLightValue, brightness) >= 0;
}

From source file:org.caleydo.view.domino.internal.data.CorrelatedDataValues.java

@Override
public int compare(EDimension dim, int a, int b, ITypedCollection otherData) {
    switch (otherData.size()) {
    case 0:/* w ww .ja  v  a 2s.  c  o m*/
        return a - b;
    case 1:
        Integer other = otherData.iterator().next();
        return Floats.compare(getNormalized(a, other), getNormalized(b, other));
    default:
        //
        float a_sum = getCached(dim, a, otherData);
        float b_sum = getCached(dim, b, otherData);
        return Floats.compare(a_sum, b_sum);
    }
}