1. HashCode sample.

Listing 1. HashCode sample.


public int hashCode() {
  int result = super.hashCode(); // PICK ONE
  //int result = 0;              // PICK ONE
  result = PRIME*result + primitiveField;
  result = PRIME*result + (flagField ? 1 : 0);
  result = PRIME*result + (int)(longField >>> 32);
  result = PRIME*result + (int)(longField & 0xFFFFFFFF);
  
  long temp = Double.doubleToLongBits(doubleField);
  result = PRIME*result + (int)(temp >>> 32);
  result = PRIME*result + (int)(temp & 0xFFFFFFFF);

  result = PRIME*result + objectField.hashCode();
  if (maybeNullField != null) {
    result = PRIME*result + maybeNullField.hashCode();
  }
  for (int i = 0; i < arrayfield.length;="" ++i)="" {="" result="PRIME*result" +="" arrayfield[i].hashcode();="" }="" return="" result;="" }="">