HashFunction newHasher - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for HashFunction newHasher method.

This code example shows how to use the following methods:newHasher
public class HashOutputStream extends OutputStream {
 
    private Hasher hasher;
 
    public HashOutputStream(HashFunction hf) {
        hasher = hf.newHasher();
    } 
 
    @Override 
    public void write(int b) throws IOException {
        hasher.putInt(b);
    } 
 
    public HashCode getHashCode() {
        return hasher.hash();
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:newHasher
            .withNoArguments() 
            .will(returnValue(this.mockHasher.proxy()));
        this.abstractChecksumProvider = new AbstractChecksumProvider(
                (HashFunction) mockHashFunction.proxy());
    } 
 
    @Test
    public void testPutBytesWithByteArray() { 
        this.mockHasher.expects(once()).method("putBytes");
        Object actual = this.abstractChecksumProvider.putBytes("abc".getBytes());
        Assert.assertTrue(actual instanceof AbstractChecksumProvider);
    } 
 
    @Test
    public void testPutBytesWithByteBuffer() { 
        this.mockHasher.expects(once()).method("putBytes");
        Object actual = this.abstractChecksumProvider.putBytes(
                ByteBuffer.wrap("abc".getBytes()));
        Assert.assertTrue(actual instanceof AbstractChecksumProvider);
    } 
5
CodeRank
This code example shows how to use the following methods:newHasher
     * Protected ctor. There should not be an instance of this class. 
     * @param hashFunction 
     */ 
    protected AbstractChecksumProvider(HashFunction hashFunction) {
        this.hashFunction = hashFunction;
        this.hasher = this.hashFunction.newHasher();
    } 
 
    /** 
     * @see ChecksumProvider#putBytes(byte[]) 
     */ 
    public ChecksumProvider putBytes(byte[] byteArray) {
        return this.putBytes(byteArray, 0, byteArray.length);
    } 
 
    /** 
     * @see ChecksumProvider#putBytes(byte[], int, int) 
     */ 
    public ChecksumProvider putBytes(byte[] byteArray, int offset, int length) {
        this.verifyState(this.hashBytes, this.hashString);
5
CodeRank
This code example shows how to use the following methods:newHasher
     * 
     * @param hashFunction 
     */ 
    public Anonymizer(final String hashFunction) {
        hf = HASH_FUNCTIONS.get(hashFunction);
        hasher = hf.newHasher();
    } 
 
    /** 
     * 
     * @param ipAddress 
     * @param userAgent 
     * @return 
     */ 
    public final String generateHash(final String ipAddress, final String userAgent) {
        HashCode hc = this.hasher.
            putString(ipAddress).
            putString(userAgent).
            hash(); 
        return hc.toString();
4
CodeRank
This code example shows how to use the following methods:newHasher
     * Create a description writer for a particular hash function. 
     * @param func The hash function. 
     * @return A description writer that computes a hash using {@code func}. 
     */ 
    public static HashDescriptionWriter hashWriter(HashFunction func) {
        return new HashDescriptionWriter(func.newHasher());
    } 
 
    /** 
     * Construct a new description writer that outputs a string. 
     * @return A string description writer. 
     */ 
    public static StringDescriptionWriter stringWriter() { 
        return new StringDescriptionWriter(); 
    } 
 
    /** 
     * Get a default describer.  This describer uses the following algorithm: 
     * <ol> 
     * <li>If the object is {@link Describable}, call its its {@link Describable#describeTo(DescriptionWriter)} method.</li> 
3
CodeRank
This code example shows how to use the following methods:newHasher
This code example shows how to use the following methods:newHasher
    /** 
     * Repository@revision should be sufficient to uniquely identify a revision 
     * @return  a loosely constructed hashcode converted to String 
     */ 
    public String id() {
        return hf.newHasher()
                .putUnencodedChars(repository)
                .putLong(revision)
                .hash()
                .toString();
    } 
 
 
} 
4
CodeRank
This code example shows how to use the following methods:newHasher
        reset(); 
    } 
 
    @Override 
    public void reset() { 
        this.hasher = hf.newHasher();
    } 
 
    @Override 
    public void update(byte b) {
        hasher.putByte(b);
    } 
 
    @Override 
    public void update(byte[] array) {
        hasher.putBytes(array);
    } 
 
    @Override 
    public void update(ByteBuffer buffer) {
4
CodeRank
This code example shows how to use the following methods:newHasher
			add(node);
		} 
	} 
 
	public boolean add(N node) { 
		ring.put(hashFunction.newHasher().putObject(node, nodeFunnel).hash().asLong(), node); 
		return true; 
	} 
 
	public boolean remove(N node) {
		return node == ring.remove(hashFunction.newHasher().putObject(node, nodeFunnel).hash().asLong()); 
	} 
 
	public N get(K key) { 
		Long hash = hashFunction.newHasher().putObject(key, keyFunnel).hash().asLong();
		if (!ring.containsKey(hash)) {
			SortedMap<Long, N> tailMap = ring.tailMap(hash);
			hash = tailMap.isEmpty() ? ring.firstKey() : tailMap.firstKey();
		} 
		return ring.get(hash);
4
CodeRank
This code example shows how to use the following methods:newHasher
newHasher Method Overview
Begins a new hash code computation as newHasher(), but provides a hint of the expected size of the input (in bytes).
See Code Examples for other Guava HashFunction Methods: