@Override protected void handleClose() throws X { try { super.handleClose(); } finally { nextElement = null; } } }
@Override public synchronized E next() throws X { if (isClosed()) { throw new NoSuchElementException("Iteration has been closed"); } return super.next(); }
@Override public synchronized void remove() throws X { if (isClosed()) { throw new IllegalStateException("Iteration has been closed"); } super.remove(); }
/** * Checks whether the wrapped Iteration contains more elements, closing this Iteration when this is not * the case. * * @return <tt>true</tt> if the wrapped Iteration contains more elements, <tt>false</tt> otherwise. */ public boolean hasNext() throws X { if (isClosed()) { return false; } else if (Thread.currentThread().isInterrupted()) { close(); return false; } boolean result = wrappedIter.hasNext(); if (!result) { close(); } return result; }
@Override public boolean hasNext() throws X { if (isClosed()) { return false; } boolean result = super.hasNext(); if (!result) { close(); } return result; }
@Override public boolean hasNext() throws E { if (isClosed()) { return false; } if (super.hasNext()) { return true; } // auto-close when exhausted close(); return false; }
/** * Returns the next element from the wrapped Iteration. * * @throws java.util.NoSuchElementException * If all elements have been returned or it has been closed. */ public E next() throws X { if (isClosed()) { throw new NoSuchElementException("The iteration has been closed."); } else if (Thread.currentThread().isInterrupted()) { close(); throw new NoSuchElementException("The iteration has been interrupted."); } try { return wrappedIter.next(); } catch(NoSuchElementException e) { close(); throw e; } }
@Override protected void handleClose() throws X { try { super.handleClose(); } finally { nextElement = null; } } }
@Override public synchronized E next() throws X { if (isClosed()) { throw new NoSuchElementException("Iteration has been closed"); } return super.next(); }
@Override public boolean hasNext() throws X { if (isClosed()) { return false; } boolean underLimit = returnCount < limit; if (!underLimit) { close(); return false; } return super.hasNext(); }
@Override public synchronized void remove() throws X { if (isClosed()) { throw new IllegalStateException("Iteration has been closed"); } super.remove(); }
/** * Checks whether the wrapped Iteration contains more elements, closing this Iteration when this is not * the case. * * @return <tt>true</tt> if the wrapped Iteration contains more elements, <tt>false</tt> otherwise. */ public boolean hasNext() throws X { if (isClosed()) { return false; } else if (Thread.currentThread().isInterrupted()) { close(); return false; } boolean result = wrappedIter.hasNext(); if (!result) { close(); } return result; }
@Override protected void handleClose() throws X { try { super.handleClose(); } finally { nextElement = null; } } }
@Override public E next() throws X { if (isClosed()) { throw new NoSuchElementException("The iteration has been closed."); } if (returnCount >= limit) { close(); throw new NoSuchElementException("limit reached"); } returnCount++; return super.next(); } }
@Override public boolean hasNext() throws X { if (isClosed()) { return false; } boolean underLimit = returnCount < limit; if (!underLimit) { close(); return false; } return super.hasNext(); }
@Override public void remove() throws X { if (isClosed()) { throw new IllegalStateException(); } try { super.remove(); } catch (IllegalStateException e) { close(); throw e; } }
/** * Checks whether the wrapped Iteration contains more elements, closing this Iteration when this is not * the case. * * @return <tt>true</tt> if the wrapped Iteration contains more elements, <tt>false</tt> otherwise. */ @Override public boolean hasNext() throws X { if (isClosed()) { return false; } else if (Thread.currentThread().isInterrupted()) { close(); return false; } boolean result = wrappedIter.hasNext(); if (!result) { close(); } return result; }