1 package net.sf.saxon.om; 2 3 import net.sf.saxon.expr.LastPositionFinder; 4 import net.sf.saxon.expr.ReversibleIterator; 5 6 7 11 12 13 public final class ReverseArrayIterator implements AxisIterator, 14 ReversibleIterator, 15 LookaheadIterator, 16 LastPositionFinder { 17 18 Item[] items; 19 int index = 0; 20 int start; 21 int end; Item current = null; 23 24 32 33 public ReverseArrayIterator(Item[] items, int start, int end) { 34 this.items = items; 35 this.end = end; 36 this.start = start; 37 index = end - 1; 38 } 39 40 48 49 public boolean hasNext() { 50 return index >= start; 51 } 52 53 public Item next() { 54 if (index >= start) { 55 current = items[index--]; 56 return current; 57 } else { 58 current = null; 59 return null; 60 } 61 } 62 63 public Item current() { 64 return current; 65 } 66 67 public int position() { 68 if (index < start-1) { 69 return -1; } 71 return end - 1 - index; 72 } 73 74 public int getLastPosition() { 75 return end - start; 76 } 77 78 public SequenceIterator getAnother() { 79 return new ReverseArrayIterator(items, start, end); 80 } 81 82 91 92 public int getProperties() { 93 return LAST_POSITION_FINDER; 94 } 95 96 102 103 public SequenceIterator getReverseIterator() { 104 return new ArrayIterator(items, start, end); 105 } 106 } 107 108 109 | Popular Tags |