1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.group;
17
18 import io.netty.util.internal.ObjectUtil;
19
20 import java.util.Iterator;
21 import java.util.NoSuchElementException;
22
23
24
25 final class CombinedIterator<E> implements Iterator<E> {
26
27 private final Iterator<E> i1;
28 private final Iterator<E> i2;
29 private Iterator<E> currentIterator;
30
31 CombinedIterator(Iterator<E> i1, Iterator<E> i2) {
32 this.i1 = ObjectUtil.checkNotNull(i1, "i1");
33 this.i2 = ObjectUtil.checkNotNull(i2, "i2");
34 this.currentIterator = i1;
35 }
36
37 @Override
38 public boolean hasNext() {
39 for (;;) {
40 if (currentIterator.hasNext()) {
41 return true;
42 }
43
44 if (currentIterator == i1) {
45 currentIterator = i2;
46 } else {
47 return false;
48 }
49 }
50 }
51
52 @Override
53 public E next() {
54 for (;;) {
55 try {
56 return currentIterator.next();
57 } catch (NoSuchElementException e) {
58 if (currentIterator == i1) {
59 currentIterator = i2;
60 } else {
61 throw e;
62 }
63 }
64 }
65 }
66
67 @Override
68 public void remove() {
69 currentIterator.remove();
70 }
71
72 }