1 package net.sf.saxon.sort; 2 3 import net.sf.saxon.expr.XPathContext; 4 import net.sf.saxon.om.Item; 5 import net.sf.saxon.om.ListIterator; 6 import net.sf.saxon.om.NodeInfo; 7 import net.sf.saxon.om.SequenceIterator; 8 import net.sf.saxon.pattern.Pattern; 9 import net.sf.saxon.trans.XPathException; 10 import net.sf.saxon.value.AtomicValue; 11 12 import java.util.ArrayList ; 13 import java.util.List ; 14 15 20 21 public class GroupStartingIterator implements GroupIterator { 22 23 private SequenceIterator population; 24 private Pattern startPattern; 25 private XPathContext baseContext; 26 private XPathContext runningContext; 27 private List currentMembers; 28 private Item next; 29 private Item current = null; 30 private int position = 0; 31 32 public GroupStartingIterator(SequenceIterator population, Pattern startPattern, 33 XPathContext context) 34 throws XPathException { 35 this.population = population; 36 this.startPattern = startPattern; 37 baseContext = context; 38 runningContext = context.newMinorContext(); 39 runningContext.setCurrentIterator(population); 40 next = population.next(); 42 } 43 44 private void advance() throws XPathException { 45 currentMembers = new ArrayList (10); 46 currentMembers.add(current); 47 while (true) { 48 NodeInfo nextCandidate = (NodeInfo)population.next(); 49 if (nextCandidate == null) { 50 break; 51 } 52 if (startPattern.matches(nextCandidate, runningContext)) { 53 next = nextCandidate; 54 return; 55 } else { 56 currentMembers.add(nextCandidate); 57 } 58 } 59 next = null; 60 } 61 62 public AtomicValue getCurrentGroupingKey() { 63 return null; 64 } 65 66 public SequenceIterator iterateCurrentGroup() { 67 return new ListIterator(currentMembers); 68 } 69 70 public Item next() throws XPathException { 71 if (next != null) { 72 current = next; 73 position++; 74 advance(); 75 return current; 76 } else { 77 current = null; 78 position = -1; 79 return null; 80 } 81 } 82 83 public Item current() { 84 return current; 85 } 86 87 public int position() { 88 return position; 89 } 90 91 public SequenceIterator getAnother() throws XPathException { 92 return new GroupStartingIterator(population.getAnother(), startPattern, baseContext); 93 } 94 95 104 105 public int getProperties() { 106 return 0; 107 } 108 109 110 } 111 112 113 | Popular Tags |