Class IteratingTask<T>
java.lang.Object
org.bukkit.scheduler.BukkitRunnable
de.eldoria.eldoutilities.threading.IteratingTask<T>
- Type Parameters:
T
- type of collection
- All Implemented Interfaces:
Runnable
A task which iterates of a collection and cancels itself when done. *
IteratingTask<T> iteratingTask = new IteratingTask<>(collection, (e) ->
{
if (didSomething(e)) {
return true;
}
return false;
}, stats -> {
Bukkit.logger().info(
String.format("Processed %d elements in %dms",
stats.getProcessedElements(),
stats.getTime()));
}
);
iteratingTask.runTaskTimer(plugin, 5, 1);
- Since:
- 1.0.0
-
Constructor Summary
ConstructorDescriptionIteratingTask
(Iterable<T> iterable, Predicate<T> processor, Consumer<TaskStatistics> statisticsConsumer) Creates a new iterating task. -
Method Summary
Methods inherited from class org.bukkit.scheduler.BukkitRunnable
cancel, getTaskId, isCancelled, runTask, runTaskAsynchronously, runTaskLater, runTaskLaterAsynchronously, runTaskTimer, runTaskTimerAsynchronously
-
Constructor Details
-
IteratingTask
public IteratingTask(Iterable<T> iterable, Predicate<T> processor, Consumer<TaskStatistics> statisticsConsumer) Creates a new iterating task.- Parameters:
iterable
- iterable collection of elements of typeIteratingTask
processor
- processor to process each element. Returnstrue
if the element was processed orfalse
if it was skipped.statisticsConsumer
- consumer which will be executed after all elements were processed
-
-
Method Details
-
run
public final void run()
-