Return-Path: X-Original-To: apmail-curator-commits-archive@minotaur.apache.org Delivered-To: apmail-curator-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2719118D8C for ; Thu, 21 Apr 2016 01:13:01 +0000 (UTC) Received: (qmail 72404 invoked by uid 500); 21 Apr 2016 01:13:00 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 72211 invoked by uid 500); 21 Apr 2016 01:13:00 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 71855 invoked by uid 99); 21 Apr 2016 01:13:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Apr 2016 01:13:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7BD4CE97B9; Thu, 21 Apr 2016 01:13:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.apache.org Date: Thu, 21 Apr 2016 01:13:13 -0000 Message-Id: In-Reply-To: <91adbad286e945d5bd30fef268ec987a@git.apache.org> References: <91adbad286e945d5bd30fef268ec987a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/33] curator git commit: NamespaceWatcher should only equals other NamespaceWatcher NamespaceWatcher should only equals other NamespaceWatcher Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/cefb70c7 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/cefb70c7 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/cefb70c7 Branch: refs/heads/CURATOR-299 Commit: cefb70c7576749fb437fc19e985606b6b4e4d8ff Parents: 95bceae Author: Scott Blum Authored: Wed Feb 10 12:38:35 2016 -0500 Committer: Scott Blum Committed: Wed Feb 10 12:38:35 2016 -0500 ---------------------------------------------------------------------- .../framework/imps/NamespaceWatcher.java | 37 +++++--------------- .../framework/imps/TestWatcherIdentity.java | 3 +- 2 files changed, 10 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/cefb70c7/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceWatcher.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceWatcher.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceWatcher.java index 5da1384..29482f5 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceWatcher.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceWatcher.java @@ -18,6 +18,7 @@ */ package org.apache.curator.framework.imps; +import com.google.common.base.Objects; import com.google.common.base.Preconditions; import org.apache.curator.framework.api.CuratorWatcher; import org.apache.curator.utils.ThreadUtils; @@ -90,8 +91,9 @@ class NamespaceWatcher implements Watcher, Closeable } } - // specialized equals()/hashCode() that makes this instance equal to the actual watcher - + /** + * NamespaceWatcher should equal other wrappers that wrap the same instance. + */ @Override public boolean equals(Object o) { @@ -107,29 +109,9 @@ class NamespaceWatcher implements Watcher, Closeable if ( getClass() == o.getClass() ) { NamespaceWatcher watcher = (NamespaceWatcher)o; - - if ( !unfixedPath.equals(watcher.getUnfixedPath()) ) - { - return false; - } - - //noinspection SimplifiableIfStatement - if ( actualWatcher != null ? !actualWatcher.equals(watcher.actualWatcher) : watcher.actualWatcher != null ) - { - return false; - } - return curatorWatcher != null ? curatorWatcher.equals(watcher.curatorWatcher) : watcher.curatorWatcher == null; - } - - if ( Watcher.class.isAssignableFrom(o.getClass()) ) - { - return actualWatcher == o; - } - - //noinspection SimplifiableIfStatement - if ( CuratorWatcher.class.isAssignableFrom(o.getClass()) ) - { - return curatorWatcher == o; + return Objects.equal(unfixedPath, watcher.getUnfixedPath()) + && Objects.equal(actualWatcher, watcher.actualWatcher) + && Objects.equal(curatorWatcher, watcher.curatorWatcher); } return false; @@ -138,9 +120,6 @@ class NamespaceWatcher implements Watcher, Closeable @Override public int hashCode() { - int result = actualWatcher != null ? actualWatcher.hashCode() : 0; - result = 31 * result + unfixedPath.hashCode(); - result = 31 * result + (curatorWatcher != null ? curatorWatcher.hashCode() : 0); - return result; + return Objects.hashCode(actualWatcher, unfixedPath, curatorWatcher); } } http://git-wip-us.apache.org/repos/asf/curator/blob/cefb70c7/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java index 2a37052..31a776b 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java @@ -74,7 +74,8 @@ public class TestWatcherIdentity extends BaseClassForTests NamespaceWatcher namespaceWatcher1 = new NamespaceWatcher(null, watcher, "/foo"); NamespaceWatcher namespaceWatcher2 = new NamespaceWatcher(null, watcher, "/foo"); Assert.assertEquals(namespaceWatcher1, namespaceWatcher2); - Assert.assertTrue(namespaceWatcher1.equals(watcher)); + Assert.assertFalse(namespaceWatcher1.equals(watcher)); + Assert.assertFalse(watcher.equals(namespaceWatcher1)); Set set = Sets.newHashSet(); set.add(namespaceWatcher1); set.add(namespaceWatcher2);