com.hazelcast.jet

## Class Traversers

- java.lang.Object
- - com.hazelcast.jet.Traversers

-     public final class Traversers
      extends Object

  Utility class with several `Traverser`s useful in `Processor` implementations.
  Since:
    3.0

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### empty

          @Nonnull
          public static <T> Traverser<T> empty()

      Returns a traverser that always returns `null`.

    - #### singleton

          @Nonnull
          public static <T> Traverser<T> singleton(@Nonnull
                                                            T item)

      Returns a traverser over the given single item.

      You can use `ResettableSingletonTraverser` for less GC litter, if you can reuse the traverser instance.

    - #### traverseIterator

          @Nonnull
          public static <T> Traverser<T> traverseIterator(@Nonnull
                                                                   Iterator<? extends T> iterator)

      Returns an adapter from `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.

    - #### traverseIterator

          @Nonnull
          public static <T> Traverser<T> traverseIterator(@Nonnull
                                                                   Iterator<? extends T> iterator,
                                                                   boolean ignoreNulls)

      Returns an adapter from `Iterator` to `Traverser`. Each time its `next()` method is called, the traverser will take another item from the iterator and return it.
      Parameters:
        `ignoreNulls` - if `true`, null elements form the iterator will be filtered out. If `false`, error will be thrown on null elements.

    - #### traverseSpliterator

          @Nonnull
          public static <T> Traverser<T> traverseSpliterator(@Nonnull
                                                                      Spliterator<T> spliterator)

      Returns an adapter from `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.

    - #### traverseEnumeration

          @Nonnull
          public static <T> Traverser<T> traverseEnumeration(@Nonnull
                                                                      Enumeration<T> enumeration)

      Returns an adapter from `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.

    - #### traverseStream

          @Nonnull
          public static <T> Traverser<T> traverseStream(@Nonnull
                                                                 Stream<T> stream)

      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 contain `null` items.

    - #### traverseIterable

          @Nonnull
          public static <T> Traverser<T> traverseIterable(@Nonnull
                                                                   Iterable<? extends T> iterable)

      Returns a traverser over the given iterable. It obtains the iterator immediately.

    - #### traverseArray

          @Nonnull
          public static <T> Traverser<T> traverseArray(@Nonnull
                                                                T[] array)

      Returns a traverser over the given array. Null elements in the array are skipped.

    - #### traverseItems

          @SafeVarargs
          public static <T> Traverser<T> traverseItems(T... items)

      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

          @Nonnull
          public static <T> Traverser<T> lazy(@Nonnull
                                                       Supplier<Traverser<T>> supplierOfTraverser)

      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 of `get()`.

Copyright © 2019. All rights reserved.