Enum Class TriState

java.lang.Object
java.lang.Enum<TriState>
net.fabricmc.fabric.api.util.TriState
All Implemented Interfaces:
Serializable, Comparable<TriState>, java.lang.constant.Constable

public enum TriState extends Enum<TriState>
Represents a boolean value which can be true, false or refer to a default value.
  • Enum Constant Details

    • FALSE

      public static final TriState FALSE
      Represents the boolean value of false.
    • DEFAULT

      public static final TriState DEFAULT
      Represents a value that refers to a "default" value, often as a fallback.
    • TRUE

      public static final TriState TRUE
      Represents the boolean value of true.
  • Method Details

    • values

      public static TriState[] 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

      public static TriState valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • of

      public static TriState of(boolean bool)
      Gets the corresponding tri-state from a boolean value.
      Parameters:
      bool - the boolean value
      Returns:
      TRUE or FALSE depending on the value of the boolean.
    • of

      public static TriState of(@Nullable @Nullable Boolean bool)
      Gets a tri-state from a nullable boxed boolean.
      Parameters:
      bool - the boolean value
      Returns:
      DEFAULT if null. Otherwise TRUE or FALSE depending on the value of the boolean.
    • get

      public boolean get()
      Gets the value of the tri-state.
      Returns:
      true if the tri-state is TRUE. Otherwise false.
    • getBoxed

      @Nullable public @Nullable Boolean getBoxed()
      Gets the value of the tri-state as a boxed, nullable boolean.
      Returns:
      null if DEFAULT. Otherwise true if TRUE or false if FALSE.
    • orElse

      public boolean orElse(boolean value)
      Gets the value of this tri-state. If the value is DEFAULT then use the supplied value.
      Parameters:
      value - the value to fallback to
      Returns:
      the value of the tri-state or the supplied value if DEFAULT.
    • orElseGet

      public boolean orElseGet(BooleanSupplier supplier)
      Gets the value of this tri-state. If the value is DEFAULT then use the supplied value.
      Parameters:
      supplier - the supplier used to get the value to fallback to
      Returns:
      the value of the tri-state or the value of the supplier if the tri-state is DEFAULT.
    • map

      public <T> Optional<T> map(BooleanFunction<@Nullable ? extends T> mapper)
      Maps the boolean value of this tri-state if it is TRUE or FALSE.
      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 is DEFAULT or the value provided by the mapper is null.
    • orElseThrow

      public <X extends Throwable> boolean orElseThrow(Supplier<X> exceptionSupplier) throws X
      Gets the value of this tri-state, or throws an exception if this tri-state's value is DEFAULT.
      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 is DEFAULT