| 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 GroupStartingIterator extends GroupMatchingIterator implements LookaheadIterator<Item<?>>, GroupIterator { |
| 27 |
|
| 28 |
public GroupStartingIterator(Expression select, Pattern startPattern, |
| 29 |
XPathContext context) |
| 30 |
throws XPathException { |
| 31 |
this.select = select; |
| 32 |
this.pattern = startPattern; |
| 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 |
GroupStartingIterator another = new GroupStartingIterator(select, pattern, baseContext); |
| 43 |
return Count.steppingCount(another); |
| 44 |
} |
| 45 |
|
| 46 |
protected void advance() throws XPathException { |
| 47 |
currentMembers = new ArrayList<>(10); |
| 48 |
currentMembers.add(current); |
| 49 |
while (true) { |
| 50 |
Item nextCandidate = population.next(); |
| 51 |
if (nextCandidate == null) { |
| 52 |
break; |
| 53 |
} |
| 54 |
if (pattern.matches(nextCandidate, runningContext)) { |
| 55 |
next = nextCandidate; |
| 56 |
return; |
| 57 |
} else { |
| 58 |
currentMembers.add(nextCandidate); |
| 59 |
} |
| 60 |
} |
| 61 |
next = null; |
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
|