Class Streams

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

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

    • toStrictlyIncreasing

      public static <C extends Comparable<? super C>> Function<C,Stream<C>> toStrictlyIncreasing()
      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----|
       
      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
    • toStrictlyDecreasing

      public static <C extends Comparable<? super C>> Function<C,Stream<C>> toStrictlyDecreasing()
      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-------|
       
      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
    • toStrictlyImproving

      public static <T> Function<T,Stream<T>> toStrictlyImproving(Comparator<? super T> comparator)
      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.
      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:
    • toIntervalMax

      public static <C extends Comparable<? super C>> Function<C,Stream<C>> toIntervalMax(int size)
      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

      public static <C extends Comparable<? super C>> Function<C,Stream<C>> toIntervalMin(int size)
      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

      public static <C> Function<C,Stream<C>> toIntervalBest(Comparator<? super C> comparator, int size)
      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:
    • toIntervalMax

      public static <C extends Comparable<? super C>> Function<C,Stream<C>> toIntervalMax(Duration timespan)
      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

      public static <C extends Comparable<? super C>> Function<C,Stream<C>> toIntervalMax(Duration timespan, Clock clock)
      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

      public static <C extends Comparable<? super C>> Function<C,Stream<C>> toIntervalMin(Duration timespan)
      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

      public static <C extends Comparable<? super C>> Function<C,Stream<C>> toIntervalMin(Duration timespan, Clock clock)
      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

      public static <C> Function<C,Stream<C>> toIntervalBest(Comparator<? super C> comparator, Duration timespan)
      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

      public static <C> Function<C,Stream<C>> toIntervalBest(Comparator<? super C> comparator, Duration timespan, Clock clock)
      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