1 package com.icl.saxon.expr; 2 import com.icl.saxon.*; 3 import com.icl.saxon.om.*; 4 5 import java.util.*; 6 7 15 16 17 public class LookaheadEnumerator implements NodeEnumeration, LastPositionFinder { 18 19 27 28 private NodeEnumeration base; 29 private Vector reservoir = null; 30 private int reservoirPosition = -1; 31 private int position = 0; 32 private int last = -1; 33 34 39 40 public LookaheadEnumerator(NodeEnumeration base) { 41 this.base = base; 42 } 43 44 47 48 public boolean hasMoreElements() { 49 if (reservoir==null) { 50 return base.hasMoreElements(); 51 } else { 52 return reservoirPosition < reservoir.size(); 53 } 54 } 55 56 59 60 public NodeInfo nextElement() throws XPathException { 61 if (reservoir==null) { 62 position++; 63 return base.nextElement(); 64 } else { 65 if (reservoirPosition<reservoir.size()) { 66 position++; 67 return (NodeInfo)reservoir.elementAt(reservoirPosition++); 68 } else { 69 return null; 70 } 71 } 72 } 73 74 77 78 public int getLastPosition() throws XPathException { 79 if (last>0) { 80 return last; 81 } else { 82 reservoir = new Vector(); 84 reservoirPosition = 0; 85 last = position; 86 while (base.hasMoreElements()) { 87 reservoir.addElement(base.nextElement()); 88 last++; 89 } 90 return last; 91 } 92 } 93 94 97 98 public boolean isSorted() { 99 return base.isSorted(); 100 } 101 102 public boolean isReverseSorted() { 103 return base.isReverseSorted(); 104 } 105 106 107 110 111 public boolean isPeer() { 112 return base.isPeer(); 113 } 114 } 115 116 117 118 | Popular Tags |