Class ProgressTokenImpl<T>

java.lang.Object
com.github.shynixn.structureblocklib.core.entity.ProgressTokenImpl<T>
All Implemented Interfaces:
com.github.shynixn.structureblocklib.api.entity.ProgressToken<T>

public class ProgressTokenImpl<T> extends Object implements com.github.shynixn.structureblocklib.api.entity.ProgressToken<T>
  • Constructor Details

  • Method Details

    • progress

      public void progress(double progress)
      Calls the progress consumers with the progress update.
      Parameters:
      progress - update.
    • getCompletionStage

      public CompletionStage<T> getCompletionStage()
      Gets the already started CompletionStage which completes with the result. This instance can be used to execute calls after the progress has finished and listens to exceptions thrown during the progress.
      Specified by:
      getCompletionStage in interface com.github.shynixn.structureblocklib.api.entity.ProgressToken<T>
      Returns:
      NotNull instance of CompletionStage.
    • onProgress

      public com.github.shynixn.structureblocklib.api.entity.ProgressToken<T> onProgress(Consumer<Double> progress)
      Adds a new consumer to the progressToken which gets called each time the progress percentage from 0.0(0%) to 1.0 (100%) changes. Is at least called once for 0.0 and once for 1.0.
      Specified by:
      onProgress in interface com.github.shynixn.structureblocklib.api.entity.ProgressToken<T>
      Parameters:
      progress - progress.
      Returns:
      This instance.
    • onException

      public com.github.shynixn.structureblocklib.api.entity.ProgressToken<T> onException(Consumer<Throwable> exception)
      Adds a new consumer to the progressToken which gets called if the the progress fails with an exception.
      Specified by:
      onException in interface com.github.shynixn.structureblocklib.api.entity.ProgressToken<T>
      Parameters:
      exception - exception.
      Returns:
      This instance.
    • onResult

      public com.github.shynixn.structureblocklib.api.entity.ProgressToken<T> onResult(Consumer<T> result)
      Adds a new consumer to the progressToken which gets called once the the progress completes.
      Specified by:
      onResult in interface com.github.shynixn.structureblocklib.api.entity.ProgressToken<T>
      Parameters:
      result - result.
      Returns:
      This instance.
    • isCancelled

      public boolean isCancelled()
      Is the progress cancelled or not.
      Specified by:
      isCancelled in interface com.github.shynixn.structureblocklib.api.entity.ProgressToken<T>
      Returns:
      True if cancelled. False if not.
    • cancel

      public void cancel()
      Cancels the progress if it has not finished yet.
      Specified by:
      cancel in interface com.github.shynixn.structureblocklib.api.entity.ProgressToken<T>