Debian Codegraph @

net/sf/saxon/tree/linked/PrecedingEnumeration.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.linked;
9
10 import net.sf.saxon.pattern.NodeTest;
11
12 final class PrecedingEnumeration extends TreeEnumeration {
13
14 /*@Nullable*/ NodeImpl nextAncestor;
15
16 public PrecedingEnumeration(/*@NotNull*/ NodeImpl node, NodeTest nodeTest) {
17 super(node, nodeTest);
18
19 // we need to avoid returning ancestors of the starting node
20 nextAncestor = (NodeImpl) node.getParent();
21 advance();
22 }
23
24
25 /**
26 * Special code to skip the ancestors of the start node
27 */
28
29 protected boolean conforms(/*@Nullable*/ NodeImpl node) {
30 // ASSERT: we'll never test the root node, because it's always
31 // an ancestor, so nextAncestor will never be null.
32 if (node != null) {
33 if (node.equals(nextAncestor)) {
34 nextAncestor = nextAncestor.getParent();
35 return false;
36 }
37 }
38 return super.conforms(node);
39 }
40
41 protected void step() {
42 next = next.getPreviousInDocument();
43 }
44
45 }
46