Example usage for com.google.common.hash Hasher putFloat

List of usage examples for com.google.common.hash Hasher putFloat

Introduction

In this page you can find the example usage for com.google.common.hash Hasher putFloat.

Prototype

@Override
Hasher putFloat(float f);

Source Link

Document

Equivalent to putInt(Float.floatToRawIntBits(f)) .

Usage

From source file:nextflow.util.CacheHelper.java

public static Hasher hasher(Hasher hasher, Object value, HashMode mode) {

    if (value == null)
        return hasher;

    if (value instanceof Boolean)
        return hasher.putBoolean((Boolean) value);

    if (value instanceof Short)
        return hasher.putShort((Short) value);

    if (value instanceof Integer)
        return hasher.putInt((Integer) value);

    if (value instanceof Long)
        return hasher.putLong((Long) value);

    if (value instanceof Float)
        return hasher.putFloat((Float) value);

    if (value instanceof Double)
        return hasher.putDouble((Double) value);

    if (value instanceof Number)
        // reduce all other number types (BigInteger, BigDecimal, AtomicXxx, etc) to string equivalent
        return hasher.putUnencodedChars(value.toString());

    if (value instanceof Character)
        return hasher.putChar((Character) value);

    if (value instanceof CharSequence)
        return hasher.putUnencodedChars((CharSequence) value);

    if (value instanceof Byte)
        return hasher.putByte((Byte) value);

    if (value instanceof byte[])
        return hasher.putBytes((byte[]) value);

    if (value instanceof Object[]) {
        for (Object item : ((Object[]) value))
            hasher = CacheHelper.hasher(hasher, item, mode);
        return hasher;
    }//from  w ww.j a v  a 2 s .  c om

    if (value instanceof Map) {
        // note: should map be order invariant as Set ?
        for (Object item : ((Map) value).values())
            hasher = CacheHelper.hasher(hasher, item, mode);
        return hasher;
    }

    if (value instanceof Bag || value instanceof Set)
        return hashUnorderedCollection(hasher, (Collection) value, mode);

    if (value instanceof Collection) {
        for (Object item : ((Collection) value))
            hasher = CacheHelper.hasher(hasher, item, mode);
        return hasher;
    }

    if (value instanceof FileHolder)
        return CacheHelper.hasher(hasher, ((FileHolder) value).getSourceObj(), mode);

    if (value instanceof Path)
        return hashFile(hasher, (Path) value, mode);

    if (value instanceof java.io.File)
        return hashFile(hasher, (java.io.File) value, mode);

    if (value instanceof UUID) {
        UUID uuid = (UUID) value;
        return hasher.putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits());
    }

    log.debug("[WARN] Unknown hashing type: {} -- {}", value.getClass(), value);
    return hasher.putInt(value.hashCode());
}

From source file:org.danilopianini.lang.HashUtils.java

private static void populateHasher(final Object data, final Hasher h) {
    if (data != null) {
        if (data instanceof Number) {
            final Number d = (Number) data;
            if (data instanceof Integer) {
                h.putInt(d.intValue());/*from   w w  w. j av  a 2s . c  om*/
            } else if (data instanceof Double) {
                h.putDouble(d.doubleValue());
            } else if (data instanceof Long) {
                h.putLong(d.longValue());
            } else if (data instanceof Float) {
                h.putFloat(d.floatValue());
            } else if (data instanceof Byte) {
                h.putByte(d.byteValue());
            } else if (data instanceof Short) {
                h.putShort(d.shortValue());
            } else {
                h.putInt(data.hashCode());
            }
        } else if (data instanceof CharSequence) {
            h.putString((CharSequence) data, CHARSET);
        } else if (data.getClass().isArray()) {
            final int size = Array.getLength(data);
            for (int i = 0; i < size; i++) {
                populateHasher(Array.get(data, i), h);
            }
        } else if (data instanceof Iterable) {
            for (final Object o : (Iterable<?>) data) {
                populateHasher(o, h);
            }
        } else {
            h.putInt(data.hashCode());
        }
    }
}

From source file:io.druid.query.aggregation.cardinality.types.FloatCardinalityAggregatorColumnSelectorStrategy.java

@Override
public void hashRow(BaseFloatColumnValueSelector selector, Hasher hasher) {
    hasher.putFloat(selector.getFloat());
}

From source file:org.apache.druid.query.aggregation.cardinality.types.FloatCardinalityAggregatorColumnSelectorStrategy.java

@Override
public void hashRow(BaseFloatColumnValueSelector selector, Hasher hasher) {
    if (NullHandling.replaceWithDefault() || !selector.isNull()) {
        hasher.putFloat(selector.getFloat());
    }/*  w  ww. j a  v  a2  s  . c om*/
}

From source file:com.facebook.buck.util.hash.AppendingHasher.java

@Override
public Hasher putFloat(float f) {
    for (Hasher hasher : hashers) {
        hasher.putFloat(f);
    }//from  w  w  w .j  a v  a 2  s .  co m
    return this;
}

From source file:edu.harvard.hms.dbmi.bd2k.irct.join.HashJoinImpl.java

private HashCode hashResultSetRow(int[] columns, PrimitiveDataType[] columnDataTypes, ResultSet resultSet)
        throws ResultSetException {
    Hasher columnHash = hashFunction.newHasher();

    for (int columnI = 0; columnI < columns.length; columnI++) {
        int column = columns[columnI];
        switch (columnDataTypes[columnI].getName()) {
        case "boolean":
            columnHash.putBoolean(resultSet.getBoolean(column));
            break;
        case "byte":
            columnHash.putByte(resultSet.getByte(column));
            break;
        case "double":
            columnHash.putDouble(resultSet.getDouble(column));
            break;
        case "float":
            columnHash.putFloat(resultSet.getFloat(column));
            break;
        case "integer":
            columnHash.putInt(resultSet.getInt(column));
            break;
        case "long":
            columnHash.putLong(resultSet.getLong(column));
            break;
        default:/*from  w ww .j  a  v a  2 s .  co m*/
            columnHash.putString(resultSet.getString(column), Charsets.UTF_8);
            break;
        }
    }

    return columnHash.hash();
}