Class HashCode

java.lang.Object
org.apache.juneau.internal.HashCode

public class HashCode extends Object
Utility class for generating integer hash codes.

General usage:

int hashCode = HashCode.create().add("foobar").add(myobject).add(123).get();

See Also:
  • Constructor Details

  • Method Details

    • create

      public static final HashCode create()
      Create a new HashCode object.
      Returns:
      A new HashCode object.
    • of

      public static final int of(Object... objects)
      Calculates a hash code over the specified objects.
      Parameters:
      objects - The objects to calculate a hashcode over.
      Returns:
      A numerical hashcode value.
    • add

      public HashCode add(Object o)
      Hashes the hashcode of the specified object into this object.
      Parameters:
      o - The object whose hashcode will be hashed with this object.
      Returns:
      This object.
    • add

      public HashCode add(int i)
      Hashes the hashcode into this object.

      The formula is simply hashCode = 31*hashCode + i;

      Parameters:
      i - The hashcode to hash into this object's hashcode.
      Returns:
      This object.
    • get

      public int get()
      Return the calculated hashcode value.
      Returns:
      The calculated hashcode.
    • unswap

      protected Object unswap(Object o)
      Converts the object to a normalized form before grabbing it's hashcode.

      Subclasses can override this method to provide specialized handling (e.g. converting numbers to strings so that 123 and "123" end up creating the same hashcode.)

      Default implementation does nothing.

      Parameters:
      o - The object to normalize before getting it's hashcode.
      Returns:
      The normalized object.