Package com.gengoai.stream
Interface MDoubleStream
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
LocalMDoubleStream
public interface MDoubleStream extends AutoCloseable
A facade for double stream classes, such as Java's
DoubleStream
and Spark'sDoubleRDD
objects. Provides a common interface to working with an manipulating streams regardless of their backend implementation.- Author:
- David B. Bracewell
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
allMatch(SerializableDoublePredicate predicate)
Determines if all doubles in the stream evaluate to true with the given predicateboolean
anyMatch(SerializableDoublePredicate predicate)
Determines if any of the doubles in the stream evaluate to true with the given predicateMDoubleStream
cache()
Caches the stream.long
count()
The number of items in the streamMDoubleStream
distinct()
Removes duplicates from the streamMDoubleStream
filter(SerializableDoublePredicate predicate)
Filters the stream.OptionalDouble
first()
Gets the first item in the streamMDoubleStream
flatMap(SerializableDoubleFunction<double[]> mapper)
Maps the doubles in this stream to one or more new doubles using the given function.void
forEach(SerializableDoubleConsumer consumer)
Performs an operation on each item in the streamStreamingContext
getContext()
Gets the context used to create the streamboolean
isDistributed()
boolean
isEmpty()
Determines if the stream is empty or notPrimitiveIterator.OfDouble
iterator()
Gets an iterator for the streamMDoubleStream
limit(int n)
Limits the stream to the firstnumber
items.MDoubleStream
map(SerializableDoubleUnaryOperator mapper)
Maps the doubles in the stream using the given function<T> MStream<T>
mapToObj(SerializableDoubleFunction<? extends T> function)
Maps the doubles in the stream to objects using the given functionOptionalDouble
max()
Returns the max item in the stream.double
mean()
The mean value of the streamOptionalDouble
min()
Returns the min item in the stream.boolean
noneMatch(SerializableDoublePredicate predicate)
Determines if none of the doubles in the stream evaluate to true with the given predicateMDoubleStream
onClose(SerializableRunnable onCloseHandler)
Sets the handler to call when the stream is closed.MDoubleStream
parallel()
Ensures that the stream is parallel or distributed.double
reduce(double zeroValue, SerializableDoubleBinaryOperator operator)
Performs a reduction on the elements of this stream using the given binary operator.OptionalDouble
reduce(SerializableDoubleBinaryOperator operator)
Performs a reduction on the elements of this stream using the given binary operator.MDoubleStream
repartition(int numberOfPartition)
Repartitions the stream to the given number of partitions.MDoubleStream
skip(int n)
Skips the firstn
items in the streamMDoubleStream
sorted(boolean ascending)
Sorts the double stream in ascending order.EnhancedDoubleStatistics
statistics()
Calculates a number of useful statistics over the elements in the streamdouble
stddev()
Calculates the standard deviation of the streamdouble
sum()
Calculates the sum of the streamdouble[]
toArray()
Collects the values of the stream as a double array.MDoubleStream
union(MDoubleStream other)
Unions this stream with anotherdefault void
updateConfig()
Updates the config instance used for this String-
Methods inherited from interface java.lang.AutoCloseable
close
-
-
-
-
Method Detail
-
allMatch
boolean allMatch(SerializableDoublePredicate predicate)
Determines if all doubles in the stream evaluate to true with the given predicate- Parameters:
predicate
- the predicate to test double entries with- Returns:
- True if all elements in the stream evaluate to true
-
anyMatch
boolean anyMatch(SerializableDoublePredicate predicate)
Determines if any of the doubles in the stream evaluate to true with the given predicate- Parameters:
predicate
- the predicate to test double entries with- Returns:
- True if any of the elements in the stream evaluate to true
-
cache
MDoubleStream cache()
Caches the stream.- Returns:
- the cached stream
-
count
long count()
The number of items in the stream- Returns:
- the number of items in the stream
-
distinct
MDoubleStream distinct()
Removes duplicates from the stream- Returns:
- the new stream without duplicates
-
filter
MDoubleStream filter(SerializableDoublePredicate predicate)
Filters the stream.- Parameters:
predicate
- the predicate to use to determine which objects are kept- Returns:
- the new stream
-
first
OptionalDouble first()
Gets the first item in the stream- Returns:
- the optional containing the first item
-
flatMap
MDoubleStream flatMap(SerializableDoubleFunction<double[]> mapper)
Maps the doubles in this stream to one or more new doubles using the given function.- Parameters:
mapper
- the function to use to map objects- Returns:
- the new stream
-
forEach
void forEach(SerializableDoubleConsumer consumer)
Performs an operation on each item in the stream- Parameters:
consumer
- the consumer action to perform
-
getContext
StreamingContext getContext()
Gets the context used to create the stream- Returns:
- the context
-
isEmpty
boolean isEmpty()
Determines if the stream is empty or not- Returns:
- True if empty, False otherwise
-
iterator
PrimitiveIterator.OfDouble iterator()
Gets an iterator for the stream- Returns:
- the iterator of items in the stream
-
limit
MDoubleStream limit(int n)
Limits the stream to the firstnumber
items.- Parameters:
n
- the number of items desired- Returns:
- the new stream of size
number
-
map
MDoubleStream map(SerializableDoubleUnaryOperator mapper)
Maps the doubles in the stream using the given function- Parameters:
mapper
- the function to use to map doubles- Returns:
- the new stream
-
mapToObj
<T> MStream<T> mapToObj(SerializableDoubleFunction<? extends T> function)
Maps the doubles in the stream to objects using the given function- Type Parameters:
T
- the component type of the returning stream- Parameters:
function
- the function to use to map doubles- Returns:
- the new stream
-
max
OptionalDouble max()
Returns the max item in the stream.- Returns:
- the optional containing the max value
-
mean
double mean()
The mean value of the stream- Returns:
- the mean value
-
min
OptionalDouble min()
Returns the min item in the stream.- Returns:
- the optional containing the min value
-
noneMatch
boolean noneMatch(SerializableDoublePredicate predicate)
Determines if none of the doubles in the stream evaluate to true with the given predicate- Parameters:
predicate
- the predicate to test double entries with- Returns:
- True if none of the elements in the stream evaluate to true
-
onClose
MDoubleStream onClose(SerializableRunnable onCloseHandler)
Sets the handler to call when the stream is closed. Typically, this is to clean up any open resources, such as file handles.- Parameters:
onCloseHandler
- the handler to run when the stream is closed.
-
isDistributed
boolean isDistributed()
-
parallel
MDoubleStream parallel()
Ensures that the stream is parallel or distributed.- Returns:
- the new stream
-
reduce
OptionalDouble reduce(SerializableDoubleBinaryOperator operator)
Performs a reduction on the elements of this stream using the given binary operator.- Parameters:
operator
- the binary operator used to combine two objects- Returns:
- the optional describing the reduction
-
reduce
double reduce(double zeroValue, SerializableDoubleBinaryOperator operator)
Performs a reduction on the elements of this stream using the given binary operator.- Parameters:
zeroValue
- the starting value for the reductionoperator
- the binary operator used to combine two objects- Returns:
- the optional describing the reduction
-
repartition
MDoubleStream repartition(int numberOfPartition)
Repartitions the stream to the given number of partitions. This may be a no-op for some streams, i.e. Local Streams.- Parameters:
numberOfPartition
- the number of partitions the stream should have- Returns:
- the new stream
-
skip
MDoubleStream skip(int n)
Skips the firstn
items in the stream- Parameters:
n
- the number of items in the stream- Returns:
- the new stream
-
sorted
MDoubleStream sorted(boolean ascending)
Sorts the double stream in ascending order.- Parameters:
ascending
- determines if the items should be sorted in ascending (true) or descending (false) order- Returns:
- the new double stream
-
statistics
EnhancedDoubleStatistics statistics()
Calculates a number of useful statistics over the elements in the stream- Returns:
- the statistics
-
stddev
double stddev()
Calculates the standard deviation of the stream- Returns:
- the standard deviation
-
sum
double sum()
Calculates the sum of the stream- Returns:
- the sum
-
toArray
double[] toArray()
Collects the values of the stream as a double array.- Returns:
- the double array
-
union
MDoubleStream union(MDoubleStream other)
Unions this stream with another- Parameters:
other
- the other stream to append to this one- Returns:
- the new double stream
-
updateConfig
default void updateConfig()
Updates the config instance used for this String
-
-