Class AbstractEnumerator<E>

java.lang.Object
java.util.Spliterators.AbstractSpliterator<E>
org.jhotdraw8.collection.enumerator.AbstractEnumerator<E>
Type Parameters:
E - the element type
All Implemented Interfaces:
Spliterator<E>, BareEnumerator<E>, Enumerator<E>

public abstract class AbstractEnumerator<E> extends Spliterators.AbstractSpliterator<E> implements Enumerator<E>
Abstract base classes for Enumerators.

Subclasses should only implement the BareEnumerator.moveNext() method and (optionally) the Spliterator.trySplit() method:

     public boolean moveNext() {
         if (...end not reached...) {
             current = ...;
             return true;
         }
         return false;
     }
 
  • Field Details

    • current

      protected E current
      The current element of the enumerator.
  • Constructor Details

    • AbstractEnumerator

      protected AbstractEnumerator(long est, int additionalCharacteristics)
      Creates a spliterator reporting the given estimated size and additionalCharacteristics.
      Parameters:
      est - the estimated size of this spliterator if known, otherwise Long.MAX_VALUE.
      additionalCharacteristics - properties of this spliterator's source or elements. If SIZED is reported then this spliterator will additionally report SUBSIZED.
  • Method Details

    • current

      public E current()
      Gets the element in the collection at the current position of the enumerator.

      Current is undefined under any of the following conditions:

      • The enumerator is positioned before the first element in the collection. Immediately after the enumerator is created BareEnumerator.moveNext() must be called to advance the enumerator to the first element of the collection before reading the value of Current.
      • The last call to BareEnumerator.moveNext() returned false, which indicates the end of the collection.
      • The enumerator is invalidated due to changes made in the collection, such as adding, modifying, or deleting elements.
      Current returns the same object until MoveNext is called.MoveNext sets Current to the next element.
      Specified by:
      current in interface BareEnumerator<E>
      Returns:
      current