| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.tree.iter; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.LastPositionFinder; |
| 11 |
import net.sf.saxon.om.GroundedValue; |
| 12 |
import net.sf.saxon.om.Item; |
| 13 |
import net.sf.saxon.om.NodeInfo; |
| 14 |
import net.sf.saxon.om.SequenceIterator; |
| 15 |
import net.sf.saxon.value.AtomicValue; |
| 16 |
import net.sf.saxon.value.SequenceExtent; |
| 17 |
|
| 18 |
import java.util.List; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class ListIterator<T extends Item<?>> |
| 25 |
implements UnfailingIterator<T>, LastPositionFinder, LookaheadIterator<T>, GroundedIterator<T>, ReversibleIterator<T> { |
| 26 |
|
| 27 |
private int index = 0; |
| 28 |
protected List<T> list; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public ListIterator(List<T> list) { |
| 37 |
index = 0; |
| 38 |
this.list = list; |
| 39 |
} |
| 40 |
|
| 41 |
public boolean hasNext() { |
| 42 |
return index < list.size(); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
public T next() { |
| 47 |
if (index >= list.size()) { |
| 48 |
return null; |
| 49 |
} |
| 50 |
return list.get(index++); |
| 51 |
} |
| 52 |
|
| 53 |
public int getLength() { |
| 54 |
return list.size(); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public int getProperties() { |
| 68 |
return GROUNDED | LAST_POSITION_FINDER | LOOKAHEAD; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public GroundedValue<T> materialize() { |
| 80 |
return SequenceExtent.makeSequenceExtent(list); |
| 81 |
} |
| 82 |
|
| 83 |
@Override |
| 84 |
public GroundedValue<T> getResidue() { |
| 85 |
List<T> l2 = list; |
| 86 |
if (index != 0) { |
| 87 |
l2 = l2.subList(index, l2.size()); |
| 88 |
} |
| 89 |
return SequenceExtent.makeSequenceExtent(l2); |
| 90 |
} |
| 91 |
|
| 92 |
public SequenceIterator<T> getReverseIterator() { |
| 93 |
return new ReverseListIterator<>(list); |
| 94 |
} |
| 95 |
|
| 96 |
public static class Atomic extends ListIterator<AtomicValue> implements AtomicIterator { |
| 97 |
public Atomic (List<AtomicValue> list) { |
| 98 |
super(list); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
public static class OfNodes extends ListIterator<NodeInfo> implements AxisIterator { |
| 103 |
public OfNodes(List<NodeInfo> list) { |
| 104 |
super(list); |
| 105 |
} |
| 106 |
|
| 107 |
public NodeInfo next() { |
| 108 |
return super.next(); |
| 109 |
} |
| 110 |
|
| 111 |
} |
| 112 |
} |
| 113 |
|