Package com.google.common.hash
Class AbstractHasher
- java.lang.Object
-
- com.google.common.hash.AbstractHasher
-
- All Implemented Interfaces:
Hasher
,PrimitiveSink
- Direct Known Subclasses:
AbstractByteHasher
,AbstractNonStreamingHashFunction.BufferingHasher
,AbstractStreamingHashFunction.AbstractStreamingHasher
abstract class AbstractHasher extends java.lang.Object implements Hasher
An abstract hasher, implementingputBoolean(boolean)
,putDouble(double)
,putFloat(float)
,putUnencodedChars(CharSequence)
, andputString(CharSequence, Charset)
as prescribed byHasher
.
-
-
Constructor Summary
Constructors Constructor Description AbstractHasher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Hasher
putBoolean(boolean b)
Equivalent toputByte(b ? (byte) 1 : (byte) 0)
.Hasher
putDouble(double d)
Equivalent toputLong(Double.doubleToRawLongBits(d))
.Hasher
putFloat(float f)
Equivalent toputInt(Float.floatToRawIntBits(f))
.Hasher
putString(java.lang.CharSequence charSequence, java.nio.charset.Charset charset)
Equivalent toputBytes(charSequence.toString().getBytes(charset))
.Hasher
putUnencodedChars(java.lang.CharSequence charSequence)
Equivalent to processing eachchar
value in theCharSequence
, in order.
-
-
-
Method Detail
-
putBoolean
public final Hasher putBoolean(boolean b)
Description copied from interface:Hasher
Equivalent toputByte(b ? (byte) 1 : (byte) 0)
.- Specified by:
putBoolean
in interfaceHasher
- Specified by:
putBoolean
in interfacePrimitiveSink
-
putDouble
public final Hasher putDouble(double d)
Description copied from interface:Hasher
Equivalent toputLong(Double.doubleToRawLongBits(d))
.- Specified by:
putDouble
in interfaceHasher
- Specified by:
putDouble
in interfacePrimitiveSink
-
putFloat
public final Hasher putFloat(float f)
Description copied from interface:Hasher
Equivalent toputInt(Float.floatToRawIntBits(f))
.- Specified by:
putFloat
in interfaceHasher
- Specified by:
putFloat
in interfacePrimitiveSink
-
putUnencodedChars
public Hasher putUnencodedChars(java.lang.CharSequence charSequence)
Description copied from interface:Hasher
Equivalent to processing eachchar
value in theCharSequence
, in order. In other words, no character encoding is performed; the low byte and high byte of eachchar
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
Hasher.putString(java.lang.CharSequence, java.nio.charset.Charset)
, usually with a charset of UTF-8. For other use cases, useputUnencodedChars
.- Specified by:
putUnencodedChars
in interfaceHasher
- Specified by:
putUnencodedChars
in interfacePrimitiveSink
-
putString
public Hasher putString(java.lang.CharSequence charSequence, java.nio.charset.Charset charset)
Description copied from interface:Hasher
Equivalent toputBytes(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
Hasher.putUnencodedChars(java.lang.CharSequence)
, which is faster, produces the same output across Java releases, and hashes everychar
in the input, even if some are invalid.- Specified by:
putString
in interfaceHasher
- Specified by:
putString
in interfacePrimitiveSink
-
-