Class HashCode


final class HashCode extends MetadataVisitor<Integer>
Computes a hash code for the specified metadata. The hash code is defined as the sum of hash codes of all non-empty properties, plus the hash code of the interface. This is a similar contract than Set.hashCode() (except for the interface) and ensures that the hash code value is insensitive to the ordering of properties.
Since:
1.0
Version:
1.0
  • Field Details

  • Constructor Details

    • HashCode

      private HashCode()
      Instantiated by VISITORS only.
  • Method Details

    • getOrCreate

      static HashCode getOrCreate()
      Returns the visitor for the current thread if it already exists, or creates a new one otherwise.
    • creator

      final ThreadLocal<HashCode> creator()
      Returns the thread-local variable that created this HashCode instance.
      Overrides:
      creator in class MetadataVisitor<Integer>
    • preVisit

      Resets the hash code to an initial value for a new metadata instance. If another hash code computation was in progress, that code shall be saved before this method is invoked.
      Overrides:
      preVisit in class MetadataVisitor<Integer>
      Parameters:
      accessor - contains the standard interface of the metadata for which a hash code value will be computed.
      Returns:
      MetadataVisitor.Filter.NON_EMPTY since this visitor is not restricted to writable properties.
    • visit

      Object visit(Class<?> type, Object value)
      Adds the hash code of the given metadata property value. Invoking this method may cause recursive calls to HashCode methods on this visitor instance if the given value is itself another metadata object.
      Specified by:
      visit in class MetadataVisitor<Integer>
      Parameters:
      value - the metadata property value for which to add hash code.
      type - the type of elements. Note that this is not necessarily the type of given value argument if the latter is a collection.
      Returns:
      null, meaning to not modify the metadata property value.
    • result

      Integer result()
      Returns the hash code result after visiting all elements in a metadata instance.
      Overrides:
      result in class MetadataVisitor<Integer>