| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.sort; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Expression; |
| 11 |
import net.sf.saxon.expr.XPathContext; |
| 12 |
import net.sf.saxon.functions.Count; |
| 13 |
import net.sf.saxon.om.Item; |
| 14 |
import net.sf.saxon.pattern.Pattern; |
| 15 |
import net.sf.saxon.trans.XPathException; |
| 16 |
import net.sf.saxon.tree.iter.LookaheadIterator; |
| 17 |
|
| 18 |
import java.util.ArrayList; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class GroupEndingIterator extends GroupMatchingIterator implements GroupIterator, LookaheadIterator<Item<?>> { |
| 27 |
|
| 28 |
public GroupEndingIterator(Expression select, Pattern endPattern, |
| 29 |
XPathContext context) |
| 30 |
throws XPathException { |
| 31 |
this.select = select; |
| 32 |
this.pattern = endPattern; |
| 33 |
baseContext = context; |
| 34 |
runningContext = context.newMinorContext(); |
| 35 |
this.population = runningContext.trackFocus(select.iterate(context)); |
| 36 |
|
| 37 |
next = population.next(); |
| 38 |
} |
| 39 |
|
| 40 |
@Override |
| 41 |
public int getLength() throws XPathException { |
| 42 |
GroupEndingIterator another = new GroupEndingIterator(select, pattern, baseContext); |
| 43 |
return Count.steppingCount(another); |
| 44 |
} |
| 45 |
|
| 46 |
protected void advance() throws XPathException { |
| 47 |
currentMembers = new ArrayList<>(20); |
| 48 |
currentMembers.add(current); |
| 49 |
|
| 50 |
next = current; |
| 51 |
while (next != null) { |
| 52 |
if (pattern.matches(next, runningContext)) { |
| 53 |
next = population.next(); |
| 54 |
if (next != null) { |
| 55 |
break; |
| 56 |
} |
| 57 |
} else { |
| 58 |
next = population.next(); |
| 59 |
if (next != null) { |
| 60 |
currentMembers.add(next); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
} |
| 68 |
|