1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.ebay.carad.os.vitalsigns;
22
23 import java.util.Collection;
24 import java.util.Iterator;
25
26 import org.apache.commons.collections.iterators.EmptyIterator;
27
28 /***
29 * An iterator that goes over an iterator containing <code>IDashboardReportContainer</code>
30 * objects, and explodes them to expose an iterator over <code>IDashboardReport</code> objects.
31 * Does not implement <code>Iterator</code> because it doesn't support remove, and doesn't return
32 * <code>Object</code>.
33 *
34 * @author Jeremy Kraybill
35 * @author Jeremy Thomerson
36 * @version $Id$
37 */
38 public class ReportContainerIterator {
39
40 /*** The wrapped list iterator, must be all IDashboardReportContainer objects. */
41 private final Iterator myIterator;
42
43 /*** The current iterator over the current IDashboardReportContainer. */
44 private Iterator currentIterator = EmptyIterator.INSTANCE;
45
46 /***
47 * Basic constructor.
48 *
49 * @param col a collection of <code>IDashboardReportContainer</code> objects.
50 */
51 public ReportContainerIterator(Collection col) {
52 if (col == null) {
53 throw new IllegalArgumentException("Wrapped collection must not be null.");
54 }
55 myIterator = col.iterator();
56 }
57
58 /***
59 * Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)
60 *
61 * @return true if the iterator has more elements.
62 */
63 public boolean hasNext() {
64 moveToNextActive();
65 return currentIterator.hasNext();
66 }
67
68 /***
69 * Returns the next <code>IDashboardReport</code> in the iteration.
70 *
71 * @return the next element in the iteration.
72 */
73 public IDashboardReport next() {
74 moveToNextActive();
75 return (IDashboardReport) currentIterator.next();
76 }
77
78 /***
79 * Ensures our current iterator has elements to offer, or that we are at the end of the line.
80 */
81 private void moveToNextActive() {
82 while (!currentIterator.hasNext() && myIterator.hasNext()) {
83
84 Object obj = myIterator.next();
85 currentIterator = ((IDashboardReportContainer) obj).getReports().iterator();
86 }
87 }
88
89 }