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

public class IteratingTask<T> extends BukkitRunnable
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 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 type IteratingTask
      processor - processor to process each element. Returns true if the element was processed or false if it was skipped.
      statisticsConsumer - consumer which will be executed after all elements were processed
  • Method Details

    • run

      public final void run()