Enum TriStateBoolean

  • All Implemented Interfaces:
    Serializable, Comparable<TriStateBoolean>

    public enum TriStateBoolean
    extends Enum<TriStateBoolean>
    A tri-state toggle for boolean-like config options that need to distinguish "the user never set this" from an explicit true/false, e.g. so a weak default can be applied along with a one-time warning when the option was left unset, while an explicit false silently keeps the same default behavior.

    This replaces the previous convention of using a boxed Boolean field where null meant "unset", which requires a code comment at every declaration site to be understandable.

    • Enum Constant Detail

      • UNSET

        public static final TriStateBoolean UNSET
        The option was never explicitly set by the user (neither true nor false).
      • FALSE

        public static final TriStateBoolean FALSE
        The option was explicitly set to false.
      • TRUE

        public static final TriStateBoolean TRUE
        The option was explicitly set to true.
    • Method Detail

      • values

        public static TriStateBoolean[] 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 (TriStateBoolean c : TriStateBoolean.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static TriStateBoolean 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 name
        NullPointerException - if the argument is null
      • isTrue

        public boolean isTrue()
        Whether this state represents an explicit, affirmative opt-in (TRUE).
      • isUnset

        public boolean isUnset()
        Whether the option was never explicitly set (UNSET).
      • fromNullableBoolean

        public static TriStateBoolean fromNullableBoolean​(Boolean value)
        Convert a nullable Boolean (the CLI/config-option convention where null means "not present in additionalProperties") into a TriStateBoolean.
        Parameters:
        value - null for unset, Boolean.TRUE/Boolean.FALSE for an explicit value
        Returns:
        UNSET, TRUE, or FALSE