summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-06-15 03:09:57 -0500
committerEndi Sukma Dewata <edewata@redhat.com>2012-06-21 11:31:05 -0500
commit3153fa5ba15d402b4729a649737d02eead5a5064 (patch)
treee1f16518cfa967f9f3bd6cf7f6a4558c36fc6607 /base
parentd5d0b91bc5597eec19520cee74569e9ddacc2090 (diff)
downloadpki-3153fa5ba15d402b4729a649737d02eead5a5064.tar.gz
pki-3153fa5ba15d402b4729a649737d02eead5a5064.tar.xz
pki-3153fa5ba15d402b4729a649737d02eead5a5064.zip
Fixed equals() and hashCode() in X500Name and RDN.
The X500Name and RDN have been modified to fix the incorrect method signature for equals() and the missing hashCode(). Ticket #206
Diffstat (limited to 'base')
-rw-r--r--base/util/src/netscape/security/x509/RDN.java33
-rw-r--r--base/util/src/netscape/security/x509/X500Name.java31
2 files changed, 34 insertions, 30 deletions
diff --git a/base/util/src/netscape/security/x509/RDN.java b/base/util/src/netscape/security/x509/RDN.java
index dc26eb214..bf8212305 100644
--- a/base/util/src/netscape/security/x509/RDN.java
+++ b/base/util/src/netscape/security/x509/RDN.java
@@ -18,6 +18,7 @@
package netscape.security.x509;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.Vector;
@@ -201,25 +202,25 @@ public class RDN {
// other public methods.
- /**
- * Checks if this RDN is the same as another by comparing the AVAs
- * in the RDNs.
- *
- * @param other the other RDN.
- * @return true iff the other RDN is the same.
- */
- public boolean equals(RDN other) {
- int i;
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(assertion);
+ return result;
+ }
- if (other == this)
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
return true;
- if (assertion.length != other.assertion.length)
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ RDN other = (RDN) obj;
+ if (!Arrays.equals(assertion, other.assertion))
return false;
-
- for (i = 0; i < assertion.length; i++)
- if (!assertion[i].equals(other.assertion[i]))
- return false;
-
return true;
}
diff --git a/base/util/src/netscape/security/x509/X500Name.java b/base/util/src/netscape/security/x509/X500Name.java
index c2886dab2..d0111a27e 100644
--- a/base/util/src/netscape/security/x509/X500Name.java
+++ b/base/util/src/netscape/security/x509/X500Name.java
@@ -19,6 +19,7 @@ package netscape.security.x509;
import java.io.IOException;
import java.security.Principal;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.Vector;
@@ -285,23 +286,25 @@ public class X500Name implements Principal, GeneralNameInterface {
}
}
- /**
- * Compares this name with another, for equality.
- *
- * @return true iff the names are identical.
- */
- synchronized public boolean equals(X500Name other) {
- int i;
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(names);
+ return result;
+ }
- if (this == other)
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
return true;
-
- if (names.length != other.names.length)
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ X500Name other = (X500Name) obj;
+ if (!Arrays.equals(names, other.names))
return false;
- for (i = 0; i < names.length; i++) {
- if (!names[i].equals(other.names[i]))
- return false;
- }
return true;
}