Debian Codegraph @

net/sf/saxon/expr/sort/GroupMatchingIterator.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.expr.sort;
9
10 import com.saxonica.ee.stream.ManualGroupIterator;
11 import net.sf.saxon.expr.Expression;
12 import net.sf.saxon.expr.LastPositionFinder;
13 import net.sf.saxon.expr.XPathContext;
14 import net.sf.saxon.om.AtomicSequence;
15 import net.sf.saxon.om.FocusIterator;
16 import net.sf.saxon.om.Item;
17 import net.sf.saxon.om.SequenceIterator;
18 import net.sf.saxon.pattern.Pattern;
19 import net.sf.saxon.trans.XPathException;
20 import net.sf.saxon.tree.iter.ListIterator;
21 import net.sf.saxon.tree.iter.LookaheadIterator;
22
23 import java.util.List;
24
25 /**
26 * A GroupMatchingIterator contains code shared between GroupStartingIterator and GroupEndingIterator
27 */
28
29 public abstract class GroupMatchingIterator implements LookaheadIterator<Item<?>>, LastPositionFinder, GroupIterator {
30
31 protected Expression select;
32 protected FocusIterator population;
33 protected Pattern pattern;
34 protected XPathContext baseContext;
35 protected XPathContext runningContext;
36 protected List<Item<?>> currentMembers;
37 /*@Nullable*/ protected Item next;
38 protected Item current = null;
39 protected int position = 0;
40
41
42 protected abstract void advance() throws XPathException;
43
44 public AtomicSequence getCurrentGroupingKey() {
45 return null;
46 }
47
48 public SequenceIterator<Item<?>> iterateCurrentGroup() {
49 return new ListIterator<>(currentMembers);
50 }
51
52 public boolean hasNext() {
53 return next != null;
54 }
55
56 public Item next() throws XPathException {
57 if (next != null) {
58 current = next;
59 position++;
60 advance();
61 return current;
62 } else {
63 current = null;
64 position = -1;
65 return null;
66 }
67 }
68
69 public void close() {
70 population.close();
71 }
72
73 public int getProperties() {
74 return LOOKAHEAD | LAST_POSITION_FINDER;
75 }
76
77 //#if EE==true
78
79 public ManualGroupIterator getSnapShot(XPathContext context) {
80 return new ManualGroupMatchingIterator();
81 }
82
83 private class ManualGroupMatchingIterator extends ManualGroupIterator {
84 List<Item<?>> cMembers = currentMembers;
85 XPathContext savedcontext = runningContext.newMinorContext();
86
87 ManualGroupMatchingIterator() {
88 super(current, position);
89 setLastPositionFinder(() -> savedcontext.getLast());
90 }
91
92 public AtomicSequence getCurrentGroupingKey() {
93 return null;
94 }
95
96 public SequenceIterator<Item<?>> iterateCurrentGroup() {
97 return new ListIterator<>(cMembers);
98 }
99
100
101 }
102
103 //#endif
104
105 }
106