Class CurrentIterator<T>

  • Type Parameters:
    T - the type of elements in the iterator

    public class CurrentIterator<T>
    extends Object
    This iterator can return the current element rather than the next element as a normal iterator does. At construction it is positioned before the first element. You can move to the first element with moveNext(). Then you can access the current element as many times as needed with getCurrent(), and you can move to the next element with moveNext().
    • Constructor Detail

      • CurrentIterator

        public CurrentIterator​(Iterator<? extends T> it)
        Constructs a new instance. The iterator will be positioned before the first element.
        Parameters:
        it - the underlying iterator
    • Method Detail

      • getCurrent

        public T getCurrent()
        Returns the current element. If the iterator is positioned before the first element or after the last element, this method returns null. An element itself may also be null. Use moveNext() to know the position.
        Returns:
        the current element (can be null)
      • moveNext

        public boolean moveNext()
        Moves to the next element. If there is no more element, this method returns false.
        Returns:
        true if the iterator is at the next element, false if there is no more element
      • removeMoveNext

        public boolean removeMoveNext()
        Removes the current element and moves to the next element. If there is no more element, this method returns false.
        Returns:
        true if the iterator is at the next element, false if there is no more element