T - the type of elements maintained by this Collectionpublic class ObjectAsyncBuilder<T>
extends java.lang.Object
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)
}
| Modifier and Type | Class and Description |
|---|---|
static class |
ObjectAsyncBuilder.BaseObjectTask<T>
Base Task of the Actions that can be performed.
|
| Constructor and Description |
|---|
ObjectAsyncBuilder(ObjectAsyncBuilder.BaseObjectTask<T> task)
Helper constructor.
|
ObjectAsyncBuilder(ObjectIterable<T> iterable)
Main Constructor that uses a Iterable to build a Offthread Task.
|
| Modifier and Type | Method and Description |
|---|---|
<E> ObjectAsyncBuilder<E> |
arrayflatMap(Object2ObjectFunction<T,E[]> mapper)
Maps the elements to something else
|
IntAsyncBuilder |
count(Object2BooleanFunction<T> filter)
Counts all desired elements inside the Iterable
|
ObjectAsyncBuilder<T> |
distinct()
Removes duplicated elements out of the Iterable
|
ObjectTask<T> |
execute()
Starts the Execution of the task without awaiting its result
|
ObjectAsyncBuilder<T> |
executor(java.util.concurrent.Executor executor)
Optional way to add a custom executor that runs this offthread task.
|
ObjectAsyncBuilder<T> |
filter(Object2BooleanFunction<T> filter)
Filters out the unwanted elements out of the Iterable
|
ObjectAsyncBuilder<T> |
findFirst(Object2BooleanFunction<T> filter)
Searches through the elements of the Iterable to find if the desired element.
|
<E,V extends java.lang.Iterable<E>> |
flatMap(Object2ObjectFunction<T,V> mapper)
Maps the elements to something else
|
ObjectAsyncBuilder<java.lang.Void> |
forEach(java.util.function.Consumer<T> action)
Iterates over the Iterable with a desired action
|
T |
join()
Starts the Execution of the task and will await its completion, returning the result.
|
T |
join(long timeout,
java.util.concurrent.TimeUnit unit)
Starts the Execution of the task and will await its completion with a timeout, returning the result.
|
ObjectAsyncBuilder<T> |
limit(long limit)
Limits how many elements are inside of the Iterable
|
<E> ObjectAsyncBuilder<E> |
map(Object2ObjectFunction<T,E> mapper)
Maps the elements to something else
|
BooleanAsyncBuilder |
matchAll(Object2BooleanFunction<T> filter)
Searches through the elements of the Iterable to find if all the desired elements are present.
|
BooleanAsyncBuilder |
matchAny(Object2BooleanFunction<T> filter)
Searches through the elements of the Iterable to find if the desired element is present.
|
BooleanAsyncBuilder |
matchNone(Object2BooleanFunction<T> filter)
Searches through the elements of the Iterable to find if unwanted elements are present.
|
static <T> ObjectAsyncBuilder<T> |
of(java.lang.Iterable<T> iterable)
Helper function that automatically wraps a Iterable into a AsyncBuilder since it forces this collections Iterable.
|
static <T> ObjectAsyncBuilder<T> |
of(T... values)
Helper function that automatically wraps a array into a AsyncBuilder since it forces this collections Iterable.
|
ObjectAsyncBuilder<T> |
onCompletion(java.util.function.Consumer<ObjectTask<T>> callback)
Optional way to set a callback that allows to compute actions after the task was completed.
|
ObjectAsyncBuilder<T> |
peek(java.util.function.Consumer<T> action)
Allows to preview elements before they are processed
|
<E extends ObjectCollection<T>> |
pour(E collection)
Pours all elements into a collection that can be later
|
ObjectAsyncBuilder<ObjectList<T>> |
pourAsList()
Pours all elements into a List that can be later
|
ObjectAsyncBuilder<ObjectSet<T>> |
pourAsSet()
Pours all elements into a Set that can be later
|
<E> ObjectAsyncBuilder<E> |
reduce(E identity,
java.util.function.BiFunction<E,T,E> operator)
Reduces the elements inside of the Iterable down to one element using a identity element.
|
ObjectAsyncBuilder<T> |
reduce(ObjectObjectUnaryOperator<T,T> operator)
Reduces the elements inside of the Iterable down to one element
|
ObjectAsyncBuilder<T> |
sorted(java.util.Comparator<T> sorter)
Sorts the elements inside of the Iterable.
|
public ObjectAsyncBuilder(ObjectIterable<T> iterable)
iterable - that should be processedpublic ObjectAsyncBuilder(ObjectAsyncBuilder.BaseObjectTask<T> task)
task - that had been buildpublic static <T> ObjectAsyncBuilder<T> of(java.lang.Iterable<T> iterable)
T - the type of elements maintained by this Collectioniterable - that should be wrappedpublic static <T> ObjectAsyncBuilder<T> of(T... values)
T - the type of elements maintained by this Collectionvalues - that should be wrappedpublic <E> ObjectAsyncBuilder<E> map(Object2ObjectFunction<T,E> mapper)
E - The return type.mapper - the mapping functionpublic <E,V extends java.lang.Iterable<E>> ObjectAsyncBuilder<E> flatMap(Object2ObjectFunction<T,V> mapper)
V - The return type supplier.E - The return type.mapper - the flatMapping functionpublic <E> ObjectAsyncBuilder<E> arrayflatMap(Object2ObjectFunction<T,E[]> mapper)
E - The return type.mapper - the flatMapping functionpublic ObjectAsyncBuilder<T> filter(Object2BooleanFunction<T> filter)
filter - the elements that should be keptpublic ObjectAsyncBuilder<T> distinct()
public ObjectAsyncBuilder<T> limit(long limit)
limit - how many elements should max be iterated throughpublic ObjectAsyncBuilder<T> sorted(java.util.Comparator<T> sorter)
sorter - that sorts the elements.public ObjectAsyncBuilder<T> peek(java.util.function.Consumer<T> action)
action - the action that should be appliedpublic ObjectAsyncBuilder<java.lang.Void> forEach(java.util.function.Consumer<T> action)
action - that should be appliedpublic ObjectAsyncBuilder<T> reduce(ObjectObjectUnaryOperator<T,T> operator)
operator - that reduces the elements.public <E> ObjectAsyncBuilder<E> reduce(E identity, java.util.function.BiFunction<E,T,E> operator)
E - the return typeidentity - the element the reduce function should start withoperator - that reduces the elements.public ObjectAsyncBuilder<ObjectList<T>> pourAsList()
public ObjectAsyncBuilder<ObjectSet<T>> pourAsSet()
public <E extends ObjectCollection<T>> ObjectAsyncBuilder<E> pour(E collection)
E - the return typecollection - the collection the elementspublic BooleanAsyncBuilder matchAny(Object2BooleanFunction<T> filter)
filter - that decides the desired elementspublic BooleanAsyncBuilder matchNone(Object2BooleanFunction<T> filter)
filter - that decides the unwanted elementspublic BooleanAsyncBuilder matchAll(Object2BooleanFunction<T> filter)
filter - that decides the desired elementspublic ObjectAsyncBuilder<T> findFirst(Object2BooleanFunction<T> filter)
filter - that decides the desired elementspublic IntAsyncBuilder count(Object2BooleanFunction<T> filter)
filter - that decides the desired elementspublic ObjectAsyncBuilder<T> executor(java.util.concurrent.Executor executor)
executor - that executes the task, defaults to SanityChecks.invokeAsyncTask(Runnable)public ObjectAsyncBuilder<T> onCompletion(java.util.function.Consumer<ObjectTask<T>> callback)
callback - that should be notified after completion of the taskpublic ObjectTask<T> execute()
public T join() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
java.util.concurrent.ExecutionException - if the task threw a exceptionjava.lang.InterruptedException - if the caller thread was interruptedpublic T join(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
timeout - of how long the thread should wait the task to be completedunit - of the desired waiting time.java.lang.InterruptedException - if the caller thread was interruptedjava.util.concurrent.ExecutionException - if the task threw a exceptionjava.util.concurrent.TimeoutException - if the timeout was reached before the task was finished