Repository: curator
Updated Branches:
  refs/heads/CURATOR-397 c3db1810a -> ef9df2b79


fixed startsWith


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/56c6c85a
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/56c6c85a
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/56c6c85a

Branch: refs/heads/CURATOR-397
Commit: 56c6c85a2f26ef914574139e4c1c657b5a7573a5
Parents: c3db181
Author: randgalt <randg...@apache.org>
Authored: Tue May 2 01:11:13 2017 -0500
Committer: randgalt <randg...@apache.org>
Committed: Tue May 2 01:11:13 2017 -0500

----------------------------------------------------------------------
 .../curator/x/async/modeled/details/ZPathImpl.java   | 15 ++++++++++++---
 .../apache/curator/x/async/modeled/TestZPath.java    | 12 +++++++++---
 2 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/56c6c85a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
----------------------------------------------------------------------
diff --git 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
index f6c941a..b6c0d2f 100644
--- 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
+++ 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
@@ -47,6 +47,11 @@ public class ZPathImpl implements ZPath
 
     public static ZPath parse(String fullPath, UnaryOperator<String> 
nameFilter)
     {
+        return parseInternal(fullPath, nameFilter);
+    }
+
+    private static ZPathImpl parseInternal(String fullPath, 
UnaryOperator<String> nameFilter)
+    {
         List<String> nodes = ImmutableList.<String>builder()
             .add(ZKPaths.PATH_SEPARATOR)
             .addAll(
@@ -123,12 +128,16 @@ public class ZPathImpl implements ZPath
     @Override
     public boolean startsWith(ZPath path)
     {
+        ZPathImpl rhs;
         if ( path instanceof ZPathImpl )
         {
-            ZPathImpl rhs = (ZPathImpl)path;
-            return (nodes.size() >= rhs.nodes.size()) && nodes.subList(0, 
rhs.nodes.size()).equals(rhs);
+            rhs = (ZPathImpl)path;
+        }
+        else
+        {
+            rhs = parseInternal(path.fullPath(), s -> s);
         }
-        return false;
+        return (nodes.size() >= rhs.nodes.size()) && nodes.subList(0, 
rhs.nodes.size()).equals(rhs.nodes);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/curator/blob/56c6c85a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
----------------------------------------------------------------------
diff --git 
a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
 
b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
index 8397ef5..7d8a463 100644
--- 
a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
+++ 
b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
@@ -25,6 +25,8 @@ import org.testng.annotations.Test;
 import java.util.Arrays;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import static org.apache.curator.x.async.modeled.ZPath.parameterNodeName;
+
 public class TestZPath
 {
     @Test
@@ -47,6 +49,9 @@ public class TestZPath
         Assert.assertEquals(path.nodeName(), "two");
         Assert.assertEquals(path.fullPath(), "/one/two");
         Assert.assertEquals(path.parentPath(), "/one");
+
+        Assert.assertTrue(path.startsWith(ZPath.root().at("one")));
+        Assert.assertFalse(path.startsWith(ZPath.root().at("two")));
     }
 
     @Test
@@ -55,26 +60,27 @@ public class TestZPath
         Assert.assertEquals(ZPath.parse("/"), ZPath.root());
         Assert.assertEquals(ZPath.parse("/one/two/three"), 
ZPath.root().at("one").at("two").at("three"));
         Assert.assertEquals(ZPath.parse("/one/two/three"), ZPath.from("one", 
"two", "three"));
+        Assert.assertEquals(ZPath.parseWithIds("/one/{id}/two/{id}"), 
ZPath.from("one", parameterNodeName(), "two", parameterNodeName()));
     }
 
     @Test(expectedExceptions = IllegalStateException.class)
     public void testUnresolvedPath()
     {
-        ZPath path = ZPath.from("one", ZPath.parameterNodeName(), "two");
+        ZPath path = ZPath.from("one", parameterNodeName(), "two");
         path.fullPath();
     }
 
     @Test
     public void testResolvedPath()
     {
-        ZPath path = ZPath.from("one", ZPath.parameterNodeName(), "two", 
ZPath.parameterNodeName());
+        ZPath path = ZPath.from("one", parameterNodeName(), "two", 
parameterNodeName());
         Assert.assertEquals(path.resolved("a", "b"), ZPath.from("one", "a", 
"two", "b"));
     }
 
     @Test
     public void testResolving()
     {
-        ZPath path = ZPath.from("one", ZPath.parameterNodeName(), "two", 
ZPath.parameterNodeName());
+        ZPath path = ZPath.from("one", parameterNodeName(), "two", 
parameterNodeName());
         AtomicInteger count = new AtomicInteger(0);
         ZPath resolving = path.resolving(Arrays.asList(() -> "x" + 
count.get(), () -> "y" + count.get()));
         Assert.assertEquals(resolving.fullPath(), "/one/x0/two/y0");

Reply via email to