Skip to content

Commit

Permalink
NodeSetView tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Simkin committed May 28, 2018
1 parent c1d69b8 commit ea5bdb1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Attribute(QName attribute, Iterable<Expr> predicates) {
<N extends Node> IterableNodeView<N> resolveStep(ViewContext<N> context) throws XmlBuilderException {
final Navigator<N> navigator = context.getNavigator();
final N parentNode = context.getCurrent().getNode();
IterableNodeView<N> result = NodeSetView.filtered(navigator.attributesOf(parentNode), filter);
IterableNodeView<N> result = new NodeSetView<N>(navigator.attributesOf(parentNode), filter);
if (context.isGreedy() && !context.hasNext() && !result.toBoolean()) {
result = createStepNode(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Element(QName element, Iterable<Expr> predicates) {
<N extends Node> IterableNodeView<N> resolveStep(ViewContext<N> context) throws XmlBuilderException {
final Navigator<N> navigator = context.getNavigator();
final N parentNode = context.getCurrent().getNode();
IterableNodeView<N> result = NodeSetView.filtered(navigator.elementsOf(parentNode), filter);
IterableNodeView<N> result = new NodeSetView<N>(navigator.elementsOf(parentNode), filter);
if (context.isGreedy() && !context.hasNext() && !result.toBoolean()) {
result = createStepNode(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,24 @@ public static <T extends Node> NodeSetView<T> empty() {
return (NodeSetView<T>) EMPTY_NODE_SET;
}

private final Iterable<NodeView<N>> nodeSet;

/**
* Creates filtered node view from given nodes and predicate.
* Creates NodeSetView from given nodes and predicate.
*
* @param nodes nodes to wap in a view
* @param predicate predicate to apply to nodes
* @param <T> XML model type
* @return newly created node set view
*/
public static <T extends Node> NodeSetView<T> filtered(final Iterable<? extends T> nodes,
final Predicate<? super T> predicate) {
return new NodeSetView<T>(new Iterable<NodeView<T>>() {
public NodeSetView(final Iterable<? extends N> nodes, final Predicate<? super N> predicate) {
this(new Iterable<NodeView<N>>() {
@Override
public Iterator<NodeView<T>> iterator() {
return new TransformingIterator<T, NodeView<T>>(
new FilteringIterator<T>(nodes.iterator(), predicate), new NodeWrapper<T>());
public Iterator<NodeView<N>> iterator() {
return new TransformingIterator<N, NodeView<N>>(new FilteringIterator<N>(nodes.iterator(), predicate),
new NodeWrapper<N>());
}
});
}

private final Iterable<NodeView<N>> nodeSet;

public NodeSetView(Iterable<NodeView<N>> nodeSet) {
this.nodeSet = nodeSet;
}
Expand Down

0 comments on commit ea5bdb1

Please sign in to comment.