gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / util / ChainedIterator.java @ 2003
History | View | Annotate | Download (1000 Bytes)
1 |
package org.gvsig.tools.util; |
---|---|
2 |
|
3 |
import java.util.Iterator; |
4 |
|
5 |
public class ChainedIterator<T> implements Iterator<T> { |
6 |
|
7 |
private final Iterator<T>[] iterators; |
8 |
private int current; |
9 |
|
10 |
public ChainedIterator(Iterator<T>... iterators) { |
11 |
this.iterators = iterators;
|
12 |
this.current = 0; |
13 |
} |
14 |
|
15 |
@Override
|
16 |
public boolean hasNext() { |
17 |
if( this.iterators == null ) { |
18 |
return false; |
19 |
} |
20 |
while (this.current < this.iterators.length) { |
21 |
Iterator<T> it = this.iterators[this.current]; |
22 |
if( it!=null ) { |
23 |
if (it.hasNext()) {
|
24 |
return true; |
25 |
} |
26 |
} |
27 |
this.current++;
|
28 |
} |
29 |
return false; |
30 |
} |
31 |
|
32 |
@Override
|
33 |
public T next() {
|
34 |
if( this.iterators == null ) { |
35 |
return null; |
36 |
} |
37 |
Iterator<T> it = this.iterators[this.current]; |
38 |
if( it==null ) { |
39 |
return null; |
40 |
} |
41 |
return it.next();
|
42 |
} |
43 |
} |