List of usage examples for com.google.common.hash Hasher putLong
@Override
Hasher putLong(long l);
From source file:fr.inria.eventcloud.api.Skolemizator.java
private static Node createSkolemUri(Node subjectOrObject, Map<Node, Node> assignedSkolems) { UUID randomId = UUID.randomUUID(); Hasher hasher = Hashing.murmur3_128().newHasher(); hasher.putString(subjectOrObject.toString(), Charsets.UTF_8); hasher.putLong(randomId.getMostSignificantBits()); hasher.putLong(randomId.getLeastSignificantBits()); Node skolem = NodeFactory/*from w w w.jav a 2 s . com*/ .createURI(SKOLEM_URI_SUFFIX + SKOLEM_URI_PATH_COMPONENT + hasher.hash().toString()); assignedSkolems.put(subjectOrObject, skolem); return skolem; }
From source file:nextflow.util.CacheHelper.java
/** * Hashes the file by using the metadata information: full path string, size and last update timestamp * * @param hasher The current {@code Hasher} object * @param file file The {@code Path} object to hash * @return The updated {@code Hasher} object *//*ww w . j a va2 s.c o m*/ static private Hasher hashFileMetadata(Hasher hasher, Path file) { hasher = hasher.putUnencodedChars(file.toAbsolutePath().normalize().toString()); try { BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class); hasher = hasher.putLong(attrs.size()); if (attrs.lastAccessTime() != null) { hasher = hasher.putLong(attrs.lastModifiedTime().toMillis()); } return hasher; } catch (IOException e) { log.debug("Unable to hash file: {} -- Cause: {}", file, e.toString()); return hasher; } }
From source file:com.attribyte.relay.wp.PostMeta.java
/** * Creates a unique fingerprint for a post. * @param post The post./* w w w . j av a 2 s . c o m*/ * @param hasher The hasher. */ public static final void fingerprint(final Post post, final Hasher hasher) { if (post == null) { return; } hasher.putString(Strings.nullToEmpty(post.slug), Charsets.UTF_8); hasher.putString(Strings.nullToEmpty(post.title), Charsets.UTF_8); hasher.putString(Strings.nullToEmpty(post.excerpt), Charsets.UTF_8); hasher.putString(Strings.nullToEmpty(post.content), Charsets.UTF_8); hasher.putLong(post.authorId); hasher.putLong(post.publishTimestamp); hasher.putString(post.status != null ? post.status.toString() : "", Charsets.UTF_8); hasher.putString(Strings.nullToEmpty(post.guid), Charsets.UTF_8); post.metadata.stream().sorted(Comparator.comparing(o -> o.key)).forEach(meta -> { hasher.putString(meta.key, Charsets.UTF_8).putString(Strings.nullToEmpty(meta.value), Charsets.UTF_8); }); hasher.putString(post.type != null ? post.type.toString() : "", Charsets.UTF_8); hasher.putString(Strings.nullToEmpty(post.mimeType), Charsets.UTF_8); post.tags().stream().sorted(Comparator.comparing(o -> o.term.name)).forEach(term -> { hasher.putString(term.term.name, Charsets.UTF_8); }); post.categories().stream().sorted(Comparator.comparing(o -> o.term.name)).forEach(term -> { hasher.putString(term.term.name, Charsets.UTF_8); }); post.children.forEach(childPost -> fingerprint(childPost, hasher)); }
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; }//w w w .j a va 2 s .c o m 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 ww. j ava 2s.c o m*/ } 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:fr.ens.biologie.genomique.eoulsan.modules.mapping.hadoop.ReadsMapperHadoopModule.java
/** * Compute the checksum of a ZIP file.//from w w w .j a v a 2 s .co m * @param in input stream * @return the checksum as a string * @throws IOException if an error occurs while creating the checksum */ private static String computeZipCheckSum(final InputStream in) throws IOException { ZipArchiveInputStream zais = new ZipArchiveInputStream(in); // Create Hash function final Hasher hs = Hashing.md5().newHasher(); // Store entries in a map final Map<String, long[]> map = new HashMap<>(); ZipArchiveEntry e; while ((e = zais.getNextZipEntry()) != null) { map.put(e.getName(), new long[] { e.getSize(), e.getCrc() }); } zais.close(); // Add values to hash function in an ordered manner for (String filename : new TreeSet<>(map.keySet())) { hs.putString(filename, StandardCharsets.UTF_8); for (long l : map.get(filename)) { hs.putLong(l); } } return hs.hash().toString(); }
From source file:io.druid.query.aggregation.cardinality.types.LongCardinalityAggregatorColumnSelectorStrategy.java
@Override public void hashRow(BaseLongColumnValueSelector dimSelector, Hasher hasher) { hasher.putLong(dimSelector.getLong()); }
From source file:com.google.gerrit.server.util.RequestId.java
private RequestId(String resourceId) { Hasher h = Hashing.sha1().newHasher(); h.putLong(Thread.currentThread().getId()).putUnencodedChars(MACHINE_ID); str = "[" + resourceId + "-" + TimeUtil.nowTs().getTime() + "-" + h.hash().toString().substring(0, 8) + "]"; }
From source file:org.apache.druid.query.aggregation.cardinality.types.LongCardinalityAggregatorColumnSelectorStrategy.java
@Override public void hashRow(BaseLongColumnValueSelector selector, Hasher hasher) { if (NullHandling.replaceWithDefault() || !selector.isNull()) { hasher.putLong(selector.getLong()); }//from w w w . j a v a 2 s. c o m }
From source file:com.spotify.heroic.metric.Spread.java
@Override public void hash(final Hasher hasher) { hasher.putInt(MetricType.SPREAD.ordinal()); hasher.putLong(timestamp); hasher.putLong(count);//from w w w.jav a 2 s .c o m hasher.putDouble(sum); hasher.putDouble(sum2); hasher.putDouble(min); hasher.putDouble(max); }