Package com.hazelcast.jet
Class Traversers
java.lang.Object
com.hazelcast.jet.Traversers
- Since:
- Jet 3.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Traverser<T>
empty()
Returns a traverser that always returnsnull
.static <T> Traverser<T>
Flattens a supplier of traverser into a lazy-initialized traverser.static <T> Traverser<T>
singleton
(T item) Returns a traverser over the given single item.static <T> Traverser<T>
traverseArray
(T[] array) Returns a traverser over the given array.static <T> Traverser<T>
traverseEnumeration
(Enumeration<T> enumeration) Returns an adapter fromEnumeration
toTraverser
.static <T> Traverser<T>
traverseItems
(T... items) Returns a traverser over the supplied arguments (or item array).static <T> Traverser<T>
traverseIterable
(Iterable<? extends T> iterable) Returns a traverser over the given iterable.static <T> Traverser<T>
traverseIterator
(Iterator<? extends T> iterator) Returns an adapter fromIterator
toTraverser
.static <T> Traverser<T>
traverseIterator
(Iterator<? extends T> iterator, boolean ignoreNulls) Returns an adapter fromIterator
toTraverser
.static <T> Traverser<T>
traverseSpliterator
(Spliterator<T> spliterator) Returns an adapter fromSpliterator
toTraverser
.static <T> Traverser<T>
traverseStream
(Stream<T> stream) Returns a traverser over the given stream.
-
Method Details
-
empty
Returns a traverser that always returnsnull
. -
singleton
Returns a traverser over the given single item.You can use
ResettableSingletonTraverser
for less GC litter, if you can reuse the traverser instance. -
traverseIterator
Returns an adapter fromIterator
toTraverser
. The iterator must return non-null
items. Each time itsnext()
method is called, the traverser will take another item from the iterator and return it. -
traverseIterator
@Nonnull public static <T> Traverser<T> traverseIterator(@Nonnull Iterator<? extends T> iterator, boolean ignoreNulls) Returns an adapter fromIterator
toTraverser
. Each time itsnext()
method is called, the traverser will take another item from the iterator and return it.- Parameters:
ignoreNulls
- iftrue
, null elements form the iterator will be filtered out. Iffalse
, error will be thrown on null elements.
-
traverseSpliterator
Returns an adapter fromSpliterator
toTraverser
. Each time itsnext()
method is called, the traverser callsSpliterator.tryAdvance(Consumer)
. If it returnstrue
, the traverser returns the item it emitted to the consumer; otherwise the traverser returnsnull
. The spliterator must not emitnull
items. -
traverseEnumeration
Returns an adapter fromEnumeration
toTraverser
. Each time itsnext()
method is called, the traverser takes another item from the enumeration and returns it. The enumeration must not containnull
items. -
traverseStream
Returns a traverser over the given stream. It will traverse it through its spliterator, which it obtains immediately. When it exhausts the stream, it closes it. The stream must not containnull
items. -
traverseIterable
Returns a traverser over the given iterable. It obtains the iterator immediately. -
traverseArray
Returns a traverser over the given array. Null elements in the array are skipped. -
traverseItems
Returns a traverser over the supplied arguments (or item array). Null items are skipped.- Type Parameters:
T
- type of the items- Parameters:
items
- the items to traverse over
-
lazy
Flattens a supplier of traverser into a lazy-initialized traverser. It obtains the traverser from this method's argument just once, upon the first invocation ofget()
.
-