Class Traversers

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

public final class Traversers
extends Object
Utility class with several Traversers useful in Processor implementations.
Since:
3.0
  • Method Details

    • 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().