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 Summary
ConstructorsConstructorDescriptionProgressTokenImpl(CompletionStage<T> item) Creates a new instance ofProgressTokenImpl. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels the progress if it has not finished yet.Gets the already startedCompletionStagewhich completes with the result.booleanIs the progress cancelled or not.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.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.com.github.shynixn.structureblocklib.api.entity.ProgressToken<T>Adds a new consumer to the progressToken which gets called once the the progress completes.voidprogress(double progress) Calls the progress consumers with the progress update.
-
Constructor Details
-
ProgressTokenImpl
Creates a new instance ofProgressTokenImpl.- Parameters:
item- Not null completionState.
-
-
Method Details
-
progress
public void progress(double progress) Calls the progress consumers with the progress update.- Parameters:
progress- update.
-
getCompletionStage
Gets the already startedCompletionStagewhich 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:
getCompletionStagein interfacecom.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:
onProgressin interfacecom.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:
onExceptionin interfacecom.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:
onResultin interfacecom.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:
isCancelledin interfacecom.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:
cancelin interfacecom.github.shynixn.structureblocklib.api.entity.ProgressToken<T>
-