From 0f4a8c8b0422ed8f9fadd67af9c00c7a782111fd Mon Sep 17 00:00:00 2001 From: Janis Streib Date: Wed, 27 Aug 2014 12:42:19 +0200 Subject: [PATCH] ADD: correct hashCode for the Name object --- src/org/cacert/gigi/Name.java | 44 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/org/cacert/gigi/Name.java b/src/org/cacert/gigi/Name.java index fda8160c..93b361ef 100644 --- a/src/org/cacert/gigi/Name.java +++ b/src/org/cacert/gigi/Name.java @@ -40,31 +40,58 @@ public class Name implements Outputable { return fname + " " + lname; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((fname == null) ? 0 : fname.hashCode()); + result = prime * result + ((lname == null) ? 0 : lname.hashCode()); + result = prime * result + ((mname == null) ? 0 : mname.hashCode()); + result = prime * result + ((suffix == null) ? 0 : suffix.hashCode()); + return result; + } + @Override public boolean equals(Object obj) { - if ( !(obj instanceof Name)) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Name other = (Name) obj; + if (fname == null) { + if (other.fname != null) { + return false; + } + } else if ( !fname.equals(other.fname)) { return false; } - Name n = (Name) obj; - if ( !(n.fname.equals(fname) && n.lname.equals(lname))) { + if (lname == null) { + if (other.lname != null) { + return false; + } + } else if ( !lname.equals(other.lname)) { return false; } if (mname == null) { - if (n.mname != null) { + if (other.mname != null) { return false; } - } else if ( !mname.equals(n.mname)) { + } else if ( !mname.equals(other.mname)) { return false; } if (suffix == null) { - if (n.suffix != null) { + if (other.suffix != null) { return false; } - } else if ( !suffix.equals(n.suffix)) { + } else if ( !suffix.equals(other.suffix)) { return false; } return true; - } public boolean matches(String text) { @@ -73,4 +100,5 @@ public class Name implements Outputable { (suffix != null && text.equals(fname + " " + lname + " " + suffix)) || // (mname != null && suffix != null && text.equals(fname + " " + mname + " " + lname + " " + suffix)); } + } -- 2.39.2