Package uk.ac.ebi.utils.streams
Class StreamUtils
java.lang.Object
uk.ac.ebi.utils.streams.StreamUtils
Stream Utils
- Author:
- brandizi
- Date:
- 25 Jul 2017
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Stream<T>
sampleStream
(Stream<T> stream, double samplingRatio) Returns a sampled stream, i.e., a stream where a quota of elements approximately equals to sampleRatio is returned.static <T> Stream<T>
sampleStream
(Stream<T> stream, long sampleSize, long totalSize) A variant ofsampleStream(Stream, double)
that computes the sampling ratio assampleSize/totalSize
.static <T> Stream<T[]>
tupleStream
(boolean isParallel, Stream<? extends T>... streams) Returns a stream of tuples built from base streams.static <T> Stream<T[]>
tupleStream
(Stream<? extends T>... streams) Defaults to 0 (which impliesSpliterator.IMMUTABLE
only) and false (i.e., non-parallel result stream).
-
Constructor Details
-
StreamUtils
public StreamUtils()
-
-
Method Details
-
tupleStream
Returns a stream of tuples built from base streams. This is done by populating each tuple item with one item from the underlining streams. This is basically a wrapper ofTupleSpliterator
, which is passed toStreamSupport.stream(Spliterator, boolean)
. The built stream usesTupleSpliterator.characteristics()
, which, in turn, are established on the basis of the underlining spliterators (see the method's javadoc).- Parameters:
isParallel
- this is passed toStreamSupport.stream(Spliterator, boolean)
, since the underlining iterator is immutable, creating a parallel stream as result shouldn't be a problem, unless you've some strange things in the base streams.streams
- the base streams from which the result is built.- See Also:
-
unit tests for examples of usage.
-
tupleStream
Defaults to 0 (which impliesSpliterator.IMMUTABLE
only) and false (i.e., non-parallel result stream). -
sampleStream
Returns a sampled stream, i.e., a stream where a quota of elements approximately equals to sampleRatio is returned.
This is obtained by attaching a filter to the initial stream that returns true if
sampleRatio must be between 0 and 1. 0 returns an empty stream, 1 returns the original stream.randomNumber[0,1) < sampleRatio
. -
sampleStream
A variant ofsampleStream(Stream, double)
that computes the sampling ratio assampleSize/totalSize
.- Parameters:
totalSize
- must be >= 0. When 0, you'll end up having an empty stream.sampleSize
- must be < totalSize and >= 0. When 0, you'll end up having an empty stream.
-