DataSeries implements Iterable<DataSeries.Point> { @NonNull public Iterator<Point> iterator() { return new Iterator<Point>() { private int i = 0; public boolean hasNext() { return i < n; } public Point next() { if (i < n) return points.get(i++); else throw new NoSuchElementException(); } public void remove() { throw new UnsupportedOperationException(); } }; }  void addPoint(double x, double y); int size(); void reset(); @NonNull Iterator<Point> iterator(); @NonNull @Override String toString();  }
@Test public void iterator() { DataSeries series = new DataSeries(); series.addPoint(1,2); series.addPoint(2,3); int count = 0; for (DataSeries.Point point : series) { count++; } assertEquals(2, count); }