Class AbstractCompositeHashFunction

java.lang.Object
com.google.common.hash.AbstractHashFunction
com.google.common.hash.AbstractCompositeHashFunction
All Implemented Interfaces:
HashFunction
Direct Known Subclasses:
Hashing.ConcatenatedHashFunction

abstract class AbstractCompositeHashFunction extends AbstractHashFunction
An abstract composition of multiple hash functions. newHasher() delegates to the Hasher objects of the delegate hash functions, and in the end, they are used by makeHash(Hasher[]) that constructs the final HashCode.
  • Field Details

  • Constructor Details

    • AbstractCompositeHashFunction

      AbstractCompositeHashFunction(HashFunction... functions)
  • Method Details

    • makeHash

      abstract HashCode makeHash(Hasher[] hashers)
      Constructs a HashCode from the Hasher objects of the functions. Each of them has consumed the entire input and they are ready to output a HashCode. The order of the hashers are the same order as the functions given to the constructor.
    • newHasher

      public Hasher newHasher()
      Description copied from interface: HashFunction
      Begins a new hash code computation by returning an initialized, stateful Hasher instance that is ready to receive data. Example:
      
       HashFunction hf = Hashing.md5();
       HashCode hc = hf.newHasher()
           .putLong(id)
           .putBoolean(isActive)
           .hash();
       
    • newHasher

      public Hasher newHasher(int expectedInputSize)
      Description copied from interface: HashFunction
      Begins a new hash code computation as HashFunction.newHasher(), but provides a hint of the expected size of the input (in bytes). This is only important for non-streaming hash functions (hash functions that need to buffer their whole input before processing any of it).
      Specified by:
      newHasher in interface HashFunction
      Overrides:
      newHasher in class AbstractHashFunction
    • fromHashers

      private Hasher fromHashers(Hasher[] hashers)