Top Description Constructors Methods
com.google.common.hash

pack-priv abstract Class AbstractHasher

extends Object
implements Hasher
Class Inheritance
All Implemented Interfaces
com.google.common.hash.Hasher, com.google.common.hash.PrimitiveSink
Known Direct Subclasses
com.google.common.hash.AbstractNonStreamingHashFunction.BufferingHasher, com.google.common.hash.AbstractStreamingHasher, com.google.common.hash.Murmur3_32HashFunction.Murmur3_32Hasher, com.google.common.hash.AbstractByteHasher
Annotations
@ElementTypesAreNonnullByDefault
Imports
com.google.common.base.Preconditions, com.google.errorprone.annotations.CanIgnoreReturnValue, java.nio.ByteBuffer, java.nio.charset.Charset, org.checkerframework.checker.nullness.qual.Nullable

An abstract implementation of Hasher, which only requires subtypes to implement putByte. Subtypes may provide more efficient implementations, however.
Author
Dimitris Andreou

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public final Hasher
putBoolean(boolean b)

Implements com.google.common.hash.Hasher.putBoolean.

Equivalent to putByte(b ?
public Hasher
putBytes(byte[]
a byte array
bytes
)

Implements com.google.common.hash.Hasher.putBytes.

Puts an array of bytes into this sink.
public Hasher
putBytes(byte[]
a byte array
bytes
,
int
the start offset in the array
off
,
int
the number of bytes to write
len
)

Implements com.google.common.hash.Hasher.putBytes.

Puts a chunk of an array of bytes into this sink.
public Hasher
putBytes(ByteBuffer
a byte buffer
b
)

Implements com.google.common.hash.Hasher.putBytes.

Puts the remaining bytes of a byte buffer into this sink.
public Hasher
putChar(char c)

Implements com.google.common.hash.Hasher.putChar.

Puts a character into this sink.
public final Hasher
putDouble(double d)

Implements com.google.common.hash.Hasher.putDouble.

Equivalent to putLong(Double.doubleToRawLongBits(d)).
public final Hasher
putFloat(float f)

Implements com.google.common.hash.Hasher.putFloat.

Equivalent to putInt(Float.floatToRawIntBits(f)).
public Hasher
putInt(int i)

Implements com.google.common.hash.Hasher.putInt.

Puts an int into this sink.
public Hasher
putLong(long l)

Implements com.google.common.hash.Hasher.putLong.

Puts a long into this sink.
public <T extends @Nullable Object> Hasher
putObject(T instance, Funnel<? super T> funnel)

Implements com.google.common.hash.Hasher.putObject.

A simple convenience for funnel.funnel(object, this).
public Hasher
putShort(short s)

Implements com.google.common.hash.Hasher.putShort.

Puts a short into this sink.
public Hasher
putString(CharSequence charSequence, Charset charset)

Implements com.google.common.hash.Hasher.putString.

Equivalent to putBytes(charSequence.toString().getBytes(charset)).
public Hasher
putUnencodedChars(CharSequence charSequence)

Implements com.google.common.hash.Hasher.putUnencodedChars.

Equivalent to processing each char value in the CharSequence, in order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AbstractHasherback to summary
pack-priv AbstractHasher()

Method Detail

putBooleanback to summary
public final Hasher putBoolean(boolean b)

Implements com.google.common.hash.Hasher.putBoolean.

Doc from com.google.common.hash.Hasher.putBoolean.

Equivalent to putByte(b ? (byte) 1 : (byte) 0).

Annotations
@Override
@CanIgnoreReturnValue
putBytesback to summary
public Hasher putBytes(byte[] bytes)

Implements com.google.common.hash.Hasher.putBytes.

Doc from com.google.common.hash.PrimitiveSink.putBytes.

Puts an array of bytes into this sink.

Parameters
bytes:byte[]

a byte array

Returns:Hasher

this instance

Annotations
@Override
@CanIgnoreReturnValue
putBytesback to summary
public Hasher putBytes(byte[] bytes, int off, int len)

Implements com.google.common.hash.Hasher.putBytes.

Doc from com.google.common.hash.PrimitiveSink.putBytes.

Puts a chunk of an array of bytes into this sink. bytes[off] is the first byte written, bytes[off + len - 1] is the last.

Parameters
bytes:byte[]

a byte array

off:int

the start offset in the array

len:int

the number of bytes to write

Returns:Hasher

this instance

Annotations
@Override
@CanIgnoreReturnValue
putBytesback to summary
public Hasher putBytes(ByteBuffer b)

Implements com.google.common.hash.Hasher.putBytes.

Doc from com.google.common.hash.PrimitiveSink.putBytes.

Puts the remaining bytes of a byte buffer into this sink. bytes.position() is the first byte written, bytes.limit() - 1 is the last. The position of the buffer will be equal to the limit when this method returns.

Parameters
b:ByteBuffer

a byte buffer

Returns:Hasher

this instance

Annotations
@Override
@CanIgnoreReturnValue
putCharback to summary
public Hasher putChar(char c)

Implements com.google.common.hash.Hasher.putChar.

Doc from com.google.common.hash.PrimitiveSink.putChar.

Puts a character into this sink.

Annotations
@Override
@CanIgnoreReturnValue
putDoubleback to summary
public final Hasher putDouble(double d)

Implements com.google.common.hash.Hasher.putDouble.

Doc from com.google.common.hash.Hasher.putDouble.

Equivalent to putLong(Double.doubleToRawLongBits(d)).

Annotations
@Override
@CanIgnoreReturnValue
putFloatback to summary
public final Hasher putFloat(float f)

Implements com.google.common.hash.Hasher.putFloat.

Doc from com.google.common.hash.Hasher.putFloat.

Equivalent to putInt(Float.floatToRawIntBits(f)).

Annotations
@Override
@CanIgnoreReturnValue
putIntback to summary
public Hasher putInt(int i)

Implements com.google.common.hash.Hasher.putInt.

Doc from com.google.common.hash.PrimitiveSink.putInt.

Puts an int into this sink.

Annotations
@Override
@CanIgnoreReturnValue
putLongback to summary
public Hasher putLong(long l)

Implements com.google.common.hash.Hasher.putLong.

Doc from com.google.common.hash.PrimitiveSink.putLong.

Puts a long into this sink.

Annotations
@Override
@CanIgnoreReturnValue
putObjectback to summary
public <T extends @Nullable Object> Hasher putObject(T instance, Funnel<? super T> funnel)

Implements com.google.common.hash.Hasher.putObject.

Doc from com.google.common.hash.Hasher.putObject.

A simple convenience for funnel.funnel(object, this).

Annotations
@Override
@CanIgnoreReturnValue
putShortback to summary
public Hasher putShort(short s)

Implements com.google.common.hash.Hasher.putShort.

Doc from com.google.common.hash.PrimitiveSink.putShort.

Puts a short into this sink.

Annotations
@Override
@CanIgnoreReturnValue
putStringback to summary
public Hasher putString(CharSequence charSequence, Charset charset)

Implements com.google.common.hash.Hasher.putString.

Doc from com.google.common.hash.Hasher.putString.

Equivalent to putBytes(charSequence.toString().getBytes(charset)).

Warning

This method, which reencodes the input before hashing it, is useful only for cross-language compatibility. For other use cases, prefer putUnencodedChars, which is faster, produces the same output across Java releases, and hashes every char in the input, even if some are invalid.

Annotations
@Override
@CanIgnoreReturnValue
putUnencodedCharsback to summary
public Hasher putUnencodedChars(CharSequence charSequence)

Implements com.google.common.hash.Hasher.putUnencodedChars.

Doc from com.google.common.hash.Hasher.putUnencodedChars.

Equivalent to processing each char value in the CharSequence, in order. In other words, no character encoding is performed; the low byte and high byte of each char are hashed directly (in that order). The input must not be updated while this method is in progress.

Warning

This method will produce different output than most other languages do when running the same hash function on the equivalent input. For cross-language compatibility, use putString, usually with a charset of UTF-8. For other use cases, use putUnencodedChars.

Annotations
@Override
@CanIgnoreReturnValue