List of usage examples for com.google.common.hash Hasher putBoolean
@Override
Hasher putBoolean(boolean b);
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; }// ww w. j av a 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:com.facebook.buck.util.hash.AppendingHasher.java
@Override public Hasher putBoolean(boolean b) { for (Hasher hasher : hashers) { hasher.putBoolean(b); }/*www . j a v a2 s . com*/ return this; }
From source file:com.google.gerrit.server.change.GetRevisionActions.java
@Override public String getETag(RevisionResource rsrc) { Hasher h = Hashing.md5().newHasher(); CurrentUser user = rsrc.getControl().getUser(); try {/*from www.j ava 2s . c o m*/ rsrc.getChangeResource().prepareETag(h, user); h.putBoolean(Submit.wholeTopicEnabled(config)); ReviewDb db = dbProvider.get(); ChangeSet cs = mergeSuperSet.get().completeChangeSet(db, rsrc.getChange(), user); for (ChangeData cd : cs.changes()) { changeResourceFactory.create(cd.changeControl()).prepareETag(h, user); } h.putBoolean(cs.furtherHiddenChanges()); } catch (IOException | OrmException e) { throw new OrmRuntimeException(e); } return h.hash().toString(); }
From source file:com.yahoo.yqlplus.api.types.YQLStructType.java
@Override public void hashTo(Hasher digest) { super.hashTo(digest); for (YQLNamePair field : fields.values()) { field.hashTo(digest);//from w w w . ja va 2s .c om } digest.putBoolean(closed); }
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 w w .ja v a 2s .c o m columnHash.putString(resultSet.getString(column), Charsets.UTF_8); break; } } return columnHash.hash(); }
From source file:org.lightjason.agentspeak.language.CLiteral.java
/** * ctor//from w ww . j av a2 s .c o m * * @param p_at @ prefix is set * @param p_negated negated flag * @param p_functor functor of the literal * @param p_values initial list of values * @param p_annotations initial set of annotations */ public CLiteral(final boolean p_at, final boolean p_negated, final IPath p_functor, final Collection<ITerm> p_values, final Collection<ILiteral> p_annotations) { m_at = p_at; m_negated = p_negated; // create a full copy of the functor, because concurrency modification m_functor = new CPath(p_functor); // create immutable structures final Multimap<IPath, ILiteral> l_annotations = HashMultimap.create(); p_annotations.forEach(i -> l_annotations.put(i.fqnfunctor(), i)); m_annotations = ImmutableSetMultimap.copyOf(l_annotations); final Multimap<IPath, ITerm> l_values = LinkedListMultimap.create(); p_values.forEach(i -> l_values.put(i.fqnfunctor(), i)); m_values = ImmutableListMultimap.copyOf(l_values); m_orderedvalues = Collections.unmodifiableList(new LinkedList<>(p_values)); // calculates hash value m_hash = m_functor.hashCode() ^ IntStream.range(0, m_orderedvalues.size()).boxed() .mapToInt(i -> (i + 1) * m_orderedvalues.get(i).hashCode()).sum() ^ m_annotations.values().stream().mapToInt(Object::hashCode).sum() ^ (m_negated ? 0 : 55529) ^ (m_at ? 0 : 8081); // calculates the structure hash value (Murmur3) of the value and annotation definition // functor will be added iif no literal data exists ( hasher must be existing twice ) final String l_functor = p_functor.getPath(); final Hasher l_valuehasher = CCommon.getTermHashing(); if (m_orderedvalues.stream().filter(i -> i instanceof ILiteral) .map(i -> l_valuehasher.putInt(((ILiteral) i).valuehash())).count() == 0) { l_valuehasher.putBoolean(m_negated); l_valuehasher.putString(l_functor, Charsets.UTF_8); } final Hasher l_annotationhasher = CCommon.getTermHashing(); if (m_annotations.values().stream().map(i -> l_annotationhasher.putInt(i.valuehash())).count() == 0) { l_annotationhasher.putBoolean(m_negated); l_annotationhasher.putString(l_functor, Charsets.UTF_8); } m_annotationhash = l_annotationhasher.hash().asInt(); m_valuehash = l_valuehasher.hash().asInt(); }
From source file:com.facebook.buck.util.hashing.FilePathHashLoader.java
@Override public HashCode get(Path root) throws IOException { // In case the root path is a directory, collect all files contained in it and sort them before // hashing to avoid non-deterministic directory traversal order from influencing the hash. ImmutableSortedSet.Builder<Path> files = ImmutableSortedSet.naturalOrder(); Files.walkFileTree(defaultCellRoot.resolve(root), ImmutableSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override//from w ww . j a va 2 s . c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { files.add(file); return FileVisitResult.CONTINUE; } }); Hasher hasher = Hashing.sha1().newHasher(); for (Path file : files.build()) { file = resolvePath(file); boolean assumeModified = assumeModifiedFiles.contains(file); Path relativePath = MorePaths.relativize(defaultCellRoot, file); // For each file add its path to the hasher suffixed by whether we assume the file to be // modified or not. This way files with different paths always result in different hashes and // files that are assumed to be modified get different hashes than all unmodified files. StringHashing.hashStringAndLength(hasher, relativePath.toString()); hasher.putBoolean(assumeModified); } return hasher.hash(); }
From source file:com.facebook.buck.hashing.FilePathHashLoader.java
@Override public HashCode get(Path root) throws IOException { // In case the root path is a directory, collect all files contained in it and sort them before // hashing to avoid non-deterministic directory traversal order from influencing the hash. final ImmutableSortedSet.Builder<Path> files = ImmutableSortedSet.naturalOrder(); Files.walkFileTree(defaultCellRoot.resolve(root), ImmutableSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override// w ww. j a v a 2 s .c om public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { files.add(file); return FileVisitResult.CONTINUE; } }); Hasher hasher = Hashing.sha1().newHasher(); for (Path file : files.build()) { file = defaultCellRoot.resolve(file).toRealPath(); boolean assumeModified = assumeModifiedFiles.contains(file); Path relativePath = MorePaths.relativize(defaultCellRoot, file); // For each file add its path to the hasher suffixed by whether we assume the file to be // modified or not. This way files with different paths always result in different hashes and // files that are assumed to be modified get different hashes than all unmodified files. StringHashing.hashStringAndLength(hasher, relativePath.toString()); hasher.putBoolean(assumeModified); } return hasher.hash(); }
From source file:com.facebook.buck.cxx.PreprocessorDelegate.java
public String hashCommand(ImmutableList<String> flags) { Hasher hasher = Hashing.murmur3_128().newHasher(); String workingDirString = workingDir.toString(); // Skips the executable argument (the first one) as that is not sanitized. for (String part : sanitizer.sanitizeFlags(Iterables.skip(flags, 1))) { // TODO(#10251354): find a better way of dealing with getting a project dir normalized hash if (part.startsWith(workingDirString)) { part = "<WORKINGDIR>" + part.substring(workingDirString.length()); }/* w w w .jav a 2 s .co m*/ hasher.putString(part, Charsets.UTF_8); hasher.putBoolean(false); // separator } return hasher.hash().toString(); }
From source file:zotmc.collect.recipe.BasicRecipeView.java
@Override public int hashCode() { Hasher h = Hashing.goodFastHash(32).newHasher().putInt(asInfo(getOutput()).hashCode()); Category cat = getCategory();/* w w w .j a v a 2 s. c om*/ if (cat == SHAPED) { h.putBoolean(false).putBoolean(true); Matrix<RecipeElement> input = getShapedInput(); if (isMirrored()) h.putInt(input.hashCode() ^ horizontalMirror(input).hashCode()); else h.putInt(input.hashCode()); } else if (cat == SHAPELESS) h.putBoolean(true).putBoolean(false).putInt(getShapelessInput().hashCode()); else h.putBoolean(false).putBoolean(false); return h.hash().asInt(); }