Interface DataStream<V>
- Type Parameters:
V
- the type of each value
- All Superinterfaces:
Displayable
,Formattable<V>
,Iterable<V>
- All Known Implementing Classes:
ImmutableDataStream
,Samples
A stream of values.
-
Method Summary
Modifier and TypeMethodDescriptiondefault V
any()
Returns any value from this stream.default TabularData<V>
Returns the contents of this object as aTabularData
instance, which can be used to save, print, or format the data in various ways.default DataStream<V>
distinct()
Retains only the unique values in this stream.static <V> DataStream<V>
enumerate
(int count, IntFunction<V> function) Similar torepeat(int, Supplier)
except the index from[0, ..., count-1]
is passed as an argument to the function.default void
enumerate
(BiConsumer<Integer, V> consumer) Similar toIterable.forEach(Consumer)
except the index is included.default DataStream<V>
Filters this stream, keeping only those values evaluating totrue
.default V
first()
Returns the first value from this stream.Applies a grouping function to the values in this data stream.default boolean
isEmpty()
Returnstrue
if this data stream is empty.Converts this data stream into aPartition
by assigning a key to each value.Applies a function to each value in the stream, returning a partition of the results.default <R> R
Applies a measurement function to this stream.static <V> DataStream<V>
of()
Creates an empty data stream.static <V> DataStream<V>
Creates a data stream with the contents of anIterable
.static DataStream<Double>
of
(DoubleStream stream) Creates a data stream with the contents of aDoubleStream
.static DataStream<Integer>
Creates a data stream with the contents of aIntStream
.static <V> DataStream<V>
Creates a data stream with the contents of aStream
.static <V> DataStream<V>
of
(V[] array) Creates a data stream with the contents of an array.static DataStream<Integer>
range
(int count) Constructs a data stream containing the integer values[0, ..., count-1]
.static DataStream<Integer>
range
(int startInclusive, int endExclusive) Constructs a data stream containing the integer values between the given start (inclusive) and end (exclusive).default V
reduce
(BinaryOperator<V> op) Applies a binary reduction operator to the values in this stream.default V
reduce
(V identity, BinaryOperator<V> op) Applies a binary reduction operator to the values in this stream.static <V> DataStream<V>
Constructs a data stream generated by invoking aSupplier
a fixed number of times.default V
single()
Asserts this stream contains exactly one value, returning said value.default V
singleOrDefault
(V defaultValue) Returns the singular value contained in this stream, or if empty, returns the given default value.int
size()
Returns the number of values in this data stream.default DataStream<V>
skip
(int n) Skips the firstn
values in the stream.default DataStream<V>
sorted()
Sorts the stream using the natural ordering of values.default DataStream<V>
sorted
(Comparator<V> comparator) Sorts the stream.stream()
Returns aStream
of the values in this data stream.values()
Returns the values in this stream as a list.default V[]
values
(IntFunction<V[]> generator) Returns the values in this stream as an array.Methods inherited from interface org.moeaframework.util.format.Displayable
display
Methods inherited from interface org.moeaframework.util.format.Formattable
display, display, display, save, save, save
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
size
int size()Returns the number of values in this data stream.- Returns:
- the number of values
-
stream
Returns aStream
of the values in this data stream.- Returns:
- the stream
-
isEmpty
default boolean isEmpty()Returnstrue
if this data stream is empty.- Returns:
true
if this data stream is empty;false
otherwise
-
values
Returns the values in this stream as a list.- Returns:
- the list of values
-
values
Returns the values in this stream as an array.- Parameters:
generator
- generator for creating the array- Returns:
- the array of values
-
map
Applies a function to each value in the stream, returning a partition of the results.- Type Parameters:
R
- the result type- Parameters:
map
- the mapping function- Returns:
- the partition of results
-
sorted
Sorts the stream using the natural ordering of values.- Returns:
- the sorted stream
- Throws:
ClassCastException
- if the value type is notComparable
-
sorted
Sorts the stream.- Parameters:
comparator
- the comparator used to sort values- Returns:
- the sorted stream
-
first
Returns the first value from this stream.- Returns:
- the selected value
- Throws:
NoSuchElementException
- if the stream is empty
-
any
Returns any value from this stream.- Returns:
- the selected value
- Throws:
NoSuchElementException
- if the stream is empty
-
singleOrDefault
Returns the singular value contained in this stream, or if empty, returns the given default value.- Parameters:
defaultValue
- the default value- Returns:
- the single value or default value
-
single
Asserts this stream contains exactly one value, returning said value.- Returns:
- the value
- Throws:
NoSuchElementException
- if the stream was empty or contained more than one value
-
skip
Skips the firstn
values in the stream.- Parameters:
n
- the number of values to skip- Returns:
- the resulting data stream
-
filter
Filters this stream, keeping only those values evaluating totrue
.- Parameters:
predicate
- the predicate function- Returns:
- the resulting data stream
-
groupBy
Applies a grouping function to the values in this data stream. Values with the same grouping key are grouped together.- Type Parameters:
K
- the type of the grouping key- Parameters:
group
- the grouping function- Returns:
- the resulting groups
-
keyedOn
Converts this data stream into aPartition
by assigning a key to each value.- Type Parameters:
K
- the type of the key- Parameters:
key
- the function mapping values to their key- Returns:
- the partition
-
reduce
Applies a binary reduction operator to the values in this stream. SeeStream.reduce(BinaryOperator)
for more details.- Parameters:
op
- the binary reduction operator- Returns:
- the final result from the reduction operator
- Throws:
NoSuchElementException
- if the stream is empty
-
reduce
Applies a binary reduction operator to the values in this stream. SeeStream.reduce(Object, BinaryOperator)
for more details.- Parameters:
identity
- the initial value supplied to the binary operatorop
- the binary reduction operator- Returns:
- the final result from the reduction operator
-
distinct
Retains only the unique values in this stream.- Returns:
- the resulting data stream
-
measure
Applies a measurement function to this stream.- Type Parameters:
R
- the return value- Parameters:
measure
- the measurement function- Returns:
- the measured value
-
enumerate
Similar toIterable.forEach(Consumer)
except the index is included.- Parameters:
consumer
- the method to invoke
-
asTabularData
Description copied from interface:Formattable
Returns the contents of this object as aTabularData
instance, which can be used to save, print, or format the data in various ways.- Specified by:
asTabularData
in interfaceFormattable<V>
- Returns:
- the
TabularData
instance
-
of
Creates an empty data stream.- Type Parameters:
V
- the type of the stream- Returns:
- the constructed data stream
-
of
Creates a data stream with the contents of aStream
.- Type Parameters:
V
- the type of the stream- Parameters:
stream
- the source stream- Returns:
- the constructed data stream
-
of
Creates a data stream with the contents of aIntStream
.- Parameters:
stream
- the source stream- Returns:
- the constructed data stream
-
of
Creates a data stream with the contents of aDoubleStream
.- Parameters:
stream
- the source stream- Returns:
- the constructed data stream
-
of
Creates a data stream with the contents of anIterable
.- Type Parameters:
V
- the type of the iterable- Parameters:
iterable
- the iterable- Returns:
- the constructed data stream
-
of
Creates a data stream with the contents of an array.- Type Parameters:
V
- the type of the array- Parameters:
array
- the array- Returns:
- the constructed data stream
-
range
Constructs a data stream containing the integer values[0, ..., count-1]
.- Parameters:
count
- the size of the returned stream- Returns:
- the constructed data stream
-
range
Constructs a data stream containing the integer values between the given start (inclusive) and end (exclusive).- Parameters:
startInclusive
- the starting valueendExclusive
- the ending value (exclusive)- Returns:
- the constructed data stream
-
repeat
Constructs a data stream generated by invoking aSupplier
a fixed number of times.- Type Parameters:
V
- the type returned by the supplier- Parameters:
count
- the number of invocations of the suppliersupplier
- the supplier- Returns:
- the constructed data stream
-
enumerate
Similar torepeat(int, Supplier)
except the index from[0, ..., count-1]
is passed as an argument to the function.- Type Parameters:
V
- the type returned by the function- Parameters:
count
- the number of invocations of the functionfunction
- the function taking the index as the first argument- Returns:
- the constructed data stream
-