Package com.complexible.common.base

# Class Streams

java.lang.Object
com.complexible.common.base.Streams

public final class Streams extends Object

Utility for streams

Since:
  4.0
Version:
  4.0
Author:
  Michael Grove

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `Streams.CheckedBiConsumer<U,T>`
  `static interface`
  `Streams.CheckedBiFunction<In1,In2,Out>`
  `static interface`
  `Streams.CheckedConsumer<T>`
  `static interface`
  `Streams.CheckedFunction<In,Out>`
  `static interface`
  `Streams.CheckedPredicate<T>`
  `static interface`
  `Streams.CheckedRunnable`
  `static interface`
  `Streams.CheckedSupplier<Out>`
  `static final class`
  `Streams.UncheckedException`
  Exception indicating that Checked* threw an exception and the default handler was used

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final boolean`
  `NOT_PARALLEL`
  `static final boolean`
  `PARALLEL`
  `static final long`
  `UNKNOWN_SIZE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Streams()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <Input, Output>
  Output`
  `applyTerminalAndClose(Stream<Input> theStream, Function<Stream<Input>,Output> theFinisher)`
  Apply the given terminal operation to the stream returning the result and close the stream.
  `static <T> Stream<T>`
  `concat(Stream<T> theStream, Stream<T> theOtherStream, Stream<T>... theMoreStreams)`
  `static <T> Predicate<? super T>`
  `distinctByKey(Function<? super T,Object> theKey)`
  A simple stateful predicate for filtering out stream elements which agree on their key values.
  `static <K, V> Collector<Map.Entry<K,V>,?,HashMap<K,V>>`
  `entriesToMap()`
  `static <T> CloseableIterator<T>`
  `flatIterator(Stream<Stream<T>> theStream)`
  `static <T> Stream<T>`
  `flatten(Stream<Stream<T>> theStream)`
  `static <T, E extends Throwable>
  void`
  `forEachChecked(Stream<T> theStream, Streams.CheckedConsumer<T> theConsumer)`
  `static <T> Function<Optional<T>,Stream<T>>`
  `optional()`
  Returns a function that will collapse a `Stream` of `optionals` into a `Stream` of the references they hold.
  `static <T> Stream<T>`
  `stream(Iterable<T> theIterable)`
  Return a new `Stream` from the given `Iterable`
  `static <T> Stream<T>`
  `stream(Iterator<? extends T> theIter)`
  `static <T> Stream<T>`
  `stream(Iterator<? extends T> theIter, long theSize)`
  `static <In1, In2, Out>
  BiFunction<In1,In2,Out>`
  `unchecked(Streams.CheckedBiFunction<In1,In2,Out> theBiFunction)`
  `static <In1, In2, Out>
  BiFunction<In1,In2,Out>`
  `unchecked(Streams.CheckedBiFunction<In1,In2,Out> theBiFunction, Consumer<Throwable> theHandler)`
  `static <In, Out> Function<In,Out>`
  `unchecked(Streams.CheckedFunction<In,Out> theFunction)`
  `static <In, Out> Function<In,Out>`
  `unchecked(Streams.CheckedFunction<In,Out> theFunction, Consumer<Throwable> theHandler)`
  `static <U, T> BiConsumer<U,T>`
  `uncheckedConsumer(Streams.CheckedBiConsumer<U,T> theConsumer)`
  `static <U, T> BiConsumer<U,T>`
  `uncheckedConsumer(Streams.CheckedBiConsumer<U,T> theConsumer, Consumer<Throwable> theHandler)`
  `static <T> Consumer<T>`
  `uncheckedConsumer(Streams.CheckedConsumer<T> theConsumer)`
  `static <T> Consumer<T>`
  `uncheckedConsumer(Streams.CheckedConsumer<T> theConsumer, Consumer<Throwable> theHandler)`
  `static <In> Predicate<In>`
  `uncheckedPredicate(Streams.CheckedPredicate<In> thePredicate)`
  `static <In> Predicate<In>`
  `uncheckedPredicate(Streams.CheckedPredicate<In> thePredicate, Consumer<Throwable> theHandler)`

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

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

- ## Field Details

  - ### NOT_PARALLEL

    public static final boolean NOT_PARALLEL
    See Also:
      - Constant Field Values

  - ### PARALLEL

    public static final boolean PARALLEL
    See Also:
      - Constant Field Values

  - ### UNKNOWN_SIZE

    public static final long UNKNOWN_SIZE
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### Streams

    public Streams()

- ## Method Details

  - ### optional

    public static <T> Function<Optional<T>,Stream<T>> optional()
    Returns a function that will collapse a `Stream` of `optionals` into a `Stream` of the references they hold. To be used with `Stream.flatMap(Function)`.
    Type Parameters:
      `T` - the optional's type
    Returns:
      a Function which unrolls optionals

  - ### stream

    public static <T> Stream<T> stream(Iterable<T> theIterable)
    Return a new `Stream` from the given `Iterable`
    Parameters:
      `theIterable` - the iterable
    Returns:
      a stream over the iterable

  - ### stream

    public static <T> Stream<T> stream(Iterator<? extends T> theIter)

  - ### stream

    public static <T> Stream<T> stream(Iterator<? extends T> theIter, long theSize)

  - ### concat

    @SafeVarargs public static <T> Stream<T> concat(Stream<T> theStream, Stream<T> theOtherStream, Stream<T>... theMoreStreams)

  - ### applyTerminalAndClose

    public static <Input, Output> Output applyTerminalAndClose(Stream<Input> theStream, Function<Stream<Input>,Output> theFinisher)
    Apply the given terminal operation to the stream returning the result and close the stream.
    Parameters:
      `theStream` - the stream
      `theFinisher` - the function which will apply the terminal operation and return the result
    Returns:
      the result of the terminal operation.

  - ### forEachChecked

    public static <T, E extends Throwable> void forEachChecked(Stream<T> theStream, Streams.CheckedConsumer<T> theConsumer) throws E
    Throws:
      `E`

  - ### unchecked

    public static <In, Out> Function<In,Out> unchecked(Streams.CheckedFunction<In,Out> theFunction)

  - ### unchecked

    public static <In, Out> Function<In,Out> unchecked(Streams.CheckedFunction<In,Out> theFunction, Consumer<Throwable> theHandler)

  - ### unchecked

    public static <In1, In2, Out> BiFunction<In1,In2,Out> unchecked(Streams.CheckedBiFunction<In1,In2,Out> theBiFunction)

  - ### unchecked

    public static <In1, In2, Out> BiFunction<In1,In2,Out> unchecked(Streams.CheckedBiFunction<In1,In2,Out> theBiFunction, Consumer<Throwable> theHandler)

  - ### uncheckedPredicate

    public static <In> Predicate<In> uncheckedPredicate(Streams.CheckedPredicate<In> thePredicate)

  - ### uncheckedPredicate

    public static <In> Predicate<In> uncheckedPredicate(Streams.CheckedPredicate<In> thePredicate, Consumer<Throwable> theHandler)

  - ### uncheckedConsumer

    public static <T> Consumer<T> uncheckedConsumer(Streams.CheckedConsumer<T> theConsumer)

  - ### uncheckedConsumer

    public static <U, T> BiConsumer<U,T> uncheckedConsumer(Streams.CheckedBiConsumer<U,T> theConsumer)

  - ### uncheckedConsumer

    public static <U, T> BiConsumer<U,T> uncheckedConsumer(Streams.CheckedBiConsumer<U,T> theConsumer, Consumer<Throwable> theHandler)

  - ### uncheckedConsumer

    public static <T> Consumer<T> uncheckedConsumer(Streams.CheckedConsumer<T> theConsumer, Consumer<Throwable> theHandler)

  - ### flatIterator

    public static <T> CloseableIterator<T> flatIterator(Stream<Stream<T>> theStream)

  - ### flatten

    public static <T> Stream<T> flatten(Stream<Stream<T>> theStream)

  - ### distinctByKey

    public static <T> Predicate<? super T> distinctByKey(Function<? super T,Object> theKey)
    A simple stateful predicate for filtering out stream elements which agree on their key values. TODO let the outer code create more optimized distinct filters e.g. for value types.

  - ### entriesToMap

    public static <K, V> Collector<Map.Entry<K,V>,?,HashMap<K,V>> entriesToMap()