1 30 31 32 package org.hsqldb.lib; 33 34 import java.util.NoSuchElementException ; 35 36 47 public class WrapperIterator implements Iterator { 48 49 private static final Object [] emptyelements = new Object [0]; 50 private Object [] elements; 51 private int i; 52 53 private boolean chained; 55 private Iterator it1; 56 private Iterator it2; 57 58 59 private boolean notNull; 60 61 64 public WrapperIterator() { 65 this.elements = emptyelements; 66 } 67 68 73 public WrapperIterator(Object [] elements) { 74 this.elements = elements; 75 } 76 77 82 public WrapperIterator(Object [] elements, boolean notNull) { 83 this.elements = elements; 84 this.notNull = notNull; 85 } 86 87 92 public WrapperIterator(Object element) { 93 this.elements = new Object []{ element }; 94 } 95 96 102 public WrapperIterator(Iterator it1, Iterator it2) { 103 104 this.it1 = it1; 105 this.it2 = it2; 106 chained = true; 107 } 108 109 115 public boolean hasNext() { 116 117 if (chained) { 119 if (it1 == null) { 120 if (it2 == null) { 121 return false; 122 } 123 124 if (it2.hasNext()) { 125 return true; 126 } 127 128 it2 = null; 129 130 return false; 131 } else { 132 if (it1.hasNext()) { 133 return true; 134 } 135 136 it1 = null; 137 138 return hasNext(); 139 } 140 } 141 142 if (elements == null) { 144 return false; 145 } 146 147 for (; notNull && i < elements.length && elements[i] == null; i++) {} 148 149 if (i < elements.length) { 150 return true; 151 } else { 152 153 elements = null; 155 156 return false; 157 } 158 } 159 160 166 public Object next() { 167 168 if (chained) { 170 if (it1 == null) { 171 if (it2 == null) { 172 throw new NoSuchElementException (); 173 } 174 175 if (it2.hasNext()) { 176 return it2.next(); 177 } 178 179 it2 = null; 180 181 next(); 182 } else { 183 if (it1.hasNext()) { 184 return it1.next(); 185 } 186 187 it1 = null; 188 189 next(); 190 } 191 } 192 193 if (hasNext()) { 195 return elements[i++]; 196 } 197 198 throw new NoSuchElementException (); 199 } 200 201 public int nextInt() { 202 throw new NoSuchElementException (); 203 } 204 205 public long nextLong() { 206 throw new NoSuchElementException (); 207 } 208 209 public void remove() { 210 throw new NoSuchElementException (); 211 } 212 } 213 | Popular Tags |