Examples of Hasher


Examples of com.google.common.hash.Hasher

     * @param language language of the literal (optional)
     * @param type     datatype URI of the literal (optional)
     * @return a 64bit hash key for the literal
     */
    public static String createCacheKey(String content, Locale language, String type) {
        Hasher hasher = Hashing.goodFastHash(64).newHasher();
        hasher.putString(content);
        if(type != null) {
            hasher.putString(type);
        }
        if(language != null) {
            hasher.putString(language.getLanguage().toLowerCase());
        }
        return hasher.hash().toString();
    }
View Full Code Here

Examples of com.google.common.hash.Hasher

     *
     * @param l the literal to create the hash for
     * @return a 64bit hash key for the literal
     */
    public static String createCacheKey(Literal l) {
        Hasher hasher = Hashing.goodFastHash(64).newHasher();
        hasher.putString(l.getLabel());
        if(l.getDatatype() != null) {
            hasher.putString(l.getDatatype().stringValue());
        }
        if(l.getLanguage() != null) {
            hasher.putString(l.getLanguage().toLowerCase());
        }
        return hasher.hash().toString();
    }
View Full Code Here

Examples of com.google.common.hash.Hasher

    }
   
    public static String getETag(RepositoryConnection conn, URI resource) throws RepositoryException {
      if (resource == null) return "";
     
        Hasher hasher = buildHasher();
        hasher.putString(resource.stringValue());
        //FIXME: The order of the statements is not defined -> might result in different hash!
        RepositoryResult<Statement> outgoing = conn.getStatements(resource, null, null, true);
        try {
          while (outgoing.hasNext()) {
            Statement statement = outgoing.next();
            hasher.putString(statement.getPredicate().stringValue());
              hasher.putString(statement.getObject().stringValue());
              //TODO: statement modification date?
          }
        } finally {
          outgoing.close();
        }
        RepositoryResult<Statement> incoming = conn.getStatements(null, null, resource, true);
        try {
          while (incoming.hasNext()) {
            Statement statement = incoming.next();
            hasher.putString(statement.getSubject().stringValue());
            hasher.putString(statement.getPredicate().stringValue());
            //TODO: statement modification date?
          }   
        } finally {
          incoming.close();
        }
        return hasher.hash().toString();
    }
View Full Code Here

Examples of com.google.common.hash.Hasher

    }  
   
    public static String getWeakETag(RepositoryConnection conn, URI resource) throws RepositoryException {
      if (resource == null) return "";
     
        Hasher hasher = buildHasher();
        hasher.putString(resource.stringValue());
        //FIXME: The order of the statements is not defined -> might result in different hash!
        RepositoryResult<Statement> statements = conn.getStatements(resource, null, null, true);
        try {
          while (statements.hasNext()) {
            Statement statement = statements.next();
            hasher.putString(statement.getPredicate().stringValue());
            hasher.putString(statement.getObject().stringValue());
            //TODO: statement modification date?
          }
        } finally {
          statements.close();
        }
        return hasher.hash().toString();
    }
View Full Code Here

Examples of com.google.common.hash.Hasher

        return hasher.hash().toString();
    }

    private static Hasher buildHasher() {
        HashFunction function = Hashing.goodFastHash(16);
        Hasher hasher = function.newHasher();
        return hasher;
    }
View Full Code Here

Examples of com.google.common.hash.Hasher

    }

    @Override
    public int hashCode() {
        HashFunction hf = Hashing.goodFastHash(32);
        Hasher h = hf.newHasher();
        h.putInt(slots.size());
        for (int i=0; i<slots.size(); i++) {
            h.putInt(slots.get(i).size());
            for (int j=0; j<slots.size(); j++) {
                h.putBytes(slots.get(i).get(j).getLowerRange());
                h.putBytes(slots.get(i).get(j).getUpperRange());
            }
        }
        return h.hash().asInt();
    }
View Full Code Here

Examples of com.google.common.hash.Hasher


    @Override
    public int hashCode() {
        if(goodHashCode == null) {
            Hasher hash = hasher.newHasher().putChar('L').putString(getContent());
            if(getLocale() != null) {
                hash.putString(getLocale().toString());
            }
            if(getType() != null) {
                hash.putString(getType().stringValue());
            }
            goodHashCode = hash.hash();
        }
        return goodHashCode.hashCode();
    }
View Full Code Here

Examples of com.google.common.hash.Hasher

     */
    @Override
    protected  ObjectId _call() {
        Preconditions.checkState(object != null, "Object has not been set.");

        final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher();
        @SuppressWarnings("unchecked")
        final Funnel<RevObject> funnel = (Funnel<RevObject>) FUNNELS[object.getType().value()];
        funnel.funnel(object, hasher);
        final byte[] rawKey = hasher.hash().asBytes();
        final ObjectId id = ObjectId.createNoClone(rawKey);

        return id;
    }
View Full Code Here

Examples of com.google.common.hash.Hasher

    private HashCode getPartitionHash(PartitionContext partitionContext) {
        // The precise implementation of this method isn't particularly important.  There are lots of ways we can hash
        // the data in the PartitionContext.  It just needs to be deterministic and to take into account the values in
        // the PartitionContext for the configured partition keys.
        Hasher hasher = Hashing.md5().newHasher();
        boolean empty = true;
        if (_partitionKeys.isEmpty()) {
            // Use the default context.
            Object value = partitionContext.get();
            if (value != null) {
                hasher.putString(value.toString());
                empty = false;
            }
        }
        for (String partitionKey : _partitionKeys) {
            Object value = partitionContext.get(partitionKey);
            if (value != null) {
                // Include both the key and value in the hash so "reviewId" of 1 and "reviewerId" of 1 hash differently.
                hasher.putString(partitionKey);
                hasher.putString(value.toString());
                empty = false;
            }
        }
        if (empty) {
            // When the partition context has no relevant values that means we should ignore the partition context and
            // don't filter the end points based on partition.  Return null to indicate this.
            return null;
        }
        return hasher.hash();
    }
View Full Code Here

Examples of com.google.common.hash.Hasher

        // randomly generated ranges to each end point.  The individual ranges may vary widely in size, but, with
        // sufficient # of entries per end point, the overall amount of data assigned to each server tends to even out
        // with minimal variation (256 entries per server yields roughly 5% variation in server load).
        List<Integer> list = Lists.newArrayListWithCapacity(_entriesPerEndPoint);
        for (int i = 0; list.size() < _entriesPerEndPoint; i++) {
            Hasher hasher = Hashing.md5().newHasher();
            hasher.putInt(i);
            hasher.putString(endPointId);
            ByteBuffer buf = ByteBuffer.wrap(hasher.hash().asBytes());
            while (buf.hasRemaining() && list.size() < _entriesPerEndPoint) {
                list.add(buf.getInt());
            }
        }
        return list;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.