| 16 | import java.util.NoSuchElementException; |
| 17 | |
| 18 | public class SeekableViewChain implements SeekableView { |
| 19 | |
| 20 | private final List<SeekableView> iterators; |
| 21 | private int currentIterator; |
| 22 | |
| 23 | SeekableViewChain(List<SeekableView> iterators) { |
| 24 | this.iterators = iterators; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Returns {@code true} if this view has more elements. |
| 29 | */ |
| 30 | @Override |
| 31 | public boolean hasNext() { |
| 32 | SeekableView iterator = getCurrentIterator(); |
| 33 | return iterator != null && iterator.hasNext(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns a <em>view</em> on the next data point. |
| 38 | * No new object gets created, the referenced returned is always the same |
| 39 | * and must not be stored since its internal data structure will change the |
| 40 | * next time {@code next()} is called. |
| 41 | * |
| 42 | * @throws NoSuchElementException if there were no more elements to iterate |
| 43 | * on (in which case {@link #hasNext} would have returned {@code false}. |
| 44 | */ |
| 45 | @Override |
| 46 | public DataPoint next() { |
| 47 | SeekableView iterator = getCurrentIterator(); |
| 48 | if (iterator == null || !iterator.hasNext()) { |
| 49 | throw new NoSuchElementException("No elements left in iterator"); |
| 50 | } |
| 51 | |
| 52 | DataPoint next = iterator.next(); |
| 53 | |
| 54 | if (!iterator.hasNext()) { |
| 55 | currentIterator++; |
| 56 | } |
| 57 | |
| 58 | return next; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Unsupported operation. |
| 63 | * |
| 64 | * @throws UnsupportedOperationException always. |
| 65 | */ |
| 66 | @Override |
| 67 | public void remove() { |
| 68 | throw new UnsupportedOperationException("Removing items is not supported"); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Advances the iterator to the given point in time. |
| 73 | * <p> |
| 74 | * This allows the iterator to skip all the data points that are strictly |
| 75 | * before the given timestamp. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…