Class OptBool


  • public final class OptBool
    extends java.lang.Object
    Utility for working with Optional<Boolean>s.

    This also saves memory by holding three static instances of Optional<Boolean>, which represents the possible states it can have.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Optional<java.lang.Boolean> EMPTY
      The absent value.
      static java.util.Optional<java.lang.Boolean> FALSE
      The false value.
      static java.util.Optional<java.lang.Boolean> TRUE
      The true value.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Optional<java.lang.Boolean> of​(boolean bool)
      Constructs a new Optional<Boolean> from the given boolean.
      static java.util.Optional<java.lang.Boolean> of​(@Nullable java.lang.Boolean bool)
      Constructs a new Optional<Boolean> from the given Boolean.
      static java.util.Optional<java.lang.Boolean> of​(java.util.Optional<java.lang.Boolean> bool)
      Coerces the given Optional<Boolean> into one of the three stored states.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TRUE

        public static final java.util.Optional<java.lang.Boolean> TRUE
        The true value.
      • FALSE

        public static final java.util.Optional<java.lang.Boolean> FALSE
        The false value.
      • EMPTY

        public static final java.util.Optional<java.lang.Boolean> EMPTY
        The absent value.

        Also a shorthand for constructing instances with Optional.<Boolean>empty().

    • Method Detail

      • of

        public static java.util.Optional<java.lang.Boolean> of​(boolean bool)
        Constructs a new Optional<Boolean> from the given boolean.
        Parameters:
        bool - The boolean
        Returns:
        The constructed Optional
      • of

        public static java.util.Optional<java.lang.Boolean> of​(@Nullable java.lang.Boolean bool)
        Constructs a new Optional<Boolean> from the given Boolean.
        Parameters:
        bool - The boolean
        Returns:
        The constructed Optional, or Optional.empty()
      • of

        public static java.util.Optional<java.lang.Boolean> of​(java.util.Optional<java.lang.Boolean> bool)
        Coerces the given Optional<Boolean> into one of the three stored states.
        Parameters:
        bool - The boolean
        Returns:
        The constructed Optional, or Optional.empty()