@Test void givenValueIsNullItShouldReturnZero() { HashCode<TestObject> hashCode = new HashCodeImpl.Builder<TestObject>().build(); int result = hashCode.hashCode(null); assertThat(result) .isZero(); }
@Override public int hashCode(T object) { if (object == null) { return 0; } if (hashSteps.isEmpty()) { return System.identityHashCode(object); } int result = 1; for (int i = 0; i < hashSteps.size(); i++) { result = 31 * result + hashSteps.get(i).hash(object); } return result; }
HashCodeImpl implements HashCode<T> { @Override public int hashCode(T object) { if (object == null) { return 0; } if (hashSteps.isEmpty()) { return System.identityHashCode(object); } int result = 1; for (int i = 0; i < hashSteps.size(); i++) { result = 31 * result + hashSteps.get(i).hash(object); } return result; } }
HashCodeImpl implements HashCode<T> { @Override public int hashCode(T object) { if (object == null) { return 0; } if (hashSteps.isEmpty()) { return System.identityHashCode(object); } int result = 1; for (int i = 0; i < hashSteps.size(); i++) { result = 31 * result + hashSteps.get(i).hash(object); } return result; } private  HashCodeImpl(List<? extends HashStep<T>> hashSteps); }
HashCodeImpl implements HashCode<T> { @Override public int hashCode(T object) { if (object == null) { return 0; } if (hashSteps.isEmpty()) { return System.identityHashCode(object); } int result = 1; for (int i = 0; i < hashSteps.size(); i++) { result = 31 * result + hashSteps.get(i).hash(object); } return result; } private  HashCodeImpl(List<? extends HashStep<T>> hashSteps); @Override int hashCode(T object); }
HashCodeImpl implements HashCode<T> { @Override public int hashCode(T object) { if (object == null) { return 0; } if (hashSteps.isEmpty()) { return System.identityHashCode(object); } int result = 1; for (int i = 0; i < hashSteps.size(); i++) { result = 31 * result + hashSteps.get(i).hash(object); } return result; } private  HashCodeImpl(List<? extends HashStep<T>> hashSteps); @Override int hashCode(T object);  }