Class CountingTask<V>

java.lang.Object
java.util.concurrent.CompletableFuture<V>
eu.cloudnetservice.utils.base.concurrent.CountingTask<V>
Type Parameters:
V - the generic type of the task.
All Implemented Interfaces:
CompletionStage<V>, Future<V>

public class CountingTask<V> extends CompletableFuture<V>
The counting task is a task that starts at a specified count and is capable of counting both up and down. The task is not completed until the count is 0 or less. Once the task is completed it is not usable anymore.
Since:
4.0
  • Field Details

    • resultValue

      private final V resultValue
    • count

      private final AtomicInteger count
  • Constructor Details

    • CountingTask

      public CountingTask(@Nullable V resultValue, int initialCount)
      Constructs a new counting task with a starting count and a value to complete after counting to 0.
      Parameters:
      resultValue - the result value to complete this task with.
      initialCount - the initial count to start counting from.
  • Method Details

    • countUp

      public void countUp()
      Increments the count of this task by one and publishes the count change.
    • countDown

      public void countDown()
      Decrements the count of this task by one and publishes the count change. If the count is 0 or less this task is completed with the given result value.
    • countTo

      public void countTo(int target)
      Sets the count of this counting task to the given one and publishes the count change.
      Parameters:
      target - the value to count to.
    • count

      public int count()
      Gets the current count of this task.
      Returns:
      the count of this task.
    • publishCountChange

      protected void publishCountChange()
      Checks if the count of this task is 0 or less if that is the case this task is completed with its result value.