java.lang.Object
io.jenetics.util.Streams
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 Summary
Modifier and TypeMethodDescriptiontoIntervalBest
(Comparator<? super C> comparator, int size) Return a new flat-mapper function which returns (emits) the minimal value of the last n elements.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 giventimespan
.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 giventimespan
.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.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 giventimespan
.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 giventimespan
.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.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 giventimespan
.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 giventimespan
.static <C extends Comparable<? super C>>
Function<C,Stream<C>> Return a new flat-mapper function, which guarantees a strictly decreasing stream, from an arbitrarily ordered source stream.toStrictlyImproving
(Comparator<? super T> comparator) Return a new flat-mapper function, which guarantees a strictly improving stream, from an arbitrarily ordered source stream.static <C extends Comparable<? super C>>
Function<C,Stream<C>> Return a new flat-mapper function, which guarantees a strictly increasing stream, from an arbitrarily ordered source stream.
-
Method Details
-
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
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
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
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
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
Return a new flat-mapper function which returns (emits) the minimal value of the last n elements.- Type Parameters:
C
- the element type- Parameters:
size
- the size of the slicecomparator
- the comparator used for testing the elements- Returns:
- a new flat-mapper function
- Throws:
IllegalArgumentException
- if the given size is smaller than oneNullPointerException
- if the givencomparator
isnull
- 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 giventimespan
.+---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 oneNullPointerException
- if the giventimespan
isnull
- 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 giventimespan
.+---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 sliceclock
- theclock
used for measuring thetimespan
- Returns:
- a new flat-mapper function
- Throws:
IllegalArgumentException
- if the given size is smaller than oneNullPointerException
- if one of the arguments isnull
- 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 giventimespan
.+---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 oneNullPointerException
- if the giventimespan
isnull
- 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 giventimespan
.+---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 sliceclock
- theclock
used for measuring thetimespan
- Returns:
- a new flat-mapper function
- Throws:
IllegalArgumentException
- if the given size is smaller than oneNullPointerException
- if one of the arguments isnull
- 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 giventimespan
.- Type Parameters:
C
- the element type- Parameters:
comparator
- the comparator used for testing the elementstimespan
- 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 oneNullPointerException
- if one of the arguments isnull
- 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 giventimespan
.- Type Parameters:
C
- the element type- Parameters:
comparator
- the comparator used for testing the elementstimespan
- the timespan the elements are collected for the calculation sliceclock
- theclock
used for measuring thetimespan
- Returns:
- a new flat-mapper function
- Throws:
IllegalArgumentException
- if the given size is smaller than oneNullPointerException
- if one of the arguments isnull
-