public final class Traversers extends Object
Modifier and Type | Method and Description |
---|---|
static <T> Traverser<T> |
empty()
Returns a traverser that always returns
null . |
static <T> Traverser<T> |
lazy(Supplier<Traverser<T>> supplierOfTraverser)
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 from
Enumeration to Traverser . |
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 from
Iterator to Traverser . |
static <T> Traverser<T> |
traverseIterator(Iterator<? extends T> iterator,
boolean ignoreNulls)
Returns an adapter from
Iterator to Traverser . |
static <T> Traverser<T> |
traverseSpliterator(Spliterator<T> spliterator)
Returns an adapter from
Spliterator to Traverser . |
static <T> Traverser<T> |
traverseStream(Stream<T> stream)
Returns a traverser over the given stream.
|
@Nonnull public static <T> Traverser<T> singleton(@Nonnull T item)
You can use ResettableSingletonTraverser
for less GC litter,
if you can reuse the traverser instance.
@Nonnull public static <T> Traverser<T> traverseIterator(@Nonnull Iterator<? extends T> iterator)
Iterator
to Traverser
. The
iterator must return non-null
items. Each time its next()
method is called, the traverser will take another item from the iterator
and return it.@Nonnull public static <T> Traverser<T> traverseIterator(@Nonnull Iterator<? extends T> iterator, boolean ignoreNulls)
Iterator
to Traverser
. Each time
its next()
method is called, the traverser will take another
item from the iterator and return it.ignoreNulls
- if true
, null elements form the iterator will be
filtered out. If false
, error will be thrown on null elements.@Nonnull public static <T> Traverser<T> traverseSpliterator(@Nonnull Spliterator<T> spliterator)
Spliterator
to Traverser
. Each
time its next()
method is called, the traverser calls Spliterator.tryAdvance(Consumer)
. If it returns true
, the
traverser returns the item it emitted to the consumer; otherwise the
traverser returns null
. The spliterator must not emit null
items.@Nonnull public static <T> Traverser<T> traverseEnumeration(@Nonnull Enumeration<T> enumeration)
Enumeration
to Traverser
. Each
time its next()
method is called, the traverser takes another
item from the enumeration and returns it. The enumeration must not
contain null
items.@Nonnull public static <T> Traverser<T> traverseStream(@Nonnull Stream<T> stream)
null
items.@Nonnull public static <T> Traverser<T> traverseIterable(@Nonnull Iterable<? extends T> iterable)
@Nonnull public static <T> Traverser<T> traverseArray(@Nonnull T[] array)
@SafeVarargs public static <T> Traverser<T> traverseItems(T... items)
T
- type of the itemsitems
- the items to traverse overCopyright © 2022 Hazelcast, Inc.. All rights reserved.