Skip to content

Commit

Permalink
Fix (and simplify) wrapTasks method.
Browse files Browse the repository at this point in the history
Signed-off-by: Sjoerd Talsma <sjoerdtalsma@users.noreply.github.com>
  • Loading branch information
sjoerdtalsma committed Nov 15, 2024
1 parent 401038b commit 9b523fb
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -74,18 +73,14 @@ protected <T> Future<T> wrap(Future<T> source) {
* @see #wrap(Callable)
*/
protected <T> Collection<? extends Callable<T>> wrapTasks(Collection<? extends Callable<T>> tasks) {
Collection<? extends Callable<T>> wrappedTasks = tasks;
if (tasks != null && !tasks.isEmpty()) {
boolean modification = false;
final List<Callable<T>> copy = new ArrayList<Callable<T>>(tasks.size());
final List<Callable<T>> wrappedTasks = new ArrayList<>(tasks.size());
for (Callable<T> task : tasks) {
final Callable<T> wrapped = wrap(task);
modification |= (task == wrapped || Objects.equals(task, wrapped));
copy.add(wrapped);
wrappedTasks.add(wrap(task));
}
if (modification) wrappedTasks = copy;
tasks = wrappedTasks;
}
return wrappedTasks;
return tasks;
}

/**
Expand Down

0 comments on commit 9b523fb

Please sign in to comment.