1 24 25 package org.objectweb.dream.util; 26 27 import java.util.Iterator ; 28 import java.util.NoSuchElementException ; 29 30 33 public class MultipleIterator implements Iterator 34 { 35 36 Iterator [] iters; 37 int i; 38 39 44 public MultipleIterator(Iterator [] iters) 45 { 46 this.iters = iters; 47 i = 0; 48 } 49 50 53 public void remove() 54 { 55 iters[i].remove(); 56 } 57 58 61 public boolean hasNext() 62 { 63 while (i < iters.length) 64 { 65 boolean hasNext = iters[i].hasNext(); 66 if (hasNext) 67 { 68 return true; 69 } 70 i++; 71 } 72 return false; 73 } 74 75 78 public Object next() 79 { 80 if (!iters[i].hasNext()) 81 { 82 i++; 83 while (i < iters.length) 84 { 85 if (iters[i].hasNext()) 86 { 87 return iters[i].next(); 88 } 89 i++; 90 } 91 throw new NoSuchElementException (); 92 } 93 94 return iters[i].next(); 95 } 96 } | Popular Tags |