Example usage for com.google.common.primitives Shorts saturatedCast

List of usage examples for com.google.common.primitives Shorts saturatedCast

Introduction

In this page you can find the example usage for com.google.common.primitives Shorts saturatedCast.

Prototype

public static short saturatedCast(long value) 

Source Link

Document

Returns the short nearest in value to value .

Usage

From source file:com.facebook.presto.type.BigintOperators.java

@ScalarOperator(SATURATED_FLOOR_CAST)
@SqlType(StandardTypes.SMALLINT)//from  ww w. j av a2  s  .com
public static long saturatedFloorCastToSmallint(@SqlType(StandardTypes.BIGINT) long value) {
    return Shorts.saturatedCast(value);
}

From source file:com.facebook.presto.type.setdigest.SetDigest.java

public void mergeWith(SetDigest other) {
    hll.mergeWith(other.hll);// ww  w.j  a v  a2  s. c  om
    LongBidirectionalIterator iterator = other.minhash.keySet().iterator();
    while (iterator.hasNext()) {
        long key = iterator.nextLong();
        int count = minhash.get(key) + other.minhash.get(key);
        minhash.put(key, Shorts.saturatedCast(count));
    }
    while (minhash.size() > maxHashes) {
        minhash.remove(minhash.lastLongKey());
    }
}

From source file:com.facebook.presto.type.IntegerOperators.java

@ScalarOperator(SATURATED_FLOOR_CAST)
@SqlType(StandardTypes.SMALLINT)//from  w w w  .  j  a v  a  2 s.c  o m
public static long saturatedFloorCastToSmallint(@SqlType(StandardTypes.INTEGER) long value) {
    return Shorts.saturatedCast(value);
}

From source file:io.prestosql.plugin.hive.statistics.MetastoreHiveStatisticsProvider.java

private static long normalizeIntegerValue(Type type, long value) {
    if (type.equals(BIGINT)) {
        return value;
    }/*www  .ja  v  a  2  s. c  om*/
    if (type.equals(INTEGER)) {
        return Ints.saturatedCast(value);
    }
    if (type.equals(SMALLINT)) {
        return Shorts.saturatedCast(value);
    }
    if (type.equals(TINYINT)) {
        return SignedBytes.saturatedCast(value);
    }
    throw new IllegalArgumentException("Unexpected type: " + type);
}