1 package net.sf.saxon.sort; 2 import net.sf.saxon.om.Item; 3 import net.sf.saxon.om.NodeInfo; 4 import net.sf.saxon.om.SequenceIterator; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.value.SequenceExtent; 7 8 13 14 public final class DocumentOrderIterator implements SequenceIterator, Sortable { 15 16 private SequenceIterator iterator; 17 private SequenceExtent sequence; 18 private NodeOrderComparer comparer; 19 private NodeInfo current = null; 20 private int position = 0; 21 22 25 26 public DocumentOrderIterator(SequenceIterator base, NodeOrderComparer comparer) throws XPathException { 27 28 this.comparer = comparer; 29 30 sequence = new SequenceExtent(base); 31 if (sequence.getLength()>1) { 33 GenericSorter.quickSort(0, sequence.getLength(), this); 35 } 37 iterator = sequence.iterate(null); 38 } 39 40 43 44 private DocumentOrderIterator() {} 45 46 50 51 public int compare(int a, int b) { 52 return comparer.compare((NodeInfo)sequence.itemAt(a), 54 (NodeInfo)sequence.itemAt(b)); 55 } 56 57 60 61 public void swap(int a, int b) { 62 sequence.swap(a, b); 63 } 64 65 68 public Item next() throws XPathException { 69 while (true) { 70 NodeInfo next = (NodeInfo)iterator.next(); 71 if (next == null) { 72 current = null; 73 position = -1; 74 return null; 75 } 76 if (current != null && next.isSameNodeInfo(current)) { 77 continue; 78 } else { 79 position++; 80 current = next; 81 return current; 82 } 83 } 84 } 85 86 95 96 public int getProperties() { 97 return 0; 98 } 99 100 public Item current() { 101 return current; 102 } 103 104 public int position() { 105 return position; 106 } 107 108 public SequenceIterator getAnother() throws XPathException { 109 DocumentOrderIterator another = new DocumentOrderIterator(); 110 another.iterator = iterator.getAnother(); return another; 112 } 113 114 } 115 116 | Popular Tags |