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 GroupEndingIterator implements GroupIterator { 22 23 private SequenceIterator population; 24 private Pattern endPattern; 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 GroupEndingIterator(SequenceIterator population, Pattern endPattern, 33 XPathContext context) 34 throws XPathException { 35 this.population = population; 36 this.endPattern = endPattern; 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 (20); 46 currentMembers.add(current); 47 48 next = current; 49 while (next != null) { 50 if (endPattern.matches((NodeInfo)next, runningContext)) { 51 next = population.next(); 52 if (next != null) { 53 break; 54 } 55 } else { 56 next = population.next(); 57 if (next != null) { 58 currentMembers.add(next); 59 } 60 } 61 } 62 } 63 64 public AtomicValue getCurrentGroupingKey() { 65 return null; 66 } 67 68 public SequenceIterator iterateCurrentGroup() { 69 return new ListIterator(currentMembers); 70 } 71 72 public Item next() throws XPathException { 73 if (next != null) { 74 current = next; 75 position++; 76 advance(); 77 return current; 78 } else { 79 current = null; 80 position = -1; 81 return null; 82 } 83 } 84 85 public Item current() { 86 return current; 87 } 88 89 public int position() { 90 return position; 91 } 92 93 public SequenceIterator getAnother() throws XPathException { 94 return new GroupEndingIterator(population.getAnother(), endPattern, baseContext); 95 } 96 97 106 107 public int getProperties() { 108 return 0; 109 } 110 111 112 } 113 114 115 | Popular Tags |