java.lang.Object
speiger.src.collections.floats.utils.FloatAsyncBuilder
The Async API allows you to process collections on a different thread without having to deal with the Multithreading complexity.
It uses the Lightweight Stream Replace API to do its work, which can make it faster then sequential streams.
This feature isn't designed to do Multithreading work, but to allow moving work off the main thread into a worker thread.
So anything executed on this is still Singlethreaded.
How it works is you create the AsyncBuilder using a Iterable of the Type.
Then select things you want to use on the Iterable.
- For example: map/filter/peek/limit/etc
After that you select your action the Iterable should be applied on.
- For Example: forEach/findFirst/matchAny/etc
Then optionally a custom Executor or callback can be applied
At the end either execute or join can be called to start the task.
- execute will return the Task reference so that the task can be traced back.
- join will await the completion of the task and return the return value
During Construction a couple Disposable Builder Objects will be created.
These will be only used during construction.
The Task Object is also pause-able/Interruptable at any moment during the Processing.
A small example
It uses the Lightweight Stream Replace API to do its work, which can make it faster then sequential streams.
This feature isn't designed to do Multithreading work, but to allow moving work off the main thread into a worker thread.
So anything executed on this is still Singlethreaded.
How it works is you create the AsyncBuilder using a Iterable of the Type.
Then select things you want to use on the Iterable.
- For example: map/filter/peek/limit/etc
After that you select your action the Iterable should be applied on.
- For Example: forEach/findFirst/matchAny/etc
Then optionally a custom Executor or callback can be applied
At the end either execute or join can be called to start the task.
- execute will return the Task reference so that the task can be traced back.
- join will await the completion of the task and return the return value
During Construction a couple Disposable Builder Objects will be created.
These will be only used during construction.
The Task Object is also pause-able/Interruptable at any moment during the Processing.
A small example
public void processFiles(ObjectCollection<String> potentialFiles) {
potentialFiles.asAsync()
.map(Paths::get).filter(Files::exists) //Modifies the collection (Optional)
.forEach(Files::delete) //Creates the action (Required)
.onCompletion(T -> {}} //Callback on completion (Optional)
.execute() //Starts the task. (Required)
}
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic classBase Task of the Actions that can be performed. -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungFloatAsyncBuilder(FloatIterable iterable) Main Constructor that uses a Iterable to build a Offthread Task.Helper constructor. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibung<E> ObjectAsyncBuilder<E>arrayflatMap(FloatFunction<E[]> mapper) Maps the elements to something elsecount(FloatPredicate filter) Counts all desired elements inside the Iterabledistinct()Removes duplicated elements out of the Iterableexecute()Starts the Execution of the task without awaiting its resultOptional way to add a custom executor that runs this offthread task.filter(FloatPredicate filter) Filters out the unwanted elements out of the IterablefindFirst(FloatPredicate filter) Searches through the elements of the Iterable to find if the desired element.<E,V extends Iterable<E>>
ObjectAsyncBuilder<E>flatMap(FloatFunction<V> mapper) Maps the elements to something elseforEach(FloatConsumer action) Iterates over the Iterable with a desired actionfloatjoin()Starts the Execution of the task and will await its completion, returning the result.floatStarts the Execution of the task and will await its completion with a timeout, returning the result.limit(long limit) Limits how many elements are inside of the Iterable<E> ObjectAsyncBuilder<E>map(FloatFunction<E> mapper) Maps the elements to something elsematchAll(FloatPredicate filter) Searches through the elements of the Iterable to find if all the desired elements are present.matchAny(FloatPredicate filter) Searches through the elements of the Iterable to find if the desired element is present.matchNone(FloatPredicate filter) Searches through the elements of the Iterable to find if unwanted elements are present.static FloatAsyncBuilderof(float... values) Helper function that automatically wraps a array into a AsyncBuilder since it forces this collections Iterable.static FloatAsyncBuilderHelper function that automatically wraps a Iterable into a AsyncBuilder since it forces this collections Iterable.onCompletion(Consumer<FloatTask> callback) Optional way to set a callback that allows to compute actions after the task was completed.peek(FloatConsumer action) Allows to preview elements before they are processed<E extends FloatCollection>
ObjectAsyncBuilder<E>pour(E collection) Pours all elements into a collection that can be laterPours all elements into a List that can be laterPours all elements into a Set that can be laterreduce(float identity, FloatFloatUnaryOperator operator) Reduces the elements inside of the Iterable down to one element using a identity element.reduce(FloatFloatUnaryOperator operator) Reduces the elements inside of the Iterable down to one elementrepeat(int repeats) Repeats the elements inside of the Iterablesorted(FloatComparator sorter) Sorts the elements inside of the Iterable.ObjectAsyncBuilder<float[]>Pours all elements of the Iterable down into a Array.
-
Konstruktordetails
-
FloatAsyncBuilder
Main Constructor that uses a Iterable to build a Offthread Task.- Parameter:
iterable- that should be processed
-
FloatAsyncBuilder
Helper constructor.- Parameter:
task- that had been build
-
-
Methodendetails
-
of
Helper function that automatically wraps a Iterable into a AsyncBuilder since it forces this collections Iterable.- Parameter:
iterable- that should be wrapped- Gibt zurück:
- a AsyncBuilder with the iterable wrapped
-
of
Helper function that automatically wraps a array into a AsyncBuilder since it forces this collections Iterable.- Parameter:
values- that should be wrapped- Gibt zurück:
- a AsyncBuilder with the values wrapped
-
map
Maps the elements to something else- Typparameter:
E- The return type.- Parameter:
mapper- the mapping function- Gibt zurück:
- a new Builder Object with the mapped Iterable
-
flatMap
Maps the elements to something else- Typparameter:
E- The return type.V- The return type supplier.- Parameter:
mapper- the flatMapping function- Gibt zurück:
- a new Builder Object with the mapped Iterable
-
arrayflatMap
Maps the elements to something else- Typparameter:
E- The return type.- Parameter:
mapper- the flatMapping function- Gibt zurück:
- a new Builder Object with the mapped Iterable
-
filter
Filters out the unwanted elements out of the Iterable- Parameter:
filter- the elements that should be kept- Gibt zurück:
- Self with a filter applied
-
distinct
Removes duplicated elements out of the Iterable- Gibt zurück:
- Self with a deduplicator applied
-
repeat
Repeats the elements inside of the Iterable- Parameter:
repeats- the amount of times the elements should be repeated- Gibt zurück:
- self with a repeater applied
-
limit
Limits how many elements are inside of the Iterable- Parameter:
limit- how many elements should max be iterated through- Gibt zurück:
- self with a limiter applied
-
sorted
Sorts the elements inside of the Iterable. This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it, and this will affect the pausing feature.- Parameter:
sorter- that sorts the elements.- Gibt zurück:
- self with a sorter applied
-
peek
Allows to preview elements before they are processed- Parameter:
action- the action that should be applied- Gibt zurück:
- self with a preview applied
-
forEach
Iterates over the Iterable with a desired action- Parameter:
action- that should be applied- Gibt zurück:
- a new Builder with the forEach action applied.
-
reduce
Reduces the elements inside of the Iterable down to one element- Parameter:
operator- that reduces the elements.- Gibt zurück:
- self with the reduce action applied
-
reduce
Reduces the elements inside of the Iterable down to one element using a identity element.- Parameter:
identity- the element the reduce function should start withoperator- that reduces the elements.- Gibt zurück:
- a new Builder with the reduce function applied
-
toFloatArray
Pours all elements of the Iterable down into a Array.- Gibt zurück:
- a new Builder with the ToArray function applied
-
pourAsList
Pours all elements into a List that can be later- Gibt zurück:
- a new Builder with the pour function applied
-
pourAsSet
Pours all elements into a Set that can be later- Gibt zurück:
- a new Builder with the pour function applied
-
pour
Pours all elements into a collection that can be later- Typparameter:
E- the return type- Parameter:
collection- the collection the elements- Gibt zurück:
- a new Builder with the pour function applied
-
matchAny
Searches through the elements of the Iterable to find if the desired element is present.- Parameter:
filter- that decides the desired elements- Gibt zurück:
- a new Builder with the matchAny function applied
-
matchNone
Searches through the elements of the Iterable to find if unwanted elements are present.- Parameter:
filter- that decides the unwanted elements- Gibt zurück:
- a new Builder with the matchNone function applied
-
matchAll
Searches through the elements of the Iterable to find if all the desired elements are present.- Parameter:
filter- that decides the desired elements- Gibt zurück:
- a new Builder with the matchAll function applied
-
findFirst
Searches through the elements of the Iterable to find if the desired element. If not present it will return the default value of the type- Parameter:
filter- that decides the desired elements- Gibt zurück:
- self with the findFirst function applied
-
count
Counts all desired elements inside the Iterable- Parameter:
filter- that decides the desired elements- Gibt zurück:
- a new Builder with the count function applied
-
executor
Optional way to add a custom executor that runs this offthread task. Can only be set after the action was decided on.- Parameter:
executor- that executes the task, defaults toSanityChecks.invokeAsyncTask(Runnable)- Gibt zurück:
- self with the executor set
- Note:
- has to be NonNull
-
onCompletion
Optional way to set a callback that allows to compute actions after the task was completed. The state of the task has to be validated by the callback.- Parameter:
callback- that should be notified after completion of the task- Gibt zurück:
- self with the callback set
- Note:
- can be null
-
execute
Starts the Execution of the task without awaiting its result- Gibt zurück:
- the task object that allow to trace it.
-
join
Starts the Execution of the task and will await its completion, returning the result.- Gibt zurück:
- the result of the task provided.
- Löst aus:
ExecutionException- if the task threw a exceptionInterruptedException- if the caller thread was interrupted
-
join
public float join(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Starts the Execution of the task and will await its completion with a timeout, returning the result.- Parameter:
timeout- of how long the thread should wait the task to be completedunit- of the desired waiting time.- Gibt zurück:
- the result of the provided task
- Löst aus:
InterruptedException- if the caller thread was interruptedExecutionException- if the task threw a exceptionTimeoutException- if the timeout was reached before the task was finished
-