Index: src/main/java/org/apache/jackrabbit/oak/plugins/index/search/Aggregate.java =================================================================== --- src/main/java/org/apache/jackrabbit/oak/plugins/index/search/Aggregate.java (revision 1832658) +++ src/main/java/org/apache/jackrabbit/oak/plugins/index/search/Aggregate.java (working copy) @@ -47,7 +47,7 @@ import static org.apache.jackrabbit.oak.commons.PathUtils.elements; import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath; -public class Aggregate { +public class Aggregate { public static final String MATCH_ALL = "*"; @@ -62,14 +62,14 @@ private final boolean nodeAggregates; Aggregate(String nodeTypeName) { - this(nodeTypeName, Collections.emptyList()); + this(nodeTypeName, Collections.>emptyList()); } - Aggregate(String nodeTypeName, List includes) { + Aggregate(String nodeTypeName, List> includes) { this(nodeTypeName, includes, RECURSIVE_AGGREGATION_LIMIT_DEFAULT); } - Aggregate(String nodeTypeName, List includes, + Aggregate(String nodeTypeName, List> includes, int recursionLimit) { this.nodeTypeName = nodeTypeName; this.includes = ImmutableList.copyOf(includes); @@ -78,21 +78,21 @@ this.nodeAggregates = hasNodeIncludes(includes); } - public List getIncludes() { - return includes; + public List> getIncludes() { + return (List>) includes; } public void collectAggregates(NodeState root, ResultCollector collector) { if (matchingType(nodeTypeName, root)) { - List matchers = createMatchers(); + List> matchers = createMatchers(); collectAggregates(root, matchers, collector); } } - public List createMatchers(AggregateRoot root){ - List matchers = newArrayListWithCapacity(includes.size()); - for (Include include : includes) { - matchers.add(new Matcher(this, include, root)); + public List> createMatchers(AggregateRoot root){ + List> matchers = newArrayListWithCapacity(includes.size()); + for (Include include : getIncludes()) { + matchers.add(new Matcher(this, include, root)); } return matchers; } @@ -128,7 +128,7 @@ return false; } - private static void collectAggregates(NodeState nodeState, List matchers, + private static void collectAggregates(NodeState nodeState, List> matchers, ResultCollector collector) { if (hasPatternMatcher(matchers)){ collectAggregatesForPatternMatchers(nodeState, matchers, collector); @@ -137,11 +137,11 @@ } } - private static void collectAggregatesForDirectMatchers(NodeState nodeState, List matchers, + private static void collectAggregatesForDirectMatchers(NodeState nodeState, List> matchers, ResultCollector collector) { Map children = Maps.newHashMap(); //Collect potentially matching child nodestates based on matcher name - for (Matcher m : matchers){ + for (Matcher m : matchers){ String nodeName = m.getNodeName(); NodeState child = nodeState.getChildNode(nodeName); if (child.exists()){ @@ -151,17 +151,17 @@ matchChildren(matchers, collector, children.values()); } - private static void collectAggregatesForPatternMatchers(NodeState nodeState, List matchers, + private static void collectAggregatesForPatternMatchers(NodeState nodeState, List> matchers, ResultCollector collector) { matchChildren(matchers, collector, nodeState.getChildNodeEntries()); } - private static void matchChildren(List matchers, ResultCollector collector, + private static void matchChildren(List> matchers, ResultCollector collector, Iterable children) { for (ChildNodeEntry cne : children) { - List nextSet = newArrayListWithCapacity(matchers.size()); - for (Matcher m : matchers) { - Matcher result = m.match(cne.getName(), cne.getNodeState()); + List> nextSet = newArrayListWithCapacity(matchers.size()); + for (Matcher m : matchers) { + Matcher result = m.match(cne.getName(), cne.getNodeState()); if (result.getStatus() == Matcher.Status.MATCH_FOUND){ result.collectResults(collector); } @@ -176,8 +176,8 @@ } } - private static boolean hasPatternMatcher(List matchers){ - for (Matcher m : matchers){ + private static boolean hasPatternMatcher(List> matchers){ + for (Matcher m : matchers){ if (m.isPatternBased()){ return true; } @@ -185,17 +185,17 @@ return false; } - private List createMatchers() { - List matchers = newArrayListWithCapacity(includes.size()); - for (Include include : includes) { - matchers.add(new Matcher(this, include)); + private List> createMatchers() { + List> matchers = newArrayListWithCapacity(includes.size()); + for (Include include : getIncludes()) { + matchers.add(new Matcher(this, include)); } return matchers; } - private static List findRelativeNodeIncludes(List includes) { + private static List findRelativeNodeIncludes(List> includes) { List result = newArrayList(); - for (Include i : includes){ + for (Include i : includes){ if (i instanceof NodeInclude){ NodeInclude ni = (NodeInclude) i; if (ni.relativeNode){ @@ -206,18 +206,18 @@ return ImmutableList.copyOf(result); } - private static boolean hasNodeIncludes(List includes) { - return Iterables.any(includes, new Predicate() { + private static boolean hasNodeIncludes(List> includes) { + return Iterables.any(includes, new Predicate>() { @Override - public boolean apply(Include input) { + public boolean apply(Include input) { return input instanceof NodeInclude; } }); } - public static interface AggregateMapper { + public static interface AggregateMapper { @CheckForNull - Aggregate getAggregate(String nodeTypeName); + Aggregate getAggregate(String nodeTypeName); } //~-----------------------------------------------------< Includes > @@ -256,7 +256,7 @@ public abstract boolean aggregatesProperty(String name); @CheckForNull - public Aggregate getAggregate(NodeState matchedNodeState) { + public Aggregate getAggregate(NodeState matchedNodeState) { return null; } @@ -276,13 +276,13 @@ final String primaryType; final boolean relativeNode; private final String pattern; - private final AggregateMapper aggMapper; + private final AggregateMapper aggMapper; - public NodeInclude(AggregateMapper mapper, String pattern) { + public NodeInclude(AggregateMapper mapper, String pattern) { this(mapper, null, pattern, false); } - public NodeInclude(AggregateMapper mapper, String primaryType, String pattern, boolean relativeNode) { + public NodeInclude(AggregateMapper mapper, String primaryType, String pattern, boolean relativeNode) { super(pattern); this.pattern = pattern; this.primaryType = primaryType; @@ -320,9 +320,9 @@ } @Override - public Aggregate getAggregate(NodeState matchedNodeState) { + public Aggregate getAggregate(NodeState matchedNodeState) { //Check agg defn for primaryType first - Aggregate agg = aggMapper.getAggregate(ConfigUtil.getPrimaryTypeName(matchedNodeState)); + Aggregate agg = aggMapper.getAggregate(ConfigUtil.getPrimaryTypeName(matchedNodeState)); //If not found then look for defn for mixins if (agg == null) { @@ -473,15 +473,15 @@ String getPath(); } - public static class Matcher { + public static class Matcher { public enum Status {CONTINUE, MATCH_FOUND, FAIL} - private static class RootState { + private static class RootState { final AggregateRoot root; - final Aggregate rootAggregate; - final Include rootInclude; + final Aggregate rootAggregate; + final Include rootInclude; - private RootState(AggregateRoot root, Aggregate rootAggregate, Include rootInclude) { + private RootState(AggregateRoot root, Aggregate rootAggregate, Include rootInclude) { this.root = root; this.rootAggregate = rootAggregate; this.rootInclude = rootInclude; @@ -488,7 +488,7 @@ } } - private final RootState rootState; + private final RootState rootState; private final Include currentInclude; /** * Current depth in the include pattern. @@ -500,12 +500,12 @@ private final List aggregateStack; - public Matcher(Aggregate aggregate, Include currentInclude) { + public Matcher(Aggregate aggregate, Include currentInclude) { this(aggregate, currentInclude, null); } - public Matcher(Aggregate aggregate, Include include, AggregateRoot root) { - this.rootState = new RootState(root, aggregate, include); + public Matcher(Aggregate aggregate, Include include, AggregateRoot root) { + this.rootState = new RootState(root, aggregate, include); this.depth = 0; this.currentInclude = include; this.status = Status.CONTINUE; @@ -514,7 +514,7 @@ this.aggregateStack = Collections.emptyList(); } - private Matcher(Matcher m, Status status, int depth) { + private Matcher(Matcher m, Status status, int depth) { checkArgument(status == Status.FAIL); this.rootState = m.rootState; this.depth = depth; @@ -525,7 +525,7 @@ this.aggregateStack = m.aggregateStack; } - private Matcher(Matcher m, Status status, int depth, + private Matcher(Matcher m, Status status, int depth, NodeState matchedNodeState, String currentPath) { checkArgument(status != Status.FAIL); this.rootState = m.rootState; @@ -537,7 +537,7 @@ this.aggregateStack = m.aggregateStack; } - private Matcher(Matcher m, Include i, String currentPath) { + private Matcher(Matcher m, Include i, String currentPath) { checkArgument(m.status == Status.MATCH_FOUND); this.rootState = m.rootState; this.depth = 0; @@ -563,24 +563,24 @@ return currentInclude.getElementNameIfNotAPattern(depth); } - public Matcher match(String name, NodeState nodeState) { + public Matcher match(String name, NodeState nodeState) { boolean result = currentInclude.match(name, nodeState, depth); if (result){ if (hasMore()){ - return new Matcher(this, Status.CONTINUE, depth, nodeState, path(name)); + return new Matcher(this, Status.CONTINUE, depth, nodeState, path(name)); } else { - return new Matcher(this, Status.MATCH_FOUND, depth, nodeState, path(name)); + return new Matcher(this, Status.MATCH_FOUND, depth, nodeState, path(name)); } } else { - return new Matcher(this, Status.FAIL, depth); + return new Matcher(this, Status.FAIL, depth); } } - public Collection nextSet() { + public Collection> nextSet() { checkArgument(status != Status.FAIL); if (status == Status.MATCH_FOUND){ - Aggregate nextAgg = currentInclude.getAggregate(matchedNodeState); + Aggregate nextAgg = currentInclude.getAggregate(matchedNodeState); if (nextAgg != null){ int recursionLevel = aggregateStack.size() + 1; @@ -588,9 +588,9 @@ return Collections.emptyList(); } - List result = Lists.newArrayListWithCapacity(nextAgg.includes.size()); + List> result = Lists.newArrayListWithCapacity(nextAgg.includes.size()); for (Include i : nextAgg.includes){ - result.add(new Matcher(this, i, currentPath)); + result.add(new Matcher(this, i, currentPath)); } return result; } @@ -597,7 +597,7 @@ return Collections.emptyList(); } - return Collections.singleton(new Matcher(this, status, depth + 1, + return Collections.singleton(new Matcher(this, status, depth + 1, null, currentPath)); }