1 22 package org.jboss.util.collection; 23 24 import java.util.Iterator ; 25 import java.util.NoSuchElementException ; 26 27 34 public class CompoundIterator 35 implements Iterator 36 { 37 38 protected final Iterator iters[]; 39 40 41 protected int index; 42 43 50 public CompoundIterator(final Iterator iters[]) { 51 if (iters == null || iters.length == 0) 52 throw new IllegalArgumentException ("array is null or empty"); 53 54 this.iters = iters; 55 } 56 57 62 public boolean hasNext() { 63 for (; index < iters.length; index++) { 64 if (iters[index] != null && iters[index].hasNext()) { 65 return true; 66 } 67 } 68 69 return false; 70 } 71 72 79 public Object next() { 80 if (!hasNext()) { 81 throw new NoSuchElementException (); 82 } 83 84 return iters[index].next(); 85 } 86 87 93 public void remove() { 94 iters[index].remove(); 95 } 96 } 97 | Popular Tags |