in flink-ml-lib/src/main/java/org/apache/flink/ml/feature/hashingtf/HashingTF.java [161:193]
private static int hash(Object obj) {
if (obj == null) {
return 0;
} else if (obj instanceof Boolean) {
int value = (Boolean) obj ? 1 : 0;
return HASH_FUNC.hashInt(value).asInt();
} else if (obj instanceof Byte) {
byte value = (Byte) obj;
return HASH_FUNC.hashInt(value).asInt();
} else if (obj instanceof Short) {
short value = (Short) obj;
return HASH_FUNC.hashInt(value).asInt();
} else if (obj instanceof Integer) {
int value = (Integer) obj;
return HASH_FUNC.hashInt(value).asInt();
} else if (obj instanceof Long) {
long value = (Long) obj;
return HASH_FUNC.hashLong(value).asInt();
} else if (obj instanceof Float) {
float value = (Float) obj;
return HASH_FUNC.hashInt(Float.floatToIntBits(value)).asInt();
} else if (obj instanceof Double) {
double value = (Double) obj;
return HASH_FUNC.hashLong(Double.doubleToLongBits(value)).asInt();
} else if (obj instanceof String) {
return HASH_FUNC.hashUnencodedChars((String) obj).asInt();
} else {
throw new UnsupportedOperationException(
"HashingTF does not support type "
+ obj.getClass().getCanonicalName()
+ " of input data.");
}
}