You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2016/04/21 03:13:13 UTC
[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 <dr...@apache.org>
Authored: Wed Feb 10 12:38:35 2016 -0500
Committer: Scott Blum <dr...@apache.org>
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<Watcher> set = Sets.newHashSet();
set.add(namespaceWatcher1);
set.add(namespaceWatcher2);