Ejemplo n.º 1
0
 @Override
 public int hashCode() {
   int result = 17;
   result = 37 * result + cksumType;
   if (checksum != null) {
     result = 37 * result + Arrays.hashCode(checksum);
   }
   return result;
 }
Ejemplo n.º 2
0
  /**
   * Returns the hash code value for this <code>CompositeDataSupport</code> instance.
   *
   * <p>The hash code of a <code>CompositeDataSupport</code> instance is the sum of the hash codes
   * of all elements of information used in <code>equals</code> comparisons (ie: its <i>composite
   * type</i> and all the item values).
   *
   * <p>This ensures that <code> t1.equals(t2) </code> implies that <code>
   *  t1.hashCode()==t2.hashCode() </code> for any two <code>CompositeDataSupport</code> instances
   * <code>t1</code> and <code>t2</code>, as required by the general contract of the method {@link
   * Object#hashCode() Object.hashCode()}.
   *
   * <p>Each item value's hash code is added to the returned hash code. If an item value is an
   * array, its hash code is obtained as if by calling the {@link
   * j86.java.util.Arrays#deepHashCode(Object[]) deepHashCode} method for arrays of object reference
   * types or the appropriate overloading of {@code Arrays.hashCode(e)} for arrays of primitive
   * types.
   *
   * @return the hash code value for this <code>CompositeDataSupport</code> instance
   */
  @Override
  public int hashCode() {
    int hashcode = compositeType.hashCode();

    for (Object o : contents.values()) {
      if (o instanceof Object[]) hashcode += Arrays.deepHashCode((Object[]) o);
      else if (o instanceof byte[]) hashcode += Arrays.hashCode((byte[]) o);
      else if (o instanceof short[]) hashcode += Arrays.hashCode((short[]) o);
      else if (o instanceof int[]) hashcode += Arrays.hashCode((int[]) o);
      else if (o instanceof long[]) hashcode += Arrays.hashCode((long[]) o);
      else if (o instanceof char[]) hashcode += Arrays.hashCode((char[]) o);
      else if (o instanceof float[]) hashcode += Arrays.hashCode((float[]) o);
      else if (o instanceof double[]) hashcode += Arrays.hashCode((double[]) o);
      else if (o instanceof boolean[]) hashcode += Arrays.hashCode((boolean[]) o);
      else if (o != null) hashcode += o.hashCode();
    }

    return hashcode;
  }