Range { public static Stream<Integer> range(final int from, final int to, final int step) { return new Stream<Integer>() { @Override public Iterator<Integer> iterator() { return new ReadOnlyIterator<Integer>() { int value = from; @Override public boolean hasNext() { return value < to; } @Override public Integer next() { final int v = value; value += step; return v; } }; } }; }  static Stream<Integer> range(final int from, final int to, final int step); static Stream<Integer> range(final int from, final int to);  }
@Test public void testRange() throws Exception { assertIterableEquals(asList(1, 2, 3), range(1, 4)); assertIterableEquals(asList(1, 3, 5), range(1, 6, 2)); assertIterableEquals(asList(-3, -2, -1), range(-3, 0)); assertIterableEquals(Collections.<Integer>emptyList(), range(1, 1)); assertIterableEquals(singletonList(1), range(1, 2)); }