You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/11/20 01:56:42 UTC

[james-project] 14/49: [Refactoring] JPAMailbox rewrite equals & hashCode

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 2478c5e174dc2dc48579d4a76d5d02a44a06a864
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sat Nov 16 10:41:58 2019 +0700

    [Refactoring] JPAMailbox rewrite equals & hashCode
---
 .../james/mailbox/jpa/mail/model/JPAMailbox.java   | 31 ++++++++--------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailbox.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailbox.java
index 4770ae5..45922af 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailbox.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailbox.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.mailbox.jpa.mail.model;
 
+import java.util.Objects;
+
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -173,28 +175,17 @@ public class JPAMailbox {
     }
 
     @Override
-    public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + (int) (mailboxId ^ (mailboxId >>> 32));
-        return result;
+    public final boolean equals(Object o) {
+        if (o instanceof JPAMailbox) {
+            JPAMailbox that = (JPAMailbox) o;
+
+            return Objects.equals(this.mailboxId, that.mailboxId);
+        }
+        return false;
     }
 
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final JPAMailbox other = (JPAMailbox) obj;
-        if (mailboxId != other.mailboxId) {
-            return false;
-        }
-        return true;
+    public final int hashCode() {
+        return Objects.hash(mailboxId);
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org