1 package net.sf.saxon.om; 2 3 import net.sf.saxon.expr.LastPositionFinder; 4 import net.sf.saxon.expr.ReversibleIterator; 5 import net.sf.saxon.value.SingletonNode; 6 import net.sf.saxon.value.Value; 7 import net.sf.saxon.trans.XPathException; 8 9 10 13 14 public class SingletonIterator implements AxisIterator, 15 ReversibleIterator, LastPositionFinder, GroundedIterator, LookaheadIterator { 16 17 private Item value; 18 private int position = 0; 19 20 24 25 private SingletonIterator(Item value) { 26 this.value = value; 27 } 28 29 35 36 public static AxisIterator makeIterator(Item item) { 37 if (item==null) { 38 return EmptyIterator.getInstance(); 39 } else { 40 return new SingletonIterator(item); 41 } 42 } 43 44 52 53 public boolean hasNext() { 54 return position == 0; 55 } 56 57 public Item next() { 58 if (position == 0) { 59 position = 1; 60 return value; 61 } else if (position == 1) { 62 position = -1; 63 return null; 64 } else { 65 return null; 66 } 67 } 68 69 public Item current() { 70 if (position == 1) { 71 return value; 72 } else { 73 return null; 74 } 75 } 76 77 82 public int position() { 83 return position; 84 } 85 86 public int getLastPosition() { 87 return 1; 88 } 89 90 public SequenceIterator getAnother() { 91 return new SingletonIterator(value); 92 } 93 94 public SequenceIterator getReverseIterator() { 95 return new SingletonIterator(value); 96 } 97 98 public Item getValue() { 99 return value; 100 } 101 102 109 110 public Value materialize() { 111 if (value instanceof Value) { 112 try { 113 value = (Item)((Value)value).reduce(); 114 } catch (XPathException err) {} 115 return (Value)value; 116 } else { 117 return new SingletonNode((NodeInfo)value); 118 } 119 } 120 121 130 131 public int getProperties() { 132 return GROUNDED | LAST_POSITION_FINDER | LOOKAHEAD; 133 } 134 135 } 136 137 | Popular Tags |