All Superinterfaces:
Cloneable, Serializable
All Known Implementing Classes:
HashImpl

@ClassVersion(sourceVersion="$Id: Hash.java 1052 2023-03-06 06:30:36Z tquadrat $") @API(status=STABLE, since="0.1.1") public sealed interface Hash extends Cloneable, Serializable permits HashImpl

The definition for a wrapper around hash values of any kind. These hashes are often used as checksums to validate the integrity of files or messages.

Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: Hash.java 1052 2023-03-06 06:30:36Z tquadrat $
Since:
0.1.1
UML Diagram
UML Diagram for "org.tquadrat.foundation.util.Hash"

UML Diagram for "org.tquadrat.foundation.util.Hash"

UML Diagram for "org.tquadrat.foundation.util.Hash"
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Returns the hash as an array of bytes.
    Creates and returns a copy of this object.
    static Hash
    create(byte[] data, MessageDigest algorithm)
    Creates the hash for the given byte array, using the given algorithm.
    static Hash
    create(byte[] data, Checksum algorithm)
    Creates the hash for the given byte array, using the given algorithm.
    static Hash
    create(File data, MessageDigest algorithm)
    Creates the hash for the given file, using the given algorithm.
    static Hash
    create(File data, Checksum algorithm)
    Creates the hash for the given file, using the given algorithm.
    static Hash
    create(CharSequence data, Charset encoding, MessageDigest algorithm)
    Creates the hash for the given String, using the given algorithm.
    static Hash
    create(CharSequence data, Charset encoding, Checksum algorithm)
    Creates the hash for the given String, using the given algorithm.
    static Hash
    create(CharSequence data, MessageDigest algorithm)
    Creates the hash for the given String, using the given algorithm.
    static Hash
    create(CharSequence data, Checksum algorithm)
    Creates the hash for the given String, using the given algorithm.
    static Hash
    create(Path data, MessageDigest algorithm)
    Creates the hash for the given file, using the given algorithm.
    static Hash
    create(Path data, Checksum algorithm)
    Creates the hash for the given file, using the given algorithm.
    static Hash
    from(byte[] hashValue)
    Creates an instance of Hash from the given byte array.
    static Hash
    from(CharSequence hashValue)
    Creates an instance of Hash from the given String.
    default BigInteger
    Returns this hash as a number.
    default boolean
    validate(byte[] hashValue)
    Validates whether the given hash value matches with this hash instance.
    default boolean
    validate(long hashValue)
    Validates whether the given hash value matches with this hash instance.
    default boolean
    Validates whether the given hash value matches with this hash instance.
  • Method Details

    • bytes

      byte[] bytes()
      Returns the hash as an array of bytes.
      Returns:
      The hash value.
    • clone

      Creates and returns a copy of this object.
      Returns:
      The copy of this instance.
    • create

      static Hash create(byte[] data, Checksum algorithm)
      Creates the hash for the given byte array, using the given algorithm.
      Parameters:
      data - The input data.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
    • create

      static Hash create(CharSequence data, Checksum algorithm)
      Creates the hash for the given String, using the given algorithm.
      Parameters:
      data - The input data.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
    • create

      static Hash create(CharSequence data, Charset encoding, Checksum algorithm)
      Creates the hash for the given String, using the given algorithm.
      Parameters:
      data - The input data.
      encoding - The encoding for the String.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
    • create

      static Hash create(File data, Checksum algorithm) throws IOException
      Creates the hash for the given file, using the given algorithm.
      Parameters:
      data - The input data.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
      Throws:
      IOException - Problems to process the file.
    • create

      static Hash create(Path data, Checksum algorithm) throws IOException
      Creates the hash for the given file, using the given algorithm.
      Parameters:
      data - The input data.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
      Throws:
      IOException - Problems to process the file.
    • create

      static Hash create(byte[] data, MessageDigest algorithm)
      Creates the hash for the given byte array, using the given algorithm.
      Parameters:
      data - The input data.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
    • create

      static Hash create(CharSequence data, MessageDigest algorithm)
      Creates the hash for the given String, using the given algorithm.
      Parameters:
      data - The input data.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
    • create

      static Hash create(CharSequence data, Charset encoding, MessageDigest algorithm)
      Creates the hash for the given String, using the given algorithm.
      Parameters:
      data - The input data.
      encoding - The encoding for the String.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
    • create

      static Hash create(File data, MessageDigest algorithm) throws IOException
      Creates the hash for the given file, using the given algorithm.
      Parameters:
      data - The input data.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
      Throws:
      IOException - Problems to process the file.
    • create

      static Hash create(Path data, MessageDigest algorithm) throws IOException
      Creates the hash for the given file, using the given algorithm.
      Parameters:
      data - The input data.
      algorithm - The algorithm
      Returns:
      A new instance of Hash.
      Throws:
      IOException - Problems to process the file.
    • from

      static Hash from(byte[] hashValue)
      Creates an instance of Hash from the given byte array.
      Parameters:
      hashValue - The hash value.
      Returns:
      A new instance of Hash.
    • from

      static Hash from(CharSequence hashValue)
      Creates an instance of Hash from the given String.
      Parameters:
      hashValue - The hash value.
      Returns:
      A new instance of Hash.
    • number

      default BigInteger number()
      Returns this hash as a number.
      Returns:
      The number.
    • validate

      default boolean validate(byte[] hashValue)
      Validates whether the given hash value matches with this hash instance.
      Parameters:
      hashValue - The hash value to test.
      Returns:
      true if the hash value matches with this hash instance, false otherwise.
    • validate

      default boolean validate(long hashValue)
      Validates whether the given hash value matches with this hash instance.
      Parameters:
      hashValue - The hash value to test.
      Returns:
      true if the hash value matches with this hash instance, false otherwise.
    • validate

      default boolean validate(CharSequence hashValue)
      Validates whether the given hash value matches with this hash instance.
      Parameters:
      hashValue - The hash value to test.
      Returns:
      true if the hash value matches with this hash instance, false otherwise.