Class AbstractIteratorDecorator<E>
java.lang.Object
com.globalmentor.collections.iterators.AbstractIteratorDecorator<E>
- Type Parameters:
E
- the type of elements returned by this iterator.
- All Implemented Interfaces:
Enumeration<E>
,Iterator<E>
- Direct Known Subclasses:
IteratorDecorator
,JoinIterator
public abstract class AbstractIteratorDecorator<E>
extends Object
implements Iterator<E>, Enumeration<E>
An abstract base implementation of an iterator that wraps an existing
Iterator
.- Author:
- Garret Wilson
- API Note:
- This iterator also serves as an adapter, converting an iterator to an
Enumeration
. - Implementation Note:
- Subclasses may override
hasNext()
and/ornext()
, andEnumeration
compatibility will be maintained., This implementation specifically does not overrideIterator.forEachRemaining(Consumer)
to delegate to the underlying iterator's version of the method, because subclasses are allowed to change the decorated iterator during iteration. Therefore the default method version is retained, which callshasNext()
andnext()
repeatedly, allowing a subclass to acquire a different underlying iterator if it desires.
-
Constructor Details
-
AbstractIteratorDecorator
public AbstractIteratorDecorator()
-
-
Method Details
-
getIterator
- Returns:
- The iterator this class decorates.
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove() -
hasMoreElements
public final boolean hasMoreElements()- Specified by:
hasMoreElements
in interfaceEnumeration<E>
- Implementation Specification:
- This implementation delegates to
hasNext()
.
-
nextElement
- Specified by:
nextElement
in interfaceEnumeration<E>
- Implementation Specification:
- This implementation delegates to
next()
.
-