You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2016/10/19 15:06:25 UTC

svn commit: r1765618 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/ test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/

Author: chetanm
Date: Wed Oct 19 15:06:25 2016
New Revision: 1765618

URL: http://svn.apache.org/viewvc?rev=1765618&view=rev
Log:
OAK-1312 -  [bundling] Bundle nodes into a document

Add support for depth in Matcher

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcher.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeAllMatcher.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcher.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Matcher.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcherTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/MatcherTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcher.java?rev=1765618&r1=1765617&r2=1765618&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcher.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcher.java Wed Oct 19 15:06:25 2016
@@ -73,4 +73,9 @@ class CompositeMatcher implements Matche
         //determine the matching path
         return matchers.get(0).getMatchedPath();
     }
+
+    @Override
+    public int depth() {
+        return matchers.get(0).depth();
+    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeAllMatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeAllMatcher.java?rev=1765618&r1=1765617&r2=1765618&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeAllMatcher.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeAllMatcher.java Wed Oct 19 15:06:25 2016
@@ -19,6 +19,7 @@
 
 package org.apache.jackrabbit.oak.plugins.document.bundlor;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
 
 /**
@@ -26,14 +27,17 @@ import static org.apache.jackrabbit.oak.
  */
 class IncludeAllMatcher implements Matcher {
     private final String matchingPath;
+    private final int depth;
 
-    IncludeAllMatcher(String matchingPath) {
+    IncludeAllMatcher(String matchingPath, int depth) {
+        checkArgument(depth > 0);
         this.matchingPath = matchingPath;
+        this.depth = depth;
     }
 
     @Override
     public Matcher next(String name) {
-        return new IncludeAllMatcher(concat(matchingPath, name));
+        return new IncludeAllMatcher(concat(matchingPath, name), depth + 1);
     }
 
     @Override
@@ -45,4 +49,9 @@ class IncludeAllMatcher implements Match
     public String getMatchedPath() {
         return matchingPath;
     }
+
+    @Override
+    public int depth() {
+        return depth;
+    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcher.java?rev=1765618&r1=1765617&r2=1765618&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcher.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeMatcher.java Wed Oct 19 15:06:25 2016
@@ -43,7 +43,7 @@ class IncludeMatcher implements Matcher
             if (include.match(name, depth)) {
                 String nextPath = concat(matchedPath, name);
                 if (lastEntry() && include.getDirective() == Include.Directive.ALL) {
-                    return new IncludeAllMatcher(nextPath);
+                    return new IncludeAllMatcher(nextPath, depth + 1);
                 }
                 return new IncludeMatcher(include, depth + 1, nextPath);
             } else {
@@ -64,6 +64,11 @@ class IncludeMatcher implements Matcher
     }
 
     @Override
+    public int depth() {
+        return depth;
+    }
+
+    @Override
     public String toString() {
         return "IncludeMatcher{" +
                 "include=" + include +

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Matcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Matcher.java?rev=1765618&r1=1765617&r2=1765618&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Matcher.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Matcher.java Wed Oct 19 15:06:25 2016
@@ -35,6 +35,11 @@ public interface Matcher {
         public String getMatchedPath() {
             throw new IllegalStateException("No matching path for non matching matcher");
         }
+
+        @Override
+        public int depth() {
+            return 0;
+        }
     };
 
     /**
@@ -55,4 +60,9 @@ public interface Matcher {
      * there was a match
      */
     String getMatchedPath();
+
+    /**
+     * Matcher depth. For match done for 'x/y' depth is 2
+     */
+    int depth();
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcherTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcherTest.java?rev=1765618&r1=1765617&r2=1765618&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcherTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/CompositeMatcherTest.java Wed Oct 19 15:06:25 2016
@@ -49,12 +49,14 @@ public class CompositeMatcherTest {
         Matcher m2 = m.next("x");
         assertTrue(m2.isMatch());
         assertEquals("x", m2.getMatchedPath());
+        assertEquals(1, m2.depth());
 
         assertFalse(m.next("a").isMatch());
 
         Matcher m3 = m2.next("y");
         assertTrue(m3.isMatch());
         assertEquals("x/y", m3.getMatchedPath());
+        assertEquals(2, m3.depth());
 
         Matcher m4 = m3.next("a");
         assertFalse(m4.isMatch());

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java?rev=1765618&r1=1765617&r2=1765618&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/IncludeTest.java Wed Oct 19 15:06:25 2016
@@ -19,7 +19,6 @@
 
 package org.apache.jackrabbit.oak.plugins.document.bundlor;
 
-import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -73,12 +72,21 @@ public class IncludeTest {
         assertTrue(i2.match("x/y/z/x"));
     }
 
-    private boolean match(Include i, String path){
-        Matcher m = i.createMatcher();
-        for (String e : PathUtils.elements(path)){
-            m = m.next(e);
-        }
-        return m.isMatch();
-    }
+    @Test
+    public void depth() throws Exception{
+        Include i0 = new Include("x/*");
+        assertEquals(0, i0.createMatcher().depth());
+        assertEquals(1, i0.createMatcher().next("x").depth());
+        assertEquals(2, i0.createMatcher().next("x").next("y").depth());
+
+        // x/y/z would not match so depth should be 0
+        assertEquals(0, i0.createMatcher().next("x").next("y").next("z").depth());
 
+        Include i2 = new Include("x/y;all");
+        assertEquals(0, i2.createMatcher().depth());
+        assertEquals(1, i2.createMatcher().next("x").depth());
+        assertEquals(2, i2.createMatcher().next("x").next("y").depth());
+        assertEquals(3, i2.createMatcher().next("x").next("y").next("z").depth());
+
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/MatcherTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/MatcherTest.java?rev=1765618&r1=1765617&r2=1765618&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/MatcherTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/MatcherTest.java Wed Oct 19 15:06:25 2016
@@ -38,12 +38,14 @@ public class MatcherTest {
 
     @Test
     public void includeAll() throws Exception{
-        Matcher m = new IncludeAllMatcher("x");
+        Matcher m = new IncludeAllMatcher("x", 1);
         assertTrue(m.isMatch());
         assertEquals("x", m.getMatchedPath());
+        assertEquals(1, m.depth());
 
         assertTrue(m.next("y").isMatch());
         assertEquals("x/y", m.next("y").getMatchedPath());
+        assertEquals(2, m.next("y").depth());
     }