IteratorWithHistory implements Iterator<T> { public T getPrevious(int idx) { if ( idx >= capacity || idx < 0 ) throw new IndexOutOfBoundsException("Index: " + idx) ; if ( idx >= history.size() ) return null ; return history.get(idx) ; } IteratorWithHistory(Iterator<T> iter, int N); @Override boolean hasNext(); @Override T next(); @Override void remove(); T getPrevious(int idx); int currentSize();  }
@Test(expected=IndexOutOfBoundsException.class) public void iterHistory_04() { IteratorWithHistory<String> iter = createHistory(2, "a", "b", "c") ; iter.getPrevious(2) ; }