@Test public void shouldDuringStopWhenAllStop() throws IOException { final long millis = System.currentTimeMillis(); final long millis2 = millis + 1; final long millis3 = millis + 2; final long millis4 = millis + 3; final long millis5 = millis + 4; final Storage storage = createStorage(1000, Arrays.asList(new Pair<Long, int[]>(millis, new int[0]), new Pair<Long, int[]>(millis2, new int[0]), new Pair<Long, int[]>(millis3, new int[0]), new Pair<Long, int[]>(millis4, new int[0]))); final Iterable<Pair<Long, int[]>> iterable = storage.during(millis3, millis5); final Iterator<Pair<Long, int[]>> result = iterable.iterator(); Assert.assertEquals(millis3, (long) result.next().first); Assert.assertEquals(millis4, (long) result.next().first); Assert.assertFalse(result.hasNext()); }
@Override public Iterable<Pair<Long, int[]>> during(final long beginning, final long end) throws IOException { return new Iterable<Pair<Long, int[]>>() { final Iterable<Pair<Long, int[]>> all = all(); @Override public Iterator<Pair<Long, int[]>> iterator() { return new AbstractIterator<Pair<Long, int[]>>() { final Iterator<Pair<Long, int[]>> iterator = all.iterator(); @Override protected Pair<Long, int[]> computeNext() { while (this.iterator.hasNext()) { final Pair<Long, int[]> consolidates = this.iterator.next(); final long timestamp = consolidates.first; if (timestamp < beginning) { continue; } if (timestamp > end) { break; } return consolidates; } return endOfData(); } }; } }; }
Storage implements Reader { @Override public Iterable<Pair<Long, int[]>> during(final long beginning, final long end) throws IOException { return new Iterable<Pair<Long, int[]>>() { final Iterable<Pair<Long, int[]>> all = all(); @Override public Iterator<Pair<Long, int[]>> iterator() { return new AbstractIterator<Pair<Long, int[]>>() { final Iterator<Pair<Long, int[]>> iterator = all.iterator(); @Override protected Pair<Long, int[]> computeNext() { while (this.iterator.hasNext()) { final Pair<Long, int[]> consolidates = this.iterator.next(); final long timestamp = consolidates.first; if (timestamp < beginning) { continue; } if (timestamp > end) { break; } return consolidates; } return endOfData(); } }; } }; } }
Storage implements Reader { @Override public Iterable<Pair<Long, int[]>> during(final long beginning, final long end) throws IOException { return new Iterable<Pair<Long, int[]>>() { final Iterable<Pair<Long, int[]>> all = all(); @Override public Iterator<Pair<Long, int[]>> iterator() { return new AbstractIterator<Pair<Long, int[]>>() { final Iterator<Pair<Long, int[]>> iterator = all.iterator(); @Override protected Pair<Long, int[]> computeNext() { while (this.iterator.hasNext()) { final Pair<Long, int[]> consolidates = this.iterator.next(); final long timestamp = consolidates.first; if (timestamp < beginning) { continue; } if (timestamp > end) { break; } return consolidates; } return endOfData(); } }; } }; } Storage(final int maximumSize); }
Storage implements Reader { @Override public Iterable<Pair<Long, int[]>> during(final long beginning, final long end) throws IOException { return new Iterable<Pair<Long, int[]>>() { final Iterable<Pair<Long, int[]>> all = all(); @Override public Iterator<Pair<Long, int[]>> iterator() { return new AbstractIterator<Pair<Long, int[]>>() { final Iterator<Pair<Long, int[]>> iterator = all.iterator(); @Override protected Pair<Long, int[]> computeNext() { while (this.iterator.hasNext()) { final Pair<Long, int[]> consolidates = this.iterator.next(); final long timestamp = consolidates.first; if (timestamp < beginning) { continue; } if (timestamp > end) { break; } return consolidates; } return endOfData(); } }; } }; } Storage(final int maximumSize); @Override Optional<Long> beginning(); @Override Optional<Long> end(); @Override Iterable<Pair<Long, int[]>> during(final long beginning, final long end); abstract void append(long timestamp, int[] values); }
Storage implements Reader { @Override public Iterable<Pair<Long, int[]>> during(final long beginning, final long end) throws IOException { return new Iterable<Pair<Long, int[]>>() { final Iterable<Pair<Long, int[]>> all = all(); @Override public Iterator<Pair<Long, int[]>> iterator() { return new AbstractIterator<Pair<Long, int[]>>() { final Iterator<Pair<Long, int[]>> iterator = all.iterator(); @Override protected Pair<Long, int[]> computeNext() { while (this.iterator.hasNext()) { final Pair<Long, int[]> consolidates = this.iterator.next(); final long timestamp = consolidates.first; if (timestamp < beginning) { continue; } if (timestamp > end) { break; } return consolidates; } return endOfData(); } }; } }; } Storage(final int maximumSize); @Override Optional<Long> beginning(); @Override Optional<Long> end(); @Override Iterable<Pair<Long, int[]>> during(final long beginning, final long end); abstract void append(long timestamp, int[] values);  }