Package net.fabricmc.fabric.api.util
Enum Class TriState
- All Implemented Interfaces:
Serializable
,Comparable<TriState>
,Constable
Represents a boolean value which can be true, false or refer to a default value.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
get()
Gets the value of the tri-state.@Nullable Boolean
getBoxed()
Gets the value of the tri-state as a boxed, nullable boolean.<T> Optional<T>
map
(BooleanFunction<@Nullable ? extends T> mapper) static TriState
of
(boolean bool) Gets the corresponding tri-state from a boolean value.static TriState
Gets a tri-state from a nullable boxed boolean.boolean
orElse
(boolean value) Gets the value of this tri-state.boolean
orElseGet
(BooleanSupplier supplier) Gets the value of this tri-state.<X extends Throwable>
booleanorElseThrow
(Supplier<X> exceptionSupplier) Gets the value of this tri-state, or throws an exception if this tri-state's value isDEFAULT
.static TriState
Returns the enum constant of this class with the specified name.static TriState[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
FALSE
Represents the boolean value offalse
. -
DEFAULT
Represents a value that refers to a "default" value, often as a fallback. -
TRUE
Represents the boolean value oftrue
.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified nameNullPointerException
- if the argument is null
-
of
Gets the corresponding tri-state from a boolean value. -
of
Gets a tri-state from a nullable boxed boolean. -
get
public boolean get()Gets the value of the tri-state.- Returns:
- true if the tri-state is
TRUE
, otherwise false.
-
getBoxed
Gets the value of the tri-state as a boxed, nullable boolean. -
orElse
public boolean orElse(boolean value) Gets the value of this tri-state. If the value isDEFAULT
then use the supplied value.- Parameters:
value
- the value to fall back to- Returns:
- the value of the tri-state or the supplied value if
DEFAULT
.
-
orElseGet
Gets the value of this tri-state. If the value isDEFAULT
then use the supplied value.- Parameters:
supplier
- the supplier used to get the value to fall back to- Returns:
- the value of the tri-state or the value of the supplier if the tri-state is
DEFAULT
.
-
map
- Type Parameters:
T
- the type of object being supplier by the mapper- Parameters:
mapper
- the mapper to use- Returns:
- an optional containing the mapped value;
Optional.empty()
if the tri-state isDEFAULT
or the value provided by the mapper isnull
.
-
orElseThrow
Gets the value of this tri-state, or throws an exception if this tri-state's value isDEFAULT
.- Type Parameters:
X
- Type of the exception to be thrown- Parameters:
exceptionSupplier
- the supplying function that produces an exception to be thrown- Returns:
- the value
- Throws:
X
- if the value isDEFAULT
-