Package io.github.futures4j
Enum CompletionState
- java.lang.Object
-
- java.lang.Enum<CompletionState>
-
- io.github.futures4j.CompletionState
-
- All Implemented Interfaces:
Serializable
,Comparable<CompletionState>
public enum CompletionState extends Enum<CompletionState>
Enumerates the possible completion states of aFuture
, providing a unified way to determine whether a task is still running, completed successfully, cancelled, or failed due to an exception.This utility supports various implementations of
Future
, includingCompletableFuture
andForkJoinTask
, and offers a consistent method to assess their completion status.Use the
of(Future)
method to determine theCompletionState
of a givenFuture
.- Author:
- Sebastian Thomschke
-
-
Enum Constant Summary
Enum Constants Enum Constant Description CANCELLED
Indicates that the task was cancelled before it completed.FAILED
Indicates that the task completed with an exception (excluding cancellation exceptions).INCOMPLETE
Indicates that the task hasn't started or is still in progress.SUCCESS
Indicates that the task completed successfully without throwing any exceptions.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CompletionState
of(Future<?> future)
Determines theCompletionState
of the givenFuture
based on its current status.static CompletionState
valueOf(String name)
Returns the enum constant of this type with the specified name.static CompletionState[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
INCOMPLETE
public static final CompletionState INCOMPLETE
Indicates that the task hasn't started or is still in progress.
-
SUCCESS
public static final CompletionState SUCCESS
Indicates that the task completed successfully without throwing any exceptions.
-
CANCELLED
public static final CompletionState CANCELLED
Indicates that the task was cancelled before it completed.
-
FAILED
public static final CompletionState FAILED
Indicates that the task completed with an exception (excluding cancellation exceptions).
-
-
Method Detail
-
values
public static CompletionState[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (CompletionState c : CompletionState.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static CompletionState valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
of
public static CompletionState of(Future<?> future)
Determines theCompletionState
of the givenFuture
based on its current status.The method returns:
INCOMPLETE
if the future has not completed yet (i.e., is still running or pending).SUCCESS
if the future completed successfully without exceptions.CANCELLED
if the future was cancelled before completion.FAILED
if the future completed exceptionally due to an error (other than cancellation).
- Parameters:
future
- theFuture
whose completion state is to be determined- Returns:
- the
CompletionState
representing the current state of the future
-
-