Package com.gengoai.stream.local
Class LocalStreamingContext
- java.lang.Object
-
- com.gengoai.stream.StreamingContext
-
- com.gengoai.stream.local.LocalStreamingContext
-
- All Implemented Interfaces:
Serializable
,AutoCloseable
public final class LocalStreamingContext extends StreamingContext
Represents a local streaming context using Java's built-in streams- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static LocalStreamingContext
INSTANCE
The singleton instance of the context
-
Constructor Summary
Constructors Constructor Description LocalStreamingContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
<E> MCounterAccumulator<E>
counterAccumulator(String name)
Creates a new Counter accumulator.MDoubleAccumulator
doubleAccumulator(double initialValue, String name)
Creates a new double accumulator with the given initial value.MDoubleStream
doubleStream(double... values)
Creates a MDoubleStream from a variable list of doublesMDoubleStream
doubleStream(DoubleStream doubleStream)
Creates a MDoubleStream from a Java DoubleStream<T> MStream<T>
empty()
Creates a new empty stream<E> MAccumulator<E,List<E>>
listAccumulator(String name)
Creates a list accumulatorMLongAccumulator
longAccumulator(long initialValue, String name)
Creates a new long accumulator with the given initial value.<K,V>
MMapAccumulator<K,V>mapAccumulator(String name)
Creates a new map accumulator<K1,K2>
MMultiCounterAccumulator<K1,K2>multiCounterAccumulator(String name)
Creates a new MultiCounter accumulator<K,V>
MPairStream<K,V>pairStream(@NonNull Collection<Map.Entry<? extends K,? extends V>> tuples)
Creates a new pair stream from the given collection of entries.<K,V>
MPairStream<K,V>pairStream(@NonNull Map<? extends K,? extends V> map)
Creates a new pair stream from the given map.MStream<Integer>
range(int startInclusive, int endExclusive)
Creates a ranged based integer stream starting atstartInclusive
and ending beforeendExclusive
.<E> MAccumulator<E,Set<E>>
setAccumulator(String name)
Creates a set accumulatorMStatisticsAccumulator
statisticsAccumulator(String name)
Creates a new statistics accumulator<T> MStream<T>
stream(Iterable<? extends T> iterable)
Creates a new MStream from the given iterable<T> MStream<T>
stream(Stream<T> stream)
Creates a new MStream from Java StreamMStream<String>
textFile(Resource resource)
Creates a new MStream where each element is a line in the resources (recursive) at the given location.MStream<String>
textFile(Resource location, boolean wholeFile)
Creates a new MStream where each element is the entire content of a resource (wholeFile = true) or a single line of the resource (wholeFile = False) and resources are gathered recursively from the given location.MStream<String>
textFile(String location)
Creates a new MStream where each element is a line in the resources (recursive) at the given location.-
Methods inherited from class com.gengoai.stream.StreamingContext
counterAccumulator, distributed, doubleAccumulator, doubleAccumulator, emptyDouble, emptyPair, get, get, isDistributed, listAccumulator, local, longAccumulator, longAccumulator, mapAccumulator, multiCounterAccumulator, pairStream, setAccumulator, statisticsAccumulator, stream, stream, textFile, updateConfig
-
-
-
-
Field Detail
-
INSTANCE
public static final LocalStreamingContext INSTANCE
The singleton instance of the context
-
-
Method Detail
-
close
public void close()
-
counterAccumulator
public <E> MCounterAccumulator<E> counterAccumulator(String name)
Description copied from class:StreamingContext
Creates a new Counter accumulator.- Specified by:
counterAccumulator
in classStreamingContext
- Type Parameters:
E
- the component type of the counter- Parameters:
name
- the name of the accumulator- Returns:
- the counter accumulator
-
doubleAccumulator
public MDoubleAccumulator doubleAccumulator(double initialValue, String name)
Description copied from class:StreamingContext
Creates a new double accumulator with the given initial value.- Specified by:
doubleAccumulator
in classStreamingContext
- Parameters:
initialValue
- the initial value of the accumulatorname
- The name of the accumulator- Returns:
- the double accumulator
-
doubleStream
public MDoubleStream doubleStream(DoubleStream doubleStream)
Description copied from class:StreamingContext
Creates a MDoubleStream from a Java DoubleStream- Specified by:
doubleStream
in classStreamingContext
- Parameters:
doubleStream
- the double stream to wrap / consume- Returns:
- the MDoubleStream
-
doubleStream
public MDoubleStream doubleStream(double... values)
Description copied from class:StreamingContext
Creates a MDoubleStream from a variable list of doubles- Overrides:
doubleStream
in classStreamingContext
- Parameters:
values
- the values making up the double stream- Returns:
- the MDoubleStream
-
empty
public <T> MStream<T> empty()
Description copied from class:StreamingContext
Creates a new empty stream- Specified by:
empty
in classStreamingContext
- Type Parameters:
T
- the component type of the stream- Returns:
- the empty MStream
-
listAccumulator
public <E> MAccumulator<E,List<E>> listAccumulator(String name)
Description copied from class:StreamingContext
Creates a list accumulator- Specified by:
listAccumulator
in classStreamingContext
- Type Parameters:
E
- the component type of the list- Parameters:
name
- the name of the accumulator- Returns:
- the list accumulator
-
longAccumulator
public MLongAccumulator longAccumulator(long initialValue, String name)
Description copied from class:StreamingContext
Creates a new long accumulator with the given initial value.- Specified by:
longAccumulator
in classStreamingContext
- Parameters:
initialValue
- the initial value of the accumulatorname
- the name of the accumulator- Returns:
- the long accumulator
-
mapAccumulator
public <K,V> MMapAccumulator<K,V> mapAccumulator(String name)
Description copied from class:StreamingContext
Creates a new map accumulator- Specified by:
mapAccumulator
in classStreamingContext
- Type Parameters:
K
- the key type parameterV
- the value type parameter- Parameters:
name
- the name of the accumulator- Returns:
- the map accumulator
-
multiCounterAccumulator
public <K1,K2> MMultiCounterAccumulator<K1,K2> multiCounterAccumulator(String name)
Description copied from class:StreamingContext
Creates a new MultiCounter accumulator- Specified by:
multiCounterAccumulator
in classStreamingContext
- Type Parameters:
K1
- the first key type parameterK2
- the second key type parameter- Parameters:
name
- the name of the accumulator- Returns:
- the MultiCounter accumulator
-
pairStream
public <K,V> MPairStream<K,V> pairStream(@NonNull @NonNull Map<? extends K,? extends V> map)
Description copied from class:StreamingContext
Creates a new pair stream from the given map.- Specified by:
pairStream
in classStreamingContext
- Type Parameters:
K
- the key type parameterV
- the value type parameter- Parameters:
map
- the map to stream- Returns:
- the pair stream
-
pairStream
public <K,V> MPairStream<K,V> pairStream(@NonNull @NonNull Collection<Map.Entry<? extends K,? extends V>> tuples)
Description copied from class:StreamingContext
Creates a new pair stream from the given collection of entries.- Specified by:
pairStream
in classStreamingContext
- Type Parameters:
K
- the key type parameterV
- the value type parameter- Parameters:
tuples
- the collection of entries to use to create the pair stream- Returns:
- the pair stream
-
range
public MStream<Integer> range(int startInclusive, int endExclusive)
Description copied from class:StreamingContext
Creates a ranged based integer stream starting atstartInclusive
and ending beforeendExclusive
.- Specified by:
range
in classStreamingContext
- Parameters:
startInclusive
- the starting number in the range (inclusive)endExclusive
- the ending number in the range (exclusive)- Returns:
- the integer stream
-
setAccumulator
public <E> MAccumulator<E,Set<E>> setAccumulator(String name)
Description copied from class:StreamingContext
Creates a set accumulator- Specified by:
setAccumulator
in classStreamingContext
- Type Parameters:
E
- the component type of the set- Parameters:
name
- the name of the accumulator- Returns:
- the set accumulator
-
statisticsAccumulator
public MStatisticsAccumulator statisticsAccumulator(String name)
Description copied from class:StreamingContext
Creates a new statistics accumulator- Specified by:
statisticsAccumulator
in classStreamingContext
- Parameters:
name
- the name of the accumulator- Returns:
- the statistics accumulator
-
stream
public <T> MStream<T> stream(Stream<T> stream)
Description copied from class:StreamingContext
Creates a new MStream from Java Stream- Specified by:
stream
in classStreamingContext
- Type Parameters:
T
- the component type parameter of the stream- Parameters:
stream
- the Java stream to wrap / consume- Returns:
- the new MStream
-
stream
public <T> MStream<T> stream(Iterable<? extends T> iterable)
Description copied from class:StreamingContext
Creates a new MStream from the given iterable- Specified by:
stream
in classStreamingContext
- Type Parameters:
T
- the component type parameter of the stream- Parameters:
iterable
- the iterable to wrap / consume- Returns:
- the new MStream
-
textFile
public MStream<String> textFile(String location)
Description copied from class:StreamingContext
Creates a new MStream where each element is a line in the resources (recursive) at the given location.- Specified by:
textFile
in classStreamingContext
- Parameters:
location
- the location to read- Returns:
- the new MStream backed by the lines of the files in the given location.
-
textFile
public MStream<String> textFile(Resource resource)
Description copied from class:StreamingContext
Creates a new MStream where each element is a line in the resources (recursive) at the given location.- Specified by:
textFile
in classStreamingContext
- Parameters:
resource
- the location to read- Returns:
- the new MStream backed by the lines of the files in the given location.
-
textFile
public MStream<String> textFile(Resource location, boolean wholeFile)
Description copied from class:StreamingContext
Creates a new MStream where each element is the entire content of a resource (wholeFile = true) or a single line of the resource (wholeFile = False) and resources are gathered recursively from the given location.
- Specified by:
textFile
in classStreamingContext
- Parameters:
location
- the locationwholeFile
- the whole file- Returns:
- the m stream
-
-