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 12 13 14 public class IntersectionEnumeration implements SequenceIterator { 15 16 private SequenceIterator e1; 17 private SequenceIterator e2; 18 private NodeInfo nextNode1 = null; 19 private NodeInfo nextNode2 = null; 20 private NodeOrderComparer comparer; 21 22 private NodeInfo current = null; 23 private int position = 0; 24 25 31 32 public IntersectionEnumeration(SequenceIterator p1, SequenceIterator p2, 33 NodeOrderComparer comparer ) throws XPathException { 34 this.e1 = p1; 35 this.e2 = p2; 36 this.comparer = comparer; 37 38 40 nextNode1 = next(e1); 41 nextNode2 = next(e2); 42 } 43 44 48 49 private NodeInfo next(SequenceIterator iter) throws XPathException { 50 return (NodeInfo)iter.next(); 51 } 53 54 public Item next() throws XPathException { 55 58 if (nextNode1 == null || nextNode2 == null) { 59 current = null; 60 position = -1; 61 return null; 62 } 63 64 while (nextNode1 != null && nextNode2 != null) { 65 int c = comparer.compare(nextNode1, nextNode2); 66 if (c<0) { 67 nextNode1 = next(e1); 68 } else if (c>0) { 69 nextNode2 = next(e2); 70 } else { current = nextNode2; nextNode2 = next(e2); 73 nextNode1 = next(e1); 74 position++; 75 return current; 76 } 77 } 78 return null; 79 } 80 81 public Item current() { 82 return current; 83 } 84 85 public int position() { 86 return position; 87 } 88 89 public SequenceIterator getAnother() throws XPathException { 90 return new IntersectionEnumeration(e1.getAnother(), e2.getAnother(), comparer); 91 } 92 93 102 103 public int getProperties() { 104 return 0; 105 } 106 } 107 108 | Popular Tags |