| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.sort.ItemOrderComparer; |
| 11 |
import net.sf.saxon.om.NodeInfo; |
| 12 |
import net.sf.saxon.om.SequenceIterator; |
| 13 |
import net.sf.saxon.trans.XPathException; |
| 14 |
import net.sf.saxon.tree.iter.LookaheadIterator; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public class UnionEnumeration implements SequenceIterator<NodeInfo>, LookaheadIterator<NodeInfo> { |
| 21 |
|
| 22 |
private SequenceIterator<? extends NodeInfo> e1; |
| 23 |
private SequenceIterator<? extends NodeInfo> e2; |
| 24 |
private NodeInfo nextNode1 = null; |
| 25 |
private NodeInfo nextNode2 = null; |
| 26 |
private ItemOrderComparer comparer; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public UnionEnumeration(SequenceIterator<? extends NodeInfo> p1, SequenceIterator<? extends NodeInfo> p2, |
| 40 |
ItemOrderComparer comparer) throws XPathException { |
| 41 |
this.e1 = p1; |
| 42 |
this.e2 = p2; |
| 43 |
this.comparer = comparer; |
| 44 |
|
| 45 |
nextNode1 = next(e1); |
| 46 |
nextNode2 = next(e2); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
private NodeInfo next(SequenceIterator iter) throws XPathException { |
| 59 |
return (NodeInfo) iter.next(); |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
public boolean hasNext() { |
| 64 |
return nextNode1 != null || nextNode2 != null; |
| 65 |
} |
| 66 |
|
| 67 |
public NodeInfo next() throws XPathException { |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
if (nextNode1 != null && nextNode2 != null) { |
| 72 |
int c = comparer.compare(nextNode1, nextNode2); |
| 73 |
if (c < 0) { |
| 74 |
NodeInfo current = nextNode1; |
| 75 |
nextNode1 = next(e1); |
| 76 |
return current; |
| 77 |
|
| 78 |
} else if (c > 0) { |
| 79 |
NodeInfo current = nextNode2; |
| 80 |
nextNode2 = next(e2); |
| 81 |
return current; |
| 82 |
|
| 83 |
} else { |
| 84 |
NodeInfo current = nextNode2; |
| 85 |
nextNode2 = next(e2); |
| 86 |
nextNode1 = next(e1); |
| 87 |
return current; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
if (nextNode1 != null) { |
| 94 |
NodeInfo current = nextNode1; |
| 95 |
nextNode1 = next(e1); |
| 96 |
return current; |
| 97 |
} |
| 98 |
if (nextNode2 != null) { |
| 99 |
NodeInfo current = nextNode2; |
| 100 |
nextNode2 = next(e2); |
| 101 |
return current; |
| 102 |
} |
| 103 |
return null; |
| 104 |
} |
| 105 |
|
| 106 |
public void close() { |
| 107 |
e1.close(); |
| 108 |
e2.close(); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public int getProperties() { |
| 122 |
return LOOKAHEAD; |
| 123 |
} |
| 124 |
|
| 125 |
} |
| 126 |
|