/** * return current index * This method can be called only per call to next(). * This method can not be called after call remove(). * * @throws IllegalStateException - if the next() method has not yet been called */ public int getCurrentIndex() { if (state == State.NEXT_CALLED && index < indexEnd && indexEnd <= intBag.size()) { return index; } throw new IllegalStateException(getErrorMessage(index)); }
/** * return current index * This method can be called only per call to next(). * This method can not be called after call remove(). * * @throws IllegalStateException - if the next() method has not yet been called */ public int getCurrentIndex() { if (state == State.NEXT_CALLED && index < indexEnd && indexEnd <= intBag.size()) { return index; } throw new IllegalStateException(getErrorMessage(index)); }
/** * Returns the next element in the iteration. * * @return the next element in the iteration * @throws NoSuchElementException - if the iteration has no more elements */ public int next() { final int newIndex = index + 1; if (newIndex < indexEnd && indexEnd <= intBag.size()) { index = newIndex; state = State.NEXT_CALLED; return intBag.getData()[index]; } throw new NoSuchElementException(getErrorMessage(newIndex)); }
/** * Returns the next element in the iteration. * * @return the next element in the iteration * @throws NoSuchElementException - if the iteration has no more elements */ public int next() { final int newIndex = index + 1; if (newIndex < indexEnd && indexEnd <= intBag.size()) { index = newIndex; state = State.NEXT_CALLED; return intBag.getData()[index]; } throw new NoSuchElementException(getErrorMessage(newIndex)); }
/** * Removes from the underlying collection the last element returned by this iterator (optional operation). * This method can be called only once per call to next(). * The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method. * * @throws IllegalStateException - if the next() method has not yet been called, or the remove() method has already been called after the last call to the next() method */ public void remove() { if (state == State.NEXT_CALLED && index < indexEnd && indexEnd <= intBag.size()) { state = State.REMOVE_CALLED; intBag.remove(index); index--; indexEnd--; assert index < indexEnd; } else { throw new IllegalStateException(getErrorMessage(index)); } }
/** * Removes from the underlying collection the last element returned by this iterator (optional operation). * This method can be called only once per call to next(). * The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method. * * @throws IllegalStateException - if the next() method has not yet been called, or the remove() method has already been called after the last call to the next() method */ public void remove() { if (state == State.NEXT_CALLED && index < indexEnd && indexEnd <= intBag.size()) { state = State.REMOVE_CALLED; intBag.remove(index); index--; indexEnd--; assert index < indexEnd; } else { throw new IllegalStateException(getErrorMessage(index)); } }