| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.tree.iter; |
| 9 | |
| 10 | import net.sf.saxon.om.NodeInfo; |
| 11 | |
| 12 | /** |
| 13 | * An iterator over nodes, that concatenates the nodes returned by two supplied iterators. |
| 14 | */ |
| 15 | |
| 16 | public class ConcatenatingAxisIterator implements AxisIterator { |
| 17 | |
| 18 | AxisIterator first; |
| 19 | AxisIterator second; |
| 20 | AxisIterator active; |
| 21 | |
| 22 | public ConcatenatingAxisIterator(AxisIterator first, AxisIterator second) { |
| 23 | this.first = first; |
| 24 | this.second = second; |
| 25 | this.active = first; |
| 26 | } |
| 27 | |
| 28 | public static AxisIterator makeConcatenatingIterator(AxisIterator first, AxisIterator second) { |
| 29 | if (first instanceof EmptyIterator.OfNodes) { |
| 30 | return second; |
| 31 | } |
| 32 | if (second instanceof EmptyIterator.OfNodes) { |
| 33 | return first; |
| 34 | } |
| 35 | return new ConcatenatingAxisIterator(first, second); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * Get the next item in the sequence. <BR> |
| 41 | * |
| 42 | * @return the next Item. If there are no more nodes, return null. |
| 43 | */ |
| 44 | |
| 45 | /*@Nullable*/ |
| 46 | public NodeInfo next() { |
| 47 | NodeInfo n = active.next(); |
| 48 | if (n == null && active == first) { |
| 49 | active = second; |
| 50 | n = second.next(); |
| 51 | } |
| 52 | return n; |
| 53 | } |
| 54 | |
| 55 | public void close() { |
| 56 | first.close(); |
| 57 | second.close(); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get properties of this iterator, as a bit-significant integer. |
| 62 | * |
| 63 | * @return the properties of this iterator. This will be some combination of |
| 64 | * properties such as {@link #GROUNDED}, {@link #LAST_POSITION_FINDER}, |
| 65 | * and {@link #LOOKAHEAD}. It is always |
| 66 | * acceptable to return the value zero, indicating that there are no known special properties. |
| 67 | * It is acceptable for the properties of the iterator to change depending on its state. |
| 68 | */ |
| 69 | |
| 70 | public int getProperties() { |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | } |
| 76 |