com.github.deinok.threading.group.TaskList Maven / Gradle / Ivy
package com.github.deinok.threading.group;
import com.github.deinok.threading.OnSuccess;
import com.github.deinok.threading.Task;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class TaskList extends LinkedList> implements ITaskGroup {
@NotNull
public ITaskGroup executeAsync() {
for (Task task : this) {
task.executeAsync();
}
return this;
}
@NotNull
public ITaskGroup executeSync() {
for (Task task : this) {
task.executeSync();
}
return this;
}
public int getPriority() {
int result = 0;
for (Task task : this) {
result += task.getPriority();
}
return result / this.size();
}
@NotNull
public ITaskGroup setPriority(int priority) {
for (Task task : this) {
task.setPriority(priority);
}
return this;
}
public boolean cancel() {
for (Task task : this) {
boolean cancelled = task.cancel();
if (!cancelled) {
return false;
}
}
return true;
}
@NotNull
public ITaskGroup await() {
for (Task task : this) {
task.await();
}
return this;
}
@NotNull
public List getResult() {
final List results = new ArrayList(this.size());
for (Task task : this) {
results.add(task.getResult());
}
return results;
}
@NotNull
public ITaskGroup onSuccess(@NotNull OnSuccess onSuccess) {
for (Task task : this) {
task.onSuccess(onSuccess);
}
return this;
}
}