Enum Class TriState

java.lang.Object
java.lang.Enum<TriState>
org.apache.juneau.commons.lang.TriState
All Implemented Interfaces:
Serializable, Comparable<TriState>, Constable

public enum TriState extends Enum<TriState>
Three-state enumeration for boolean-like values that can be explicitly set or unset.

This enum is useful in scenarios where you need to distinguish between:

  • A value that is explicitly set to true
  • A value that is explicitly set to false
  • A value that is not set (should inherit from a parent/default)
Example:

// In an annotation public @interface MyConfig { TriState enabled() default TriState.UNSET; } // Usage @MyConfig(enabled = TriState.TRUE) // Explicitly enabled @MyConfig(enabled = TriState.FALSE) // Explicitly disabled @MyConfig // Not set, inherits default

  • Enum Constant Details

    • TRUE

      public static final TriState TRUE
      Explicitly set to true.
    • FALSE

      public static final TriState FALSE
      Explicitly set to false.
    • UNSET

      public static final TriState UNSET
      Not set - should inherit from parent or use default value.
  • 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
    • toBoolean

      public boolean toBoolean(boolean defaultValue)
      Converts this TriState to a boolean value.

      If this is UNSET, returns the provided default value.

      Parameters:
      defaultValue - The default value to use if this is UNSET.
      Returns:
      true if this is TRUE, false if this is FALSE, or the provided default if this is UNSET.
    • fromBoolean

      public static TriState fromBoolean(boolean value)
      Converts a boolean to a TriState.
      Parameters:
      value - The boolean value.
      Returns:
      TRUE if true, FALSE if false.