Package com.google.common.hash

Examples of com.google.common.hash.Hasher


  // FINGERPRINTABLE METHODS
  //

  @Override
  public String getFingerprint() {
    Hasher hash = Hashing.sha256().newHasher();
    hash.putString("Album(");
    hash.putString("ID(").putString(id).putString(")");
    hash.putString("Title(").putString(title).putString(")");
    hash.putString("Description(").putString(description).putString(")");
    if (albumImage != null) {
      hash.putString("AlbumImage(").putString(albumImage).putString(")");
    }

    /* add nested albums. */
    hash.putString("Albums(");
    for (Album album : albums) {
      hash.putString(album.getFingerprint());
    }
    hash.putString(")");

    /* add images. */
    hash.putString("Images(");
    for (Image image : getImages()) {
      if (image.isInserted()) {
        hash.putString(image.getFingerprint());
      }
    }
    hash.putString(")");

    hash.putString(")");
    return hash.hash().toString();
  }
View Full Code Here


     *
     * @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

     * @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

    }
   
    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

//    }
   
    public static String getWeakETag(RepositoryConnection conn, Resource 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

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

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

        this.data = data;
    }

    private void ensureHashCode() {
        if(goodHashCode == null) {
            Hasher hasher = hashFunction.newHasher();
            for(int i : data) {
                hasher.putInt(i);
            }
            goodHashCode = hasher.hash();
        }
    }
View Full Code Here

        this.data = data;
    }

    private void ensureHashCode() {
        if(hashCode32 == null) {
            Hasher hasher = hashFunction32.newHasher();
            for(int i : data) {
                hasher.putInt(i);
            }
            hashCode32 = hasher.hash();
        }
    }
View Full Code Here

        }
    }

    private void ensureLongHashCode() {
        if(hashCode64 == null) {
            Hasher hasher = hashFunction64.newHasher();
            for(int i : data) {
                hasher.putInt(i);
            }
            hashCode64 = hasher.hash();
        }

    }
View Full Code Here

     * @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, Charset.defaultCharset());
        if(type != null) {
            hasher.putString(type, Charset.defaultCharset());
        }
        if(language != null) {
            hasher.putString(language.getLanguage().toLowerCase(), Charset.defaultCharset());
        }
        return hasher.hash().toString();
    }
View Full Code Here

TOP

Related Classes of com.google.common.hash.Hasher

Copyright © 2018 www.massapicom. 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.