Java Code Examples for com.google.common.hash.PrimitiveSink#putString()
The following examples show how to use
com.google.common.hash.PrimitiveSink#putString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KarelDbCellId.java From kareldb with Apache License 2.0 | 5 votes |
@Override public void funnel(Comparable[] array, PrimitiveSink into) { for (Comparable c : array) { if (c instanceof Boolean) { into.putBoolean((Boolean) c); } else if (c instanceof Integer) { into.putInt((Integer) c); } else if (c instanceof Long) { into.putLong((Long) c); } else if (c instanceof Float) { into.putFloat((Float) c); } else if (c instanceof Double) { into.putDouble((Double) c); } else if (c instanceof ByteString) { into.putBytes(((ByteString) c).getBytes()); } else if (c instanceof String) { into.putString((String) c, UTF_8); } else if (c instanceof BigDecimal) { into.putDouble(((BigDecimal) c).doubleValue()); } else if (c instanceof Date) { into.putLong(((Date) c).getTime()); } else if (c instanceof Time) { into.putLong(((Time) c).getTime()); } else if (c instanceof Timestamp) { into.putLong(((Timestamp) c).getTime()); } else { throw new IllegalArgumentException("Unsupported object of type " + c.getClass().getName()); } } }
Example 2
Source File: LocationStrategy.java From datawave with Apache License 2.0 | 5 votes |
public void funnel(RangeSplit rangeSplit, PrimitiveSink sink) { try { for (String location : rangeSplit.getLocations()) { sink.putString(location.trim().toLowerCase()); } } catch (IOException e) { log.error(e); } }
Example 3
Source File: ProbableIntersectionCursorState.java From fdb-record-layer with Apache License 2.0 | 5 votes |
@Override public void funnel(List<Object> objects, PrimitiveSink primitiveSink) { for (Object o : objects) { if (o == null) { primitiveSink.putByte((byte)0x00); } else if (o instanceof byte[]) { primitiveSink.putBytes((byte[])o); } else if (o instanceof ByteString) { primitiveSink.putBytes(((ByteString)o).toByteArray()); } else if (o instanceof ByteBuffer) { primitiveSink.putBytes((ByteBuffer) o); } else if (o instanceof String) { primitiveSink.putString((String)o, Charsets.UTF_8); } else if (o instanceof Float) { primitiveSink.putFloat((float)o); } else if (o instanceof Double) { primitiveSink.putDouble((double)o); } else if (o instanceof Integer) { primitiveSink.putInt((int)o); } else if (o instanceof Long) { primitiveSink.putLong((long) o); } else if (o instanceof Boolean) { primitiveSink.putBoolean((boolean)o); } else if (o instanceof Enum) { primitiveSink.putInt(((Enum)o).ordinal()); } else { primitiveSink.putBytes(Tuple.from(o).pack()); } } }
Example 4
Source File: EdgeMetadataSerializationV2Impl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public void funnel( final Id from, final PrimitiveSink into ) { final UUID id = from.getUuid(); final String type = from.getType(); into.putLong( id.getMostSignificantBits() ); into.putLong( id.getLeastSignificantBits() ); into.putString( type, StringHashUtils.UTF8 ); }
Example 5
Source File: EdgeMetadataSerializationV2Impl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public void funnel( final EdgeIdTypeKey from, final PrimitiveSink into ) { final UUID id = from.node.getUuid(); final String type = from.node.getType(); into.putLong( id.getMostSignificantBits() ); into.putLong( id.getLeastSignificantBits() ); into.putString( type, StringHashUtils.UTF8 ); into.putString( from.edgeType, StringHashUtils.UTF8 ); }
Example 6
Source File: TermFilter.java From datawave with Apache License 2.0 | 4 votes |
@Override public void funnel(T from, PrimitiveSink into) { into.putString(from.toString()); }
Example 7
Source File: CorporaBloomFilter.java From modernmt with Apache License 2.0 | 4 votes |
@Override public void funnel(String from, PrimitiveSink into) { into.putString(from, UTF8Charset.get()); }
Example 8
Source File: BloomFilterBuilder.java From bboxdb with Apache License 2.0 | 4 votes |
@Override public void funnel(final String argument, final PrimitiveSink into) { into.putString(argument, Charsets.UTF_8); }
Example 9
Source File: HashingUtil.java From datacollector with Apache License 2.0 | 4 votes |
@Override public void funnel(Record record, PrimitiveSink sink) { for (String path : getFieldsToHash(record)) { Field field = record.get(path); if (field == null) { throw new IllegalArgumentException( Utils.format("Field Path {} does not exist in the record", path) ); } if (field.getValue() != null) { switch (field.getType()) { case BOOLEAN: sink.putBoolean(field.getValueAsBoolean()); break; case CHAR: sink.putChar(field.getValueAsChar()); break; case BYTE: sink.putByte(field.getValueAsByte()); break; case SHORT: sink.putShort(field.getValueAsShort()); break; case INTEGER: sink.putInt(field.getValueAsInteger()); break; case LONG: sink.putLong(field.getValueAsLong()); break; case FLOAT: sink.putFloat(field.getValueAsFloat()); break; case DOUBLE: sink.putDouble(field.getValueAsDouble()); break; case DATE: sink.putLong(field.getValueAsDate().getTime()); break; case TIME: sink.putLong(field.getValueAsTime().getTime()); break; case DATETIME: sink.putLong(field.getValueAsDatetime().getTime()); break; case DECIMAL: case STRING: sink.putString(field.getValueAsString(), Charset.defaultCharset()); break; case BYTE_ARRAY: sink.putBytes(field.getValueAsByteArray()); break; case FILE_REF: throw new IllegalStateException( Utils.format( "Hashing not supported for field: {} of type {}", path, field.getType() ) ); default: break; } } else { sink.putBoolean(true); } if(useSeparators) { sink.putString(java.nio.CharBuffer.wrap(new char[] {separator}), Charset.forName("UTF-8")); } } if (this.includeRecordHeader) { for (String attrName : record.getHeader().getAttributeNames()) { String headerAttr = record.getHeader().getAttribute(attrName); if (headerAttr != null) { sink.putString(headerAttr, Charset.defaultCharset()); } else { sink.putBoolean(true); } if(useSeparators) { sink.putString(java.nio.CharBuffer.wrap(new char[] {separator}), Charset.forName("UTF-8")); } } } }
Example 10
Source File: TestFieldHasherProcessor.java From datacollector with Apache License 2.0 | 4 votes |
static String computeHash(Field.Type fieldType, Object value, HashType hashType) { HashFunction hasher = HashingUtil.getHasher(hashType.getHashType()); PrimitiveSink sink = hasher.newHasher(); switch (fieldType) { case BOOLEAN: sink.putBoolean(new BooleanTypeSupport().convert(value)); break; case CHAR: sink.putChar(new CharTypeSupport().convert(value)); break; case BYTE: sink.putByte(new ByteTypeSupport().convert(value)); break; case SHORT: sink.putShort(new ShortTypeSupport().convert(value)); break; case INTEGER: sink.putInt(new IntegerTypeSupport().convert(value)); break; case LONG: sink.putLong(new LongTypeSupport().convert(value)); break; case FLOAT: sink.putFloat(new FloatTypeSupport().convert(value)); break; case DOUBLE: sink.putDouble(new DoubleTypeSupport().convert(value)); break; case DATE: sink.putLong(new DateTypeSupport().convert(value).getTime()); break; case TIME: sink.putLong(new DateTypeSupport().convert(value).getTime()); break; case DATETIME: sink.putLong(new DateTypeSupport().convert(value).getTime()); break; case DECIMAL: sink.putString(new StringTypeSupport().convert(value), Charset.defaultCharset()); break; case STRING: sink.putString(new StringTypeSupport().convert(value), Charset.defaultCharset()); break; case BYTE_ARRAY: sink.putBytes(new ByteArrayTypeSupport().convert(value)); break; case MAP: case LIST: default: return null; } // this was the problem in SDC-6540. sink.putByte((byte)0); return ((Hasher)sink).hash().toString(); }
Example 11
Source File: ClusterMetadata.java From onos with Apache License 2.0 | 4 votes |
@Override public void funnel(ClusterMetadata cm, PrimitiveSink into) { into.putString(cm.name, UTF_8); }
Example 12
Source File: ShardLocatorTest.java From usergrid with Apache License 2.0 | 4 votes |
@Override public void funnel( final String from, final PrimitiveSink into ) { into.putString( from, UTF8 ); }