- Type Parameters:
E- The element type.
- All Superinterfaces:
Iterator<E>
- All Known Subinterfaces:
SmartIterator.Detachable<E>,StringSplitter.Async.Iterator,StringSplitter.Iterator
- All Known Implementing Classes:
SmartIterator.ListIterator,SmartIterator.Wrapper
An iterator with extra capabilities. Note that it does not support
null elements, and is not thread-safe by default.- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSmartIterator.Detachable<E extends @NonNull Object>A smart iterator that, when creating other iterators/streams/fluxes/etc from its current state, makes them detached, so that they are independent of the future state of the original iterator and vice-versa.static classSmartIterator.ListIterator<E extends @NonNull Object>A smart iterator that iterates over a list.static classSmartIterator.Wrapper<E extends @NonNull Object>A smart iterator that wraps an existing iterator. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringException message for when there are no more elements. -
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends @NonNull Object>
SmartIterator.Detachable<E>empty()Returns an empty iterator.static <E extends @NonNull Object>
SmartIterator<E>Creates a smart iterator backed by the given iterator.static <E extends @NonNull Object>
SmartIterator.Detachable<E>Creates a smart iterator that iterates over the contents of the given list.default booleanhasNext()peek()Retrives the element that will be returned by the next call toIterator.next(), without advancing the iterator.toFlux()Returns a flux that issues the remaining elements to be traversed by this iterator.default Spliterator<E>Returns a spliterator that iterates over the remaining elements to be traversed by this iterator.toStream()Returns a stream that contains the remaining elements to be traversed by this iterator.Methods inherited from interface java.util.Iterator
forEachRemaining, next, remove
-
Field Details
-
NO_MORE_ELEMENTS_ERROR
Exception message for when there are no more elements.- See Also:
-
-
Method Details
-
empty
Returns an empty iterator.- Type Parameters:
E- The element type.- Returns:
- An empty iterator.
-
peek
Retrives the element that will be returned by the next call toIterator.next(), without advancing the iterator.- Returns:
- The next element, or
nullif there are no elements remaining.
-
toSpliterator
Returns a spliterator that iterates over the remaining elements to be traversed by this iterator.Note that this interface makes no promises as to whether it is safe to continue using this iterator while using the returned spliterator; it is left as an implementation detail.
- Returns:
- The spliterator.
- Implementation Requirements:
- The default implementation creates a spliterator backed by this iterator; as such, their state is interdependent, and continuing to use this iterator results in undefined behavior.
-
toStream
Returns a stream that contains the remaining elements to be traversed by this iterator.Note that this interface makes no promises as to whether it is safe to continue using this iterator while using the returned stream; it is left as an implementation detail.
- Returns:
- The stream.
- Implementation Requirements:
- The default implementation creates a stream backed by this iterator; as such, their state is interdependent, and continuing to use this iterator results in undefined behavior.
-
toFlux
Returns a flux that issues the remaining elements to be traversed by this iterator.Note that this interface makes no promises as to whether it is safe to continue using this iterator while using the returned flux; it is left as an implementation detail.
- Returns:
- The flux.
- Implementation Requirements:
- The default implementation creates a stream backed by this iterator; as such, their state is interdependent, and continuing to use this iterator results in undefined behavior.
-
hasNext
-
from
Creates a smart iterator backed by the given iterator.- Type Parameters:
E- The element type.- Parameters:
backing- The backing iterator.- Returns:
- The smart iterator.
-
from
Creates a smart iterator that iterates over the contents of the given list.- Type Parameters:
E- The element type.- Parameters:
list- The list to iterate over.- Returns:
- The smart iterator.
-