Author: chetanm
Date: Wed Oct 19 15:07:56 2016
New Revision: 1765625
URL: http://svn.apache.org/viewvc?rev=1765625&view=rev
Log:
OAK-1312 - [bundling] Bundle nodes into a document
Add method to determine if matcher would also match all children. This would be
later used to handle case where DocumentNodeState can determine if all children
are bundled
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/Include.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=1765625&r1=1765624&r2=1765625&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:07:56 2016
@@ -78,4 +78,14 @@ class CompositeMatcher implements Matche
public int depth() {
return matchers.get(0).depth();
}
+
+ @Override
+ public boolean matchesChildren() {
+ for (Matcher m : matchers){
+ if (m.matchesChildren()){
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java?rev=1765625&r1=1765624&r2=1765625&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/bundlor/Include.java
Wed Oct 19 15:07:56 2016
@@ -105,12 +105,27 @@ public class Include {
return directive;
}
+ /**
+ * Matches node name against pattern at given depth.
+ * Depth here would be 1 based with 0 for root depth
+ *
+ * @param nodeName nodeName to match
+ * @param depth depth in path
+ * @return true if nodeName matched against pattern at given depth
+ */
public boolean match(String nodeName, int depth) {
- checkElementIndex(depth, elements.length);
- String e = elements[depth];
+ int elementIndex = depth - 1;
+ checkElementIndex(elementIndex, elements.length);
+ String e = elements[elementIndex];
return STAR.equals(e) || nodeName.equals(e);
}
+ public boolean matchAny(int depth){
+ int elementIndex = depth - 1;
+ checkElementIndex(elementIndex, elements.length);
+ return STAR.equals(elements[elementIndex]);
+ }
+
public int size() {
return elements.length;
}
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=1765625&r1=1765624&r2=1765625&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:07:56 2016
@@ -54,4 +54,9 @@ class IncludeAllMatcher implements Match
public int depth() {
return depth;
}
+
+ @Override
+ public boolean matchesChildren() {
+ return true;
+ }
}
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=1765625&r1=1765624&r2=1765625&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:07:56 2016
@@ -24,6 +24,10 @@ import static org.apache.jackrabbit.oak.
class IncludeMatcher implements Matcher {
private final Include include;
+ /**
+ * Depth is 1 based i.e. first node element in path would have depth 1.
+ * Root has depth 0
+ */
private final int depth;
private final String matchedPath;
@@ -40,12 +44,12 @@ class IncludeMatcher implements Matcher
@Override
public Matcher next(String name) {
if (hasMore()) {
- if (include.match(name, depth)) {
+ if (include.match(name, nextElementIndex())) {
String nextPath = concat(matchedPath, name);
if (lastEntry() && include.getDirective() ==
Include.Directive.ALL) {
- return new IncludeAllMatcher(nextPath, depth + 1);
+ return new IncludeAllMatcher(nextPath, nextElementIndex());
}
- return new IncludeMatcher(include, depth + 1, nextPath);
+ return new IncludeMatcher(include, nextElementIndex(),
nextPath);
} else {
return Matcher.NON_MATCHING;
}
@@ -69,6 +73,14 @@ class IncludeMatcher implements Matcher
}
@Override
+ public boolean matchesChildren() {
+ if (hasMore()){
+ return include.matchAny(nextElementIndex());
+ }
+ return false;
+ }
+
+ @Override
public String toString() {
return "IncludeMatcher{" +
"include=" + include +
@@ -77,6 +89,10 @@ class IncludeMatcher implements Matcher
'}';
}
+ private int nextElementIndex(){
+ return depth + 1;
+ }
+
private boolean hasMore() {
return depth < include.size();
}
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=1765625&r1=1765624&r2=1765625&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:07:56 2016
@@ -42,6 +42,11 @@ public interface Matcher {
}
@Override
+ public boolean matchesChildren() {
+ return false;
+ }
+
+ @Override
public String toString() {
return "NON_MATCHING";
}
@@ -70,4 +75,12 @@ public interface Matcher {
* Matcher depth. For match done for 'x/y' depth is 2
*/
int depth();
+
+ /**
+ * Returns true if matcher for all immediate child node
+ * would also be a matching matcher. This would be the
+ * case if IncludeMatcher with '*' or '**' as pattern for
+ * child nodes
+ */
+ boolean matchesChildren();
}
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=1765625&r1=1765624&r2=1765625&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:07:56 2016
@@ -62,4 +62,16 @@ public class CompositeMatcherTest {
assertFalse(m4.isMatch());
}
+ @Test
+ public void matchChildren() throws Exception{
+ //Hypothetical case. First pattern is redundant
+ Matcher m = CompositeMatcher.compose(asList(
+ new Include("x/z").createMatcher(),
+ new Include("x/*").createMatcher())
+ );
+
+ assertFalse(m.matchesChildren());
+ assertTrue(m.next("x").matchesChildren());
+ }
+
}
\ No newline at end of file
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=1765625&r1=1765624&r2=1765625&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:07:56 2016
@@ -87,6 +87,19 @@ public class IncludeTest {
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());
+ }
+
+ @Test
+ public void matchChildren() throws Exception{
+ Include i0 = new Include("x/*");
+ Matcher m = i0.createMatcher();
+ assertFalse(m.matchesChildren());
+ assertTrue(m.next("x").matchesChildren());
+
+ Include i1 = new Include("x/**");
+ m = i1.createMatcher();
+ assertFalse(m.matchesChildren());
+ assertTrue(m.next("x").matchesChildren());
}
}
\ 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=1765625&r1=1765624&r2=1765625&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:07:56 2016
@@ -40,10 +40,12 @@ public class MatcherTest {
public void includeAll() throws Exception{
Matcher m = new IncludeAllMatcher("x", 1);
assertTrue(m.isMatch());
+ assertTrue(m.matchesChildren());
assertEquals("x", m.getMatchedPath());
assertEquals(1, m.depth());
assertTrue(m.next("y").isMatch());
+ assertTrue(m.next("y").matchesChildren());
assertEquals("x/y", m.next("y").getMatchedPath());
assertEquals(2, m.next("y").depth());
}