Class AbstractHasher

java.lang.Object
com.google.common.hash.AbstractHasher
All Implemented Interfaces:
Hasher, PrimitiveSink
Direct Known Subclasses:
AbstractByteHasher, AbstractNonStreamingHashFunction.BufferingHasher, AbstractStreamingHasher, Murmur3_32HashFunction.Murmur3_32Hasher

abstract class AbstractHasher extends Object implements Hasher
An abstract implementation of Hasher, which only requires subtypes to implement Hasher.putByte(byte). Subtypes may provide more efficient implementations, however.
  • Constructor Details

    • AbstractHasher

      AbstractHasher()
  • Method Details

    • putBoolean

      public final Hasher putBoolean(boolean b)
      Description copied from interface: Hasher
      Equivalent to putByte(b ? (byte) 1 : (byte) 0).
      Specified by:
      putBoolean in interface Hasher
      Specified by:
      putBoolean in interface PrimitiveSink
    • putDouble

      public final Hasher putDouble(double d)
      Description copied from interface: Hasher
      Equivalent to putLong(Double.doubleToRawLongBits(d)).
      Specified by:
      putDouble in interface Hasher
      Specified by:
      putDouble in interface PrimitiveSink
    • putFloat

      public final Hasher putFloat(float f)
      Description copied from interface: Hasher
      Equivalent to putInt(Float.floatToRawIntBits(f)).
      Specified by:
      putFloat in interface Hasher
      Specified by:
      putFloat in interface PrimitiveSink
    • putUnencodedChars

      public Hasher putUnencodedChars(CharSequence charSequence)
      Description copied from interface: Hasher
      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 Hasher.putString(java.lang.CharSequence, java.nio.charset.Charset), usually with a charset of UTF-8. For other use cases, use putUnencodedChars.

      Specified by:
      putUnencodedChars in interface Hasher
      Specified by:
      putUnencodedChars in interface PrimitiveSink
    • putString

      public Hasher putString(CharSequence charSequence, Charset charset)
      Description copied from interface: Hasher
      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 Hasher.putUnencodedChars(java.lang.CharSequence), which is faster, produces the same output across Java releases, and hashes every char in the input, even if some are invalid.

      Specified by:
      putString in interface Hasher
      Specified by:
      putString in interface PrimitiveSink
    • putBytes

      public Hasher putBytes(byte[] bytes)
      Description copied from interface: PrimitiveSink
      Puts an array of bytes into this sink.
      Specified by:
      putBytes in interface Hasher
      Specified by:
      putBytes in interface PrimitiveSink
      Parameters:
      bytes - a byte array
      Returns:
      this instance
    • putBytes

      public Hasher putBytes(byte[] bytes, int off, int len)
      Description copied from interface: PrimitiveSink
      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.
      Specified by:
      putBytes in interface Hasher
      Specified by:
      putBytes in interface PrimitiveSink
      Parameters:
      bytes - a byte array
      off - the start offset in the array
      len - the number of bytes to write
      Returns:
      this instance
    • putBytes

      public Hasher putBytes(ByteBuffer b)
      Description copied from interface: PrimitiveSink
      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.
      Specified by:
      putBytes in interface Hasher
      Specified by:
      putBytes in interface PrimitiveSink
      Parameters:
      b - a byte buffer
      Returns:
      this instance
    • putShort

      public Hasher putShort(short s)
      Description copied from interface: PrimitiveSink
      Puts a short into this sink.
      Specified by:
      putShort in interface Hasher
      Specified by:
      putShort in interface PrimitiveSink
    • putInt

      public Hasher putInt(int i)
      Description copied from interface: PrimitiveSink
      Puts an int into this sink.
      Specified by:
      putInt in interface Hasher
      Specified by:
      putInt in interface PrimitiveSink
    • putLong

      public Hasher putLong(long l)
      Description copied from interface: PrimitiveSink
      Puts a long into this sink.
      Specified by:
      putLong in interface Hasher
      Specified by:
      putLong in interface PrimitiveSink
    • putChar

      public Hasher putChar(char c)
      Description copied from interface: PrimitiveSink
      Puts a character into this sink.
      Specified by:
      putChar in interface Hasher
      Specified by:
      putChar in interface PrimitiveSink
    • putObject

      public <T> Hasher putObject(T instance, Funnel<? super T> funnel)
      Description copied from interface: Hasher
      A simple convenience for funnel.funnel(object, this).
      Specified by:
      putObject in interface Hasher