Package com.gengoai.stream.local
Class LocalMDoubleStream
- java.lang.Object
-
- com.gengoai.stream.local.LocalMDoubleStream
-
- All Implemented Interfaces:
MDoubleStream
,Serializable
,AutoCloseable
public class LocalMDoubleStream extends Object implements MDoubleStream, Serializable
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LocalMDoubleStream(@NonNull DoubleStream stream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allMatch(@NonNull SerializableDoublePredicate predicate)
Determines if all doubles in the stream evaluate to true with the given predicateboolean
anyMatch(@NonNull SerializableDoublePredicate predicate)
Determines if any of the doubles in the stream evaluate to true with the given predicateMDoubleStream
cache()
Caches the stream.void
close()
long
count()
The number of items in the streamMDoubleStream
distinct()
Removes duplicates from the streamMDoubleStream
filter(@NonNull SerializableDoublePredicate predicate)
Filters the stream.OptionalDouble
first()
Gets the first item in the streamMDoubleStream
flatMap(@NonNull SerializableDoubleFunction<double[]> mapper)
Maps the doubles in this stream to one or more new doubles using the given function.void
forEach(@NonNull 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(@NonNull SerializableDoubleUnaryOperator mapper)
Maps the doubles in the stream using the given function<T> MStream<T>
mapToObj(@NonNull 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(@NonNull SerializableDoublePredicate predicate)
Determines if none of the doubles in the stream evaluate to true with the given predicateMDoubleStream
onClose(@NonNull 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, @NonNull SerializableDoubleBinaryOperator operator)
Performs a reduction on the elements of this stream using the given binary operator.OptionalDouble
reduce(@NonNull 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(@NonNull MDoubleStream other)
Unions this stream with another-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.gengoai.stream.MDoubleStream
updateConfig
-
-
-
-
Constructor Detail
-
LocalMDoubleStream
public LocalMDoubleStream(@NonNull @NonNull DoubleStream stream)
-
-
Method Detail
-
allMatch
public boolean allMatch(@NonNull @NonNull SerializableDoublePredicate predicate)
Description copied from interface:MDoubleStream
Determines if all doubles in the stream evaluate to true with the given predicate- Specified by:
allMatch
in interfaceMDoubleStream
- Parameters:
predicate
- the predicate to test double entries with- Returns:
- True if all elements in the stream evaluate to true
-
anyMatch
public boolean anyMatch(@NonNull @NonNull SerializableDoublePredicate predicate)
Description copied from interface:MDoubleStream
Determines if any of the doubles in the stream evaluate to true with the given predicate- Specified by:
anyMatch
in interfaceMDoubleStream
- Parameters:
predicate
- the predicate to test double entries with- Returns:
- True if any of the elements in the stream evaluate to true
-
cache
public MDoubleStream cache()
Description copied from interface:MDoubleStream
Caches the stream.- Specified by:
cache
in interfaceMDoubleStream
- Returns:
- the cached stream
-
count
public long count()
Description copied from interface:MDoubleStream
The number of items in the stream- Specified by:
count
in interfaceMDoubleStream
- Returns:
- the number of items in the stream
-
distinct
public MDoubleStream distinct()
Description copied from interface:MDoubleStream
Removes duplicates from the stream- Specified by:
distinct
in interfaceMDoubleStream
- Returns:
- the new stream without duplicates
-
filter
public MDoubleStream filter(@NonNull @NonNull SerializableDoublePredicate predicate)
Description copied from interface:MDoubleStream
Filters the stream.- Specified by:
filter
in interfaceMDoubleStream
- Parameters:
predicate
- the predicate to use to determine which objects are kept- Returns:
- the new stream
-
first
public OptionalDouble first()
Description copied from interface:MDoubleStream
Gets the first item in the stream- Specified by:
first
in interfaceMDoubleStream
- Returns:
- the optional containing the first item
-
flatMap
public MDoubleStream flatMap(@NonNull @NonNull SerializableDoubleFunction<double[]> mapper)
Description copied from interface:MDoubleStream
Maps the doubles in this stream to one or more new doubles using the given function.- Specified by:
flatMap
in interfaceMDoubleStream
- Parameters:
mapper
- the function to use to map objects- Returns:
- the new stream
-
forEach
public void forEach(@NonNull @NonNull SerializableDoubleConsumer consumer)
Description copied from interface:MDoubleStream
Performs an operation on each item in the stream- Specified by:
forEach
in interfaceMDoubleStream
- Parameters:
consumer
- the consumer action to perform
-
getContext
public StreamingContext getContext()
Description copied from interface:MDoubleStream
Gets the context used to create the stream- Specified by:
getContext
in interfaceMDoubleStream
- Returns:
- the context
-
isEmpty
public boolean isEmpty()
Description copied from interface:MDoubleStream
Determines if the stream is empty or not- Specified by:
isEmpty
in interfaceMDoubleStream
- Returns:
- True if empty, False otherwise
-
iterator
public PrimitiveIterator.OfDouble iterator()
Description copied from interface:MDoubleStream
Gets an iterator for the stream- Specified by:
iterator
in interfaceMDoubleStream
- Returns:
- the iterator of items in the stream
-
limit
public MDoubleStream limit(int n)
Description copied from interface:MDoubleStream
Limits the stream to the firstnumber
items.- Specified by:
limit
in interfaceMDoubleStream
- Parameters:
n
- the number of items desired- Returns:
- the new stream of size
number
-
map
public MDoubleStream map(@NonNull @NonNull SerializableDoubleUnaryOperator mapper)
Description copied from interface:MDoubleStream
Maps the doubles in the stream using the given function- Specified by:
map
in interfaceMDoubleStream
- Parameters:
mapper
- the function to use to map doubles- Returns:
- the new stream
-
mapToObj
public <T> MStream<T> mapToObj(@NonNull @NonNull SerializableDoubleFunction<? extends T> function)
Description copied from interface:MDoubleStream
Maps the doubles in the stream to objects using the given function- Specified by:
mapToObj
in interfaceMDoubleStream
- Type Parameters:
T
- the component type of the returning stream- Parameters:
function
- the function to use to map doubles- Returns:
- the new stream
-
max
public OptionalDouble max()
Description copied from interface:MDoubleStream
Returns the max item in the stream.- Specified by:
max
in interfaceMDoubleStream
- Returns:
- the optional containing the max value
-
mean
public double mean()
Description copied from interface:MDoubleStream
The mean value of the stream- Specified by:
mean
in interfaceMDoubleStream
- Returns:
- the mean value
-
min
public OptionalDouble min()
Description copied from interface:MDoubleStream
Returns the min item in the stream.- Specified by:
min
in interfaceMDoubleStream
- Returns:
- the optional containing the min value
-
noneMatch
public boolean noneMatch(@NonNull @NonNull SerializableDoublePredicate predicate)
Description copied from interface:MDoubleStream
Determines if none of the doubles in the stream evaluate to true with the given predicate- Specified by:
noneMatch
in interfaceMDoubleStream
- Parameters:
predicate
- the predicate to test double entries with- Returns:
- True if none of the elements in the stream evaluate to true
-
onClose
public MDoubleStream onClose(@NonNull @NonNull SerializableRunnable onCloseHandler)
Description copied from interface:MDoubleStream
Sets the handler to call when the stream is closed. Typically, this is to clean up any open resources, such as file handles.- Specified by:
onClose
in interfaceMDoubleStream
- Parameters:
onCloseHandler
- the handler to run when the stream is closed.
-
parallel
public MDoubleStream parallel()
Description copied from interface:MDoubleStream
Ensures that the stream is parallel or distributed.- Specified by:
parallel
in interfaceMDoubleStream
- Returns:
- the new stream
-
reduce
public OptionalDouble reduce(@NonNull @NonNull SerializableDoubleBinaryOperator operator)
Description copied from interface:MDoubleStream
Performs a reduction on the elements of this stream using the given binary operator.- Specified by:
reduce
in interfaceMDoubleStream
- Parameters:
operator
- the binary operator used to combine two objects- Returns:
- the optional describing the reduction
-
reduce
public double reduce(double zeroValue, @NonNull @NonNull SerializableDoubleBinaryOperator operator)
Description copied from interface:MDoubleStream
Performs a reduction on the elements of this stream using the given binary operator.- Specified by:
reduce
in interfaceMDoubleStream
- Parameters:
zeroValue
- the starting value for the reductionoperator
- the binary operator used to combine two objects- Returns:
- the optional describing the reduction
-
repartition
public MDoubleStream repartition(int numberOfPartition)
Description copied from interface:MDoubleStream
Repartitions the stream to the given number of partitions. This may be a no-op for some streams, i.e. Local Streams.- Specified by:
repartition
in interfaceMDoubleStream
- Parameters:
numberOfPartition
- the number of partitions the stream should have- Returns:
- the new stream
-
skip
public MDoubleStream skip(int n)
Description copied from interface:MDoubleStream
Skips the firstn
items in the stream- Specified by:
skip
in interfaceMDoubleStream
- Parameters:
n
- the number of items in the stream- Returns:
- the new stream
-
sorted
public MDoubleStream sorted(boolean ascending)
Description copied from interface:MDoubleStream
Sorts the double stream in ascending order.- Specified by:
sorted
in interfaceMDoubleStream
- Parameters:
ascending
- determines if the items should be sorted in ascending (true) or descending (false) order- Returns:
- the new double stream
-
statistics
public EnhancedDoubleStatistics statistics()
Description copied from interface:MDoubleStream
Calculates a number of useful statistics over the elements in the stream- Specified by:
statistics
in interfaceMDoubleStream
- Returns:
- the statistics
-
stddev
public double stddev()
Description copied from interface:MDoubleStream
Calculates the standard deviation of the stream- Specified by:
stddev
in interfaceMDoubleStream
- Returns:
- the standard deviation
-
sum
public double sum()
Description copied from interface:MDoubleStream
Calculates the sum of the stream- Specified by:
sum
in interfaceMDoubleStream
- Returns:
- the sum
-
toArray
public double[] toArray()
Description copied from interface:MDoubleStream
Collects the values of the stream as a double array.- Specified by:
toArray
in interfaceMDoubleStream
- Returns:
- the double array
-
isDistributed
public boolean isDistributed()
- Specified by:
isDistributed
in interfaceMDoubleStream
-
union
public MDoubleStream union(@NonNull @NonNull MDoubleStream other)
Description copied from interface:MDoubleStream
Unions this stream with another- Specified by:
union
in interfaceMDoubleStream
- Parameters:
other
- the other stream to append to this one- Returns:
- the new double stream
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
-