Debian Codegraph @

net/sf/saxon/tree/iter/LookaheadIteratorImpl.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.iter;
9
10 import net.sf.saxon.om.Item;
11 import net.sf.saxon.om.SequenceIterator;
12 import net.sf.saxon.trans.XPathException;
13
14 /**
15 * This class wraps any sequence iterator, turning it into a lookahead iterator,
16 * by looking ahead one item
17 */
18 public class LookaheadIteratorImpl implements LookaheadIterator {
19
20 private SequenceIterator base;
21 /*@Nullable*/ private Item next;
22
23 private LookaheadIteratorImpl(/*@NotNull*/ SequenceIterator base) throws XPathException {
24 this.base = base;
25 next = base.next();
26 }
27
28 /*@NotNull*/
29 public static LookaheadIterator makeLookaheadIterator(/*@NotNull*/ SequenceIterator base) throws XPathException {
30 if ((base.getProperties() & SequenceIterator.LOOKAHEAD) != 0) {
31 return (LookaheadIterator) base;
32 } else {
33 return new LookaheadIteratorImpl(base);
34 }
35 }
36
37 public boolean hasNext() {
38 return next != null;
39 }
40
41 /*@Nullable*/
42 public Item next() throws XPathException {
43 Item current = next;
44 if (next != null) {
45 next = base.next();
46 }
47 return current;
48 }
49
50 public void close() {
51 base.close();
52 }
53
54 public int getProperties() {
55 return LOOKAHEAD;
56 }
57 }
58