Enum TriState

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<TriState>

    public enum TriState
    extends java.lang.Enum<TriState>
    Similar to a boolean but with three states.
    Since:
    4.8.0
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      FALSE
      State describing a false value.
      NOT_SET
      State describing the absence of a value.
      TRUE
      State describing a true value.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static @NotNull TriState byBoolean​(boolean value)
      Gets a state from a boolean.
      static @NotNull TriState byBoolean​(@Nullable java.lang.Boolean value)
      Gets a state from a Boolean.
      @Nullable java.lang.Boolean toBoolean()
      Converts this tri-state back into a Boolean.
      boolean toBooleanOrElse​(boolean other)
      Converts this tri-state back into a boolean.
      boolean toBooleanOrElseGet​(@NotNull java.util.function.BooleanSupplier supplier)
      Converts this tri-state back into a boolean.
      static TriState valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static TriState[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • NOT_SET

        public static final TriState NOT_SET
        State describing the absence of a value.
        Since:
        4.8.0
      • FALSE

        public static final TriState FALSE
        State describing a false value.
        Since:
        4.8.0
      • TRUE

        public static final TriState TRUE
        State describing a true value.
        Since:
        4.8.0
    • Method Detail

      • values

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

        public static TriState valueOf​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • toBoolean

        @Nullable
        public @Nullable java.lang.Boolean toBoolean()
        Converts this tri-state back into a Boolean.
        Returns:
        the boolean representing this tri-state. NOT_SET will be represented by null.
        Since:
        4.10.0
      • toBooleanOrElse

        public boolean toBooleanOrElse​(boolean other)
        Converts this tri-state back into a boolean.

        As the NOT_SET state cannot be represented by the boolean type, this method maps the NOT_SET state to other passed boolean value. This method may hence also be viewed as an equivalent to Optional.orElse(Object).

        Parameters:
        other - the boolean value that should be returned if this tri-state is NOT_SET.
        Returns:
        the boolean representing the tri-state or the boolean passed if this state is NOT_SET.
        Since:
        4.10.0
      • toBooleanOrElseGet

        public boolean toBooleanOrElseGet​(@NotNull
                                          @NotNull java.util.function.BooleanSupplier supplier)
        Converts this tri-state back into a boolean.

        As the NOT_SET state cannot be represented by the boolean type, this method maps the NOT_SET state to the suppliers result. This method may hence also be viewed as an equivalent to Optional.orElseGet(java.util.function.Supplier).

        Parameters:
        supplier - the supplier that will be executed to produce the value that should be returned if this tri-state is NOT_SET.
        Returns:
        the boolean representing the tri-state or the result of the passed supplier if this state is NOT_SET.
        Since:
        4.10.0
      • byBoolean

        @NotNull
        public static @NotNull TriState byBoolean​(boolean value)
        Gets a state from a boolean.
        Parameters:
        value - the boolean
        Returns:
        a tri-state
        Since:
        4.8.0
      • byBoolean

        @NotNull
        public static @NotNull TriState byBoolean​(@Nullable
                                                  @Nullable java.lang.Boolean value)
        Gets a state from a Boolean.
        Parameters:
        value - the boolean
        Returns:
        a tri-state
        Since:
        4.8.0