Class Option.None

  • All Implemented Interfaces:
    Effect.Applicant<java.lang.Object>, Maybe<java.lang.Object>, java.io.Serializable, java.lang.Iterable<java.lang.Object>
    Enclosing class:
    Option<A>

    static final class Option.None
    extends Option<java.lang.Object>
    One of the big two actual implementation classes.
    Since:
    4.2.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static Option<java.lang.Object> NONE  
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      None()  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean contains​(java.lang.Object elem)
      Tests whether the option contains a given value as an element.
      <B> B fold​(java.util.function.Supplier<? extends B> none, java.util.function.Function<? super java.lang.Object,​? extends B> some)
      If this is a some value apply the some function, otherwise get the None value.
      void foreach​(Effect<? super java.lang.Object> effect)
      Deprecated.
      void forEach​(java.util.function.Consumer<? super java.lang.Object> effect)  
      java.lang.Object get()
      Get the value if defined.
      java.lang.Object getOrError​(java.util.function.Supplier<java.lang.String> err)
      Get the value or throws an error with the supplied message if not defined.
      <X extends java.lang.Throwable>
      java.lang.Object
      getOrThrow​(java.util.function.Supplier<X> ifUndefined)
      Get the value or throws the supplied throwable if not defined.
      boolean isDefined()
      If the type contains a value return true.
      private java.lang.Object readResolve()  
      java.util.Optional<java.lang.Object> toOptional()
      Create an Optional from this option.
      java.util.stream.Stream<java.lang.Object> toStream()
      Create a Stream from this option.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        spliterator
    • Field Detail

      • NONE

        private static final Option<java.lang.Object> NONE
    • Constructor Detail

      • None

        None()
    • Method Detail

      • fold

        public <B> B fold​(java.util.function.Supplier<? extends B> none,
                          java.util.function.Function<? super java.lang.Object,​? extends B> some)
        Description copied from class: Option
        If this is a some value apply the some function, otherwise get the None value.
        Specified by:
        fold in class Option<java.lang.Object>
        Type Parameters:
        B - the result type
        Parameters:
        none - the supplier of the None type
        some - the function to apply if this is a Some
        Returns:
        the appropriate value
      • get

        public java.lang.Object get()
        Description copied from interface: Maybe
        Get the value if defined. Throw an exception otherwise.
        Returns:
        the wrapped value
      • isDefined

        public boolean isDefined()
        Description copied from interface: Maybe
        If the type contains a value return true.
        Returns:
        true if this holds a value, false otherwise.
      • getOrError

        public java.lang.Object getOrError​(java.util.function.Supplier<java.lang.String> err)
        Description copied from interface: Maybe
        Get the value or throws an error with the supplied message if not defined.

        Used when absolutely sure this is defined.

        Parameters:
        err - the message for the error.
        Returns:
        the contained value.
      • getOrThrow

        public <X extends java.lang.Throwable> java.lang.Object getOrThrow​(java.util.function.Supplier<X> ifUndefined)
                                                                    throws X extends java.lang.Throwable
        Description copied from interface: Maybe
        Get the value or throws the supplied throwable if not defined.

        Used when absolutely sure this is defined.

        Type Parameters:
        X - exception type
        Parameters:
        ifUndefined - the supplier of the throwable.
        Returns:
        the contained value.
        Throws:
        X - the throwable the supplier creates if there is no value.
        X extends java.lang.Throwable
      • foreach

        @Deprecated
        public void foreach​(Effect<? super java.lang.Object> effect)
        Deprecated.
        Description copied from interface: Effect.Applicant
        Perform the given side-effect for each contained element.
        Parameters:
        effect - the input to use for performing the effect.
      • forEach

        public void forEach​(java.util.function.Consumer<? super java.lang.Object> effect)
      • toOptional

        public java.util.Optional<java.lang.Object> toOptional()
        Description copied from class: Option
        Create an Optional from this option. Will throw a NullPointerException if this option is defined and contains a null value.
        Specified by:
        toOptional in class Option<java.lang.Object>
        Returns:
        Optional.of(Object) with the value if defined and not null, Optional.empty() if not defined.
      • toStream

        public java.util.stream.Stream<java.lang.Object> toStream()
        Description copied from class: Option
        Create a Stream from this option.
        Specified by:
        toStream in class Option<java.lang.Object>
        Returns:
        Stream.of(Object) with the value if defined, Stream.empty() if not defined.
      • contains

        public boolean contains​(java.lang.Object elem)
        Description copied from interface: Maybe
        Tests whether the option contains a given value as an element.
        Parameters:
        elem - the element to test
        Returns:
        true if the option has an element that is equal to elem, false otherwise
      • readResolve

        private java.lang.Object readResolve()