Class Streams

java.lang.Object
io.jenetics.util.Streams

public final class Streams extends Object
This class contains factory methods for (flat) mapping stream element. The functions of this class can be used in the following way.
 final ISeq<Integer> values = new Random().ints(0, 100).boxed()
     .limit(100)
     .gather(Streams.maxOfInterval(13))
     .collect(ISeq.toISeq());
Since:
6.0
Version:
6.0
  • Method Details

    • toStrictlyIncreasing

      @Deprecated(forRemoval=true, since="9.1") public static <C extends Comparable<? super C>> Function<C, Stream<C>> toStrictlyIncreasing()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use the strictlyIncreasing() method instead.
      Return a new flat-mapper function, which guarantees a strictly increasing stream, from an arbitrarily ordered source stream. Note that this function doesn't sort the stream. It just skips the out of order elements.
          +----3--2--5--4--7--7--4--9----|
             toStrictlyIncreasing()
          +----3-----5-----7--------9----|
      
      @SuppressWarnings("removal")
      final ISeq<Integer> values = new Random().ints(0, 100)
          .boxed()
          .limit(100)
          .flatMap(Streams.toStrictlyIncreasing())
          .collect(ISeq.toISeq());
      
      System.out.println(values);
      // [6,47,65,78,96,96,99]
      
      Type Parameters:
      C - the comparable type
      Returns:
      a new flat-mapper function
    • strictlyIncreasing

      public static <C extends Comparable<? super C>> Gatherer<C,?,C> strictlyIncreasing()
      Return a new gatherer, which guarantees a strictly increasing stream, from an arbitrarily ordered source stream. Note that this gatherer doesn't sort the stream. It just skips the out of order elements.
           +----3--2--5--4--7--7--4--9----|
              toStrictlyIncreasing()
           +----3-----5-----7--------9----|
       
       final ISeq<Integer> values = new Random().ints(0, 100)
           .boxed()
           .limit(100)
           .gather(Streams.strictlyIncreasing())
           .collect(ISeq.toISeq());
      
       System.out.println(values);
       // [6,47,65,78,96,96,99]
      
      Type Parameters:
      C - the comparable type
      Returns:
      a new gatherer
    • toStrictlyDecreasing

      @Deprecated(forRemoval=true, since="9.1") public static <C extends Comparable<? super C>> Function<C, Stream<C>> toStrictlyDecreasing()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return a new flat-mapper function, which guarantees a strictly decreasing stream, from an arbitrarily ordered source stream. Note that this function doesn't sort the stream. It just skips the out of order elements.
          +----9--8--9--5--6--6--2--9----|
             toStrictlyDecreasing()
          +----9--8-----5--------2-------|
      
      @SuppressWarnings("removal")
      final ISeq<Integer> values = new Random().ints(0, 100)
          .boxed()
          .limit(100)
          .flatMap(Streams.toStrictlyDecreasing())
          .collect(ISeq.toISeq());
      
      System.out.println(values);
      // [45,32,15,12,3,1]
      
      Type Parameters:
      C - the comparable type
      Returns:
      a new flat-mapper function
    • strictlyDecreasing

      public static <C extends Comparable<? super C>> Gatherer<C,?,C> strictlyDecreasing()
      Return a new gatherer, which guarantees a strictly decreasin stream, from an arbitrarily ordered source stream. Note that this gatherer doesn't sort the stream. It just skips the out of order elements.
          +----9--8--9--5--6--6--2--9----|
             strictlyDecreasing()
          +----9--8-----5--------2-------|
      
      final ISeq<Integer> values = new Random().ints(0, 100)
          .boxed()
          .limit(100)
          .gather(Streams.strictlyDecreasing())
          .collect(ISeq.toISeq());
      
      System.out.println(values);
      // [45,32,15,12,3,1]
      
      Type Parameters:
      C - the comparable type
      Returns:
      a new flat-mapper function
    • toStrictlyImproving

      @Deprecated(forRemoval=true, since="9.1") public static <T> Function<T, Stream<T>> toStrictlyImproving(Comparator<? super T> comparator)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return a new flat-mapper function, which guarantees a strictly improving stream, from an arbitrarily ordered source stream. Note that this function doesn't sort the stream. It just skips the out of order elements.
      @SuppressWarnings("removal")
      final ISeq<Integer> values = new Random().ints(0, 100)
          .boxed()
          .limit(100)
          .flatMap(Streams.toStrictlyImproving(Comparator.naturalOrder()))
          .collect(ISeq.toISeq());
      
      System.out.println(values);
      // [6,47,65,78,96,96,99]
      
      Type Parameters:
      T - the element type
      Parameters:
      comparator - the comparator used for testing the elements
      Returns:
      a new flat-mapper function
      See Also:
    • strictlyImproving

      public static <T> Gatherer<T,?,T> strictlyImproving(Comparator<? super T> comparator)
      Return a new gatherer, which guarantees a strictly improving stream, from an arbitrarily ordered source stream. Note that this gatherer doesn't sort the stream. It just skips the out of order elements.
       final ISeq<Integer> values = new Random().ints(0, 100)
           .boxed()
           .limit(100)
           .gather(Streams.strictlyImproving(Comparator.naturalOrder()))
           .collect(ISeq.toISeq());
      
       System.out.println(values);
       // [6,47,65,78,96,96,99]
      
      Type Parameters:
      T - the element type
      Parameters:
      comparator - the comparator used for testing the elements
      Returns:
      a new gatherer
      Throws:
      NullPointerException - if the given comparator is null
    • toIntervalMax

      @Deprecated(forRemoval=true, since="9.1") public static <C extends Comparable<? super C>> Function<C, Stream<C>> toIntervalMax(int size)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Will be removed. Use maxOfInterval(int) instead.
      Return a new flat-mapper function which returns (emits) the maximal value of the last n elements.
               +----3---+----3---+
               |        |        |
          +----9--8--3--3--5--4--2--9----|
             toIntervalMax(3)
          +----------9--------5----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      size - the size of the slice
      Returns:
      a new flat-mapper function
      Throws:
      IllegalArgumentException - if the given size is smaller than one
    • toIntervalMin

      @Deprecated(forRemoval=true, since="9.1") public static <C extends Comparable<? super C>> Function<C, Stream<C>> toIntervalMin(int size)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Will be removed. Use minOfInterval(int) instead.
      Return a new flat-mapper function which returns (emits) the minimal value of the last n elements.
               +----3---+----3---+
               |        |        |
          +----9--8--3--3--1--4--2--9----|
             toIntervalMin(3)
          +----------3--------1----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      size - the size of the slice
      Returns:
      a new flat-mapper function
      Throws:
      IllegalArgumentException - if the given size is smaller than one
    • toIntervalBest

      @Deprecated(forRemoval=true, since="9.1") public static <C> Function<C, Stream<C>> toIntervalBest(Comparator<? super C> comparator, int size)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Will be removed. Use bestOfInterval(Comparator, int) instead.
      Return a new flat-mapper function which returns (emits) the minimal value of the last n elements.
      Type Parameters:
      C - the element type
      Parameters:
      comparator - the comparator used for testing the elements
      size - the size of the slice
      Returns:
      a new flat-mapper function
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if the given comparator is null
      See Also:
    • maxOfInterval

      public static <C extends Comparable<? super C>> Gatherer<C,?,C> maxOfInterval(int size)
      Return a new gatherer which emits the maximum element of the last n consumed elements. If the stream ends with a final interval smaller than n, the maximum element of this remaining interval is emitted as well.
               +----3---+----3---+
               |        |        |--+
          +----9--8--3--3--5--4--2--9----|
             maxOfInterval(3)
          +----------9--------5-----9----|
      
      Type Parameters:
      C - the element type
      Parameters:
      size - the size of the slice
      Returns:
      a new gatherer
      Throws:
      IllegalArgumentException - if the given size is smaller than one
    • minOfInterval

      public static <C extends Comparable<? super C>> Gatherer<C,?,C> minOfInterval(int size)
      Return a new gatherer which emits the minimum element of the last n consumed elements. If the stream ends with a final interval smaller than n, the minimum element of this remaining interval is emitted as well.
               +----3---+----3---+
               |        |        |--+
          +----9--8--3--3--1--4--2--9----|
             minOfInterval(3)
          +----------3--------1-----2----|
      
      Type Parameters:
      C - the element type
      Parameters:
      size - the size of the slice
      Returns:
      a new gatherer
      Throws:
      IllegalArgumentException - if the given size is smaller than one
    • bestOfInterval

      public static <C> Gatherer<C,?,C> bestOfInterval(Comparator<? super C> comparator, int size)
      Return a new gatherer which emits the best element of the last n consumed elements. If the stream ends with a final interval smaller than n, the best element of this remaining interval is emitted as well.
      Type Parameters:
      C - the element type
      Parameters:
      comparator - the comparator used for testing the elements
      size - the size of the slice
      Returns:
      a new gatherer
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if the given comparator is null
      See Also:
    • toIntervalMax

      @Deprecated(forRemoval=true, since="9.1") public static <C extends Comparable<? super C>> Function<C, Stream<C>> toIntervalMax(Duration timespan)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Will be removed. Use maxOfInterval(Duration) instead.
      Return a new flat-mapper function which returns (emits) the maximal value of the elements emitted within the given timespan.
               +---3s---+---3s---+
               |        |        |
          +----9--8--3--3--5--4--2--9----|
             toIntervalMax(3s)
          +----------9--------5----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      timespan - the timespan the elements are collected for the calculation slice
      Returns:
      a new flat-mapper function
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if the given timespan is null
      See Also:
    • toIntervalMax

      @Deprecated(forRemoval=true, since="9.1") public static <C extends Comparable<? super C>> Function<C, Stream<C>> toIntervalMax(Duration timespan, Clock clock)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Will be removed. Use maxOfInterval(Duration, Clock) instead.
      Return a new flat-mapper function which returns (emits) the maximal value of the elements emitted within the given timespan.
               +---3s---+---3s---+
               |        |        |
          +----9--8--3--3--5--4--2--9----|
             toIntervalMax(3s)
          +----------9--------5----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      timespan - the timespan the elements are collected for the calculation slice
      clock - the clock used for measuring the timespan
      Returns:
      a new flat-mapper function
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if one of the arguments is null
      See Also:
    • toIntervalMin

      @Deprecated(forRemoval=true, since="9.1") public static <C extends Comparable<? super C>> Function<C, Stream<C>> toIntervalMin(Duration timespan)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Will be removed. Use minOfInterval(Duration) instead.
      Return a new flat-mapper function which returns (emits) the minimal value of the elements emitted within the given timespan.
               +---3s---+---3s---+
               |        |        |
          +----9--8--3--3--1--4--2--9----|
             toIntervalMin(3s)
          +----------3--------1----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      timespan - the timespan the elements are collected for the calculation slice
      Returns:
      a new flat-mapper function
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if the given timespan is null
      See Also:
    • toIntervalMin

      @Deprecated(forRemoval=true, since="9.1") public static <C extends Comparable<? super C>> Function<C, Stream<C>> toIntervalMin(Duration timespan, Clock clock)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Will be removed. Use minOfInterval(Duration, Clock) instead.
      Return a new flat-mapper function which returns (emits) the minimal value of the elements emitted within the given timespan.
               +---3s---+---3s---+
               |        |        |
          +----9--8--3--3--1--4--2--9----|
             toIntervalMin(3s)
          +----------3--------1----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      timespan - the timespan the elements are collected for the calculation slice
      clock - the clock used for measuring the timespan
      Returns:
      a new flat-mapper function
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if one of the arguments is null
      See Also:
    • toIntervalBest

      @Deprecated(forRemoval=true, since="9.1") public static <C> Function<C, Stream<C>> toIntervalBest(Comparator<? super C> comparator, Duration timespan)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Will be removed. Use bestOfInterval(Comparator, Duration) instead.
      Return a new flat-mapper function which returns (emits) the minimal value of the elements emitted within the given timespan.
      Type Parameters:
      C - the element type
      Parameters:
      comparator - the comparator used for testing the elements
      timespan - the timespan the elements are collected for the calculation slice
      Returns:
      a new flat-mapper function
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if one of the arguments is null
      See Also:
    • toIntervalBest

      @Deprecated(forRemoval=true, since="9.1") public static <C> Function<C, Stream<C>> toIntervalBest(Comparator<? super C> comparator, Duration timespan, Clock clock)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Will be removed. Use bestOfInterval(Comparator, Duration, Clock) instead.
      Return a new flat-mapper function which returns (emits) the minimal value of the elements emitted within the given timespan.
      Type Parameters:
      C - the element type
      Parameters:
      comparator - the comparator used for testing the elements
      timespan - the timespan the elements are collected for the calculation slice
      clock - the clock used for measuring the timespan
      Returns:
      a new flat-mapper function
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if one of the arguments is null
    • maxOfInterval

      public static <C extends Comparable<? super C>> Gatherer<C,?,C> maxOfInterval(Duration timespan)
      Return a new gatherer which emits the maximal element consumed within the given timespan.
               +---3s---+---3s---+
               |        |        |
          +----9--8--3--3--5--4--2--9----|
             maxOfInterval(3s)
          +----------9--------5----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      timespan - the timespan the elements are collected for the calculation slice
      Returns:
      a new gatherer
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if the given timespan is null
      See Also:
    • maxOfInterval

      public static <C extends Comparable<? super C>> Gatherer<C,?,C> maxOfInterval(Duration timespan, Clock clock)
      Return a new gatherer which emits the maximal element consumed within the given timespan.
               +---3s---+---3s---+
               |        |        |
          +----9--8--3--3--5--4--2--9----|
             maxOfInterval(3s)
          +----------9--------5----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      timespan - the timespan the elements are collected for the calculation slice
      clock - the clock used for measuring the timespan
      Returns:
      a new gatherer
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if one of the arguments is null
      See Also:
    • minOfInterval

      public static <C extends Comparable<? super C>> Gatherer<C,?,C> minOfInterval(Duration timespan)
      Return a new gatherer which emits the minimal element consumed within the given timespan.
               +---3s---+---3s---+
               |        |        |
          +----9--8--3--3--1--4--2--9----|
             minOfInterval(3s)
          +----------3--------1----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      timespan - the timespan the elements are collected for the calculation slice
      Returns:
      a new gatherer
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if the given timespan is null
      See Also:
    • minOfInterval

      public static <C extends Comparable<? super C>> Gatherer<C,?,C> minOfInterval(Duration timespan, Clock clock)
      Return a new gatherer which emits the minimal element consumed within the given timespan.
               +---3s---+---3s---+
               |        |        |
          +----9--8--3--3--1--4--2--9----|
             minOfInterval(3s)
          +----------3--------1----------|
      
      Type Parameters:
      C - the element type
      Parameters:
      timespan - the timespan the elements are collected for the calculation slice
      clock - the clock used for measuring the timespan
      Returns:
      a new gatherer
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if one of the arguments is null
      See Also:
    • bestOfInterval

      public static <C> Gatherer<C,?,C> bestOfInterval(Comparator<? super C> comparator, Duration timespan)
      Return a new gatherer which emits the best element consumed within the given timespan.
      Type Parameters:
      C - the element type
      Parameters:
      comparator - the comparator used for testing the elements
      timespan - the timespan the elements are collected for the calculation slice
      Returns:
      a new gatherer
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if one of the arguments is null
      See Also:
    • bestOfInterval

      public static <C> Gatherer<C,?,C> bestOfInterval(Comparator<? super C> comparator, Duration timespan, Clock clock)
      Return a new gatherer which emits the best element consumed within the given timespan.
      Type Parameters:
      C - the element type
      Parameters:
      comparator - the comparator used for testing the elements
      timespan - the timespan the elements are collected for the calculation slice
      clock - the clock used for measuring the timespan
      Returns:
      a new gatherer
      Throws:
      IllegalArgumentException - if the given size is smaller than one
      NullPointerException - if one of the arguments is null