1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jxpath.ri.axes;
19
20 import org.apache.commons.jxpath.NodeSet;
21 import org.apache.commons.jxpath.ri.EvalContext;
22 import org.apache.commons.jxpath.ri.model.NodePointer;
23
24
25
26
27 public class NodeSetContext extends EvalContext {
28
29 private boolean startedSet;
30 private final NodeSet nodeSet;
31
32
33
34
35
36
37
38 public NodeSetContext(final EvalContext parentContext, final NodeSet nodeSet) {
39 super(parentContext);
40 this.nodeSet = nodeSet;
41 }
42
43 @Override
44 public NodePointer getCurrentNodePointer() {
45 if (position == 0 && !setPosition(1)) {
46 return null;
47 }
48 return (NodePointer) nodeSet.getPointers().get(position - 1);
49 }
50
51 @Override
52 public NodeSet getNodeSet() {
53 return nodeSet;
54 }
55
56 @Override
57 public boolean nextNode() {
58 return setPosition(position + 1);
59 }
60
61 @Override
62 public boolean nextSet() {
63 if (startedSet) {
64 return false;
65 }
66 startedSet = true;
67 return true;
68 }
69
70 @Override
71 public boolean setPosition(final int position) {
72 super.setPosition(position);
73 return position >= 1 && position <= nodeSet.getPointers().size();
74 }
75 }