Made hashCode() implement satisfy the Object.hashCode() contract, i.e., a.equals(b) implies a.hashCode() == b.hashCode()

Former-commit-id: 9f347a57b740b572d2d6a9a9e523de44e384773e
This commit is contained in:
Dale Visser
2015-06-24 14:41:20 -04:00
parent d76799cfd0
commit e8353089f3
3 changed files with 19 additions and 5 deletions

View File

@@ -26,6 +26,9 @@ import java.io.Serializable;
*/
public class Evidence implements Serializable, Comparable<Evidence> {
public static final int MAGIC_HASH_INIT_VALUE = 3;
public static final int MAGIC_HASH_MULTIPLIER = 67;
/**
* Creates a new Evidence object.
*/
@@ -176,11 +179,11 @@ public class Evidence implements Serializable, Comparable<Evidence> {
*/
@Override
public int hashCode() {
int hash = 3;
hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0);
hash = 67 * hash + (this.source != null ? this.source.hashCode() : 0);
hash = 67 * hash + (this.value != null ? this.value.hashCode() : 0);
hash = 67 * hash + (this.confidence != null ? this.confidence.hashCode() : 0);
int hash = MAGIC_HASH_INIT_VALUE;
hash = MAGIC_HASH_MULTIPLIER * hash + (this.name != null ? this.name.toLowerCase().hashCode() : 0);
hash = MAGIC_HASH_MULTIPLIER * hash + (this.source != null ? this.source.toLowerCase().hashCode() : 0);
hash = MAGIC_HASH_MULTIPLIER * hash + (this.value != null ? this.value.toLowerCase().hashCode() : 0);
hash = MAGIC_HASH_MULTIPLIER * hash + (this.confidence != null ? this.confidence.hashCode() : 0);
return hash;
}