Debian Codegraph @

net/sf/saxon/tree/tiny/AncestorIterator.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.tree.tiny;
9
10 import net.sf.saxon.om.NodeInfo;
11 import net.sf.saxon.pattern.NodeTest;
12 import net.sf.saxon.tree.iter.AxisIterator;
13
14 /**
15 * This class enumerates the ancestor:: or ancestor-or-self:: axes,
16 * starting at a given node. The start node will never be the root.
17 */
18
19 final public class AncestorIterator implements AxisIterator {
20
21 private NodeInfo startNode;
22 private NodeInfo current;
23 private NodeTest test;
24
25 public AncestorIterator(NodeInfo node, NodeTest nodeTest) {
26 test = nodeTest;
27 startNode = node;
28 current = startNode;
29 }
30
31 /*@Nullable*/
32 public NodeInfo next() {
33 if (current == null) {
34 return null;
35 }
36 NodeInfo node = current.getParent();
37 while (node != null && !test.matchesNode(node)) {
38 node = node.getParent();
39 }
40 return current = node;
41 }
42
43 }
44