Package com.landawn.abacus.util.stream
Enum Class BaseStream.Splitor
- All Implemented Interfaces:
Serializable
,Comparable<BaseStream.Splitor>
,Constable
- Enclosing interface:
- BaseStream<T,
A, P, C, PL, OT, IT, ITER extends Iterator<T>, S extends BaseStream<T, A, P, C, PL, OT, IT, ITER, S>>
Generally, or most of time, elements will be fetched and processed by parallel threads one by one.
If you want to customize the buffer size for each thread, try
synchronized (elements) { if (elements.hasNext()) { next = elements.next(); } } // Do something with next...
Splitor.ARRAY
only works when stream elements are stored in an array.
The array will be equally split into slices based on thread number for each thread:
int sliceSize = (toIndex - fromIndex) / threadNum + ((toIndex - fromIndex) % threadNum == 0 ? 0 : 1);If stream elements are not stored in an array,
Splitor.ARRAY
will just works as same as how Splitor.ITERATOR
works.
If you want to customize the buffer size for each thread, try
stream.split(bufferSize)
or stream.splitToList(bufferSize)
stream.split(bufferSize).parallel(...).map/filter/flatMap...(sliceStream -> // do whatever you want to do); stream.splitToList(bufferSize).parallel(...).map/filter/flatMap...(sliceList -> // do whatever you want to do); // Or stream.sps(maxThreadNum, bufferSize, op)
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic BaseStream.Splitor
Returns the enum constant of this class with the specified name.static BaseStream.Splitor[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class java.lang.Enum
compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Enum Constant Details
-
ITERATOR
Elements will be fetched and processed by parallel threads one by one.synchronized (elements) { if (elements.hasNext()) { next = elements.next(); } } // Do something with next...
-
ARRAY
Splitor.ARRAY
only works when stream elements are stored in an array. The array will be equally split into slices based on thread number for each thread:int sliceSize = (toIndex - fromIndex) / threadNum + ((toIndex - fromIndex) % threadNum == 0 ? 0 : 1);
If stream elements are not stored in an array,Splitor.ARRAY
will just works as same as howSplitor.ITERATOR
works.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-