1 package net.sf.saxon.expr; 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.sort.NodeOrderComparer; 6 import net.sf.saxon.trans.XPathException; 7 8 9 13 14 15 public class DifferenceEnumeration implements SequenceIterator { 16 17 18 private SequenceIterator p1; 19 private SequenceIterator p2; 20 21 private NodeInfo nextNode1 = null; 22 private NodeInfo nextNode2 = null; 23 private NodeOrderComparer comparer; 24 25 private NodeInfo current = null; 27 private int position = 0; 28 29 36 37 public DifferenceEnumeration(SequenceIterator p1, SequenceIterator p2, 38 NodeOrderComparer comparer) throws XPathException { 39 this.p1 = p1; 40 this.p2 = p2; 41 this.comparer = comparer; 42 43 45 nextNode1 = next(p1); 46 nextNode2 = next(p2); 47 } 48 49 53 54 private NodeInfo next(SequenceIterator iter) throws XPathException { 55 return (NodeInfo)iter.next(); 56 } 58 59 public Item next() throws XPathException { 60 63 while (true) { 64 65 if (nextNode1 == null) { 66 current = null; 67 position = -1; 68 return null; 69 } 70 71 if (nextNode2 == null) { 72 return deliver(); 74 } 75 76 int c = comparer.compare(nextNode1, nextNode2); 77 if (c<0) { return deliver(); 79 80 } else if (c>0) { nextNode2 = next(p2); 82 if (nextNode2 == null) { 83 return deliver(); 84 } 85 86 } else { nextNode2 = next(p2); 88 nextNode1 = next(p1); 89 } 90 } 91 } 92 93 99 private NodeInfo deliver() throws XPathException { 100 current = nextNode1; 101 nextNode1 = next(p1); 102 position++; 103 return current; 104 } 105 106 public Item current() { 107 return current; 108 } 109 110 public int position() { 111 return position; 112 } 113 114 public SequenceIterator getAnother() throws XPathException { 115 return new DifferenceEnumeration(p1.getAnother(), p2.getAnother(), comparer); 116 } 117 118 127 128 public int getProperties() { 129 return 0; 130 } 131 } 132 133 | Popular Tags |