Class None<T>

java.lang.Object
org.storynode.pigeon.option.Option<T>
org.storynode.pigeon.option.None<T>
All Implemented Interfaces:
SafelyWrapped<T>, Wrapped<T>

public class None<T> extends Option<T>
Represents an Option with no value
Author:
Andrea Coronese
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final Option<?>
    Constant INSTANCE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates an option with no value in it
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    filter(Predicate<? super T> predicate)
    If a value is present, and the value matches the given predicate, returns an Option describing the value, otherwise returns an empty Option.
    <U> Option<U>
    flatMap(Function<? super T,? extends Option<? extends U>> mapper)
    If a value is present, returns the result of applying the given Optional-bearing mapping function to the value, otherwise returns an empty Optional.
    int
    void
    Executes func if this is Some, consuming the contained value.
    void
    ifPresentOrElse(Consumer<T> whenPresent, @NotNull Runnable otherwise)
    Executes whenPresent if this is Some, consuming the contained value, or runs otherwise if this is None
    boolean
    Whether this option contains a value or not
    <U> Option<U>
    map(@NotNull Function<T,U> mapper)
    If a value is present, returns an Option describing (as if by Option.some(T)) the result of applying the given mapping function to the value, otherwise returns an empty Option.
    Option<? extends T>
    or(@NotNull Supplier<? extends Option<? extends T>> supplier)
    If a value is present, returns an Option describing the value, otherwise returns an Option produced by the given supplying function
    orElse(T other)
    If a value is present, returns the value, otherwise returns other.
    orElseGet(@NotNull Supplier<T> supplier)
    If a value is present, returns the value, otherwise returns the result produced by the supplying function.
    If a value is present returns that value, otherwise throws NoSuchElementException.
    <E extends Throwable>
    T
    orElseThrow(@NotNull Supplier<E> throwable)
    If a value is present returns that value, otherwise throws the supplied Throwable.
    Streams the contained value, if any.
    Gets the wrapped value.

    Methods inherited from class org.storynode.pigeon.option.Option

    isNone, none, of, of, some

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.storynode.pigeon.protocol.SafelyWrapped

    tryUnwrap
  • Field Details

    • INSTANCE

      protected static final Option<?> INSTANCE
      Constant INSTANCE
  • Constructor Details

    • None

      protected None()
      Creates an option with no value in it
  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isSome

      public boolean isSome()
      Whether this option contains a value or not
      Specified by:
      isSome in class Option<T>
      Returns:
      true if this contains a value, false otherwise
      See Also:
    • ifPresent

      public void ifPresent(Consumer<T> func)
      Executes func if this is Some, consuming the contained value.
      Specified by:
      ifPresent in class Option<T>
      Parameters:
      func - The function to execute
    • ifPresentOrElse

      public void ifPresentOrElse(Consumer<T> whenPresent, @NotNull @NotNull Runnable otherwise)
      Executes whenPresent if this is Some, consuming the contained value, or runs otherwise if this is None
      Specified by:
      ifPresentOrElse in class Option<T>
      Parameters:
      whenPresent - The function to execute if this is Some
      otherwise - The function to execute if this is None
    • filter

      public Option<T> filter(Predicate<? super T> predicate)
      If a value is present, and the value matches the given predicate, returns an Option describing the value, otherwise returns an empty Option.
      Specified by:
      filter in class Option<T>
      Parameters:
      predicate - the predicate to apply to a value, if present
      Returns:
      an Option describing the value of this Option, if a value is present and the value matches the given predicate, otherwise an empty Option
    • map

      public <U> Option<U> map(@NotNull @NotNull Function<T,U> mapper)
      If a value is present, returns an Option describing (as if by Option.some(T)) the result of applying the given mapping function to the value, otherwise returns an empty Option.

      If the mapping function returns a null result then this method returns an empty Option.

      Specified by:
      map in class Option<T>
      Type Parameters:
      U - The type of the value returned from the mapping function
      Parameters:
      mapper - the mapping function to apply to a value, if present
      Returns:
      an Option describing the result of applying a mapping function to the value of this Option, if a value is present, otherwise an empty Option
    • flatMap

      public <U> Option<U> flatMap(Function<? super T,? extends Option<? extends U>> mapper)
      If a value is present, returns the result of applying the given Optional-bearing mapping function to the value, otherwise returns an empty Optional.

      This method is similar to Option.map(Function), but the mapping function is one whose result is already an Optional, and if invoked, flatMap does not wrap it within an additional Optional.

      Specified by:
      flatMap in class Option<T>
      Type Parameters:
      U - The type of value of the Optional returned by the mapping function
      Parameters:
      mapper - the mapping function to apply to a value, if present
      Returns:
      the result of applying an Optional-bearing mapping function to the value of this Optional, if a value is present, otherwise an empty Optional
    • or

      public Option<? extends T> or(@NotNull @NotNull Supplier<? extends Option<? extends T>> supplier)
      If a value is present, returns an Option describing the value, otherwise returns an Option produced by the given supplying function
      Specified by:
      or in class Option<T>
      Parameters:
      supplier - The supplier that produces the Option in case a value is not present in this
      Returns:
      An Option with the value of this, if any is present, or another Option supplied by the provided supplying function
    • orElseGet

      public T orElseGet(@NotNull @NotNull Supplier<T> supplier)
      If a value is present, returns the value, otherwise returns the result produced by the supplying function.
      Specified by:
      orElseGet in class Option<T>
      Parameters:
      supplier - the supplying function that produces a value to be returned
      Returns:
      the value, if present, otherwise the result produced by the supplying function
    • orElse

      public T orElse(T other)
      If a value is present, returns the value, otherwise returns other.
      Specified by:
      orElse in class Option<T>
      Parameters:
      other - the value to be returned, if no value is present. May be null.
      Returns:
      the value, if present, otherwise other
    • orElseThrow

      public T orElseThrow() throws NoSuchElementException
      If a value is present returns that value, otherwise throws NoSuchElementException.

      Please note that this is mainly for API compatibility with Optional but should be avoided in favour of Option.orElse(Object) and Option.orElseGet(Supplier)

      Specified by:
      orElseThrow in class Option<T>
      Returns:
      The contained value, if present
      Throws:
      NoSuchElementException - When the option is None
    • orElseThrow

      public <E extends Throwable> T orElseThrow(@NotNull @NotNull Supplier<E> throwable) throws E
      If a value is present returns that value, otherwise throws the supplied Throwable.

      Please note that this is mainly for API compatibility with Optional but should be avoided in favour of Option.orElse(Object) and Option.orElseGet(Supplier)

      Specified by:
      orElseThrow in class Option<T>
      Type Parameters:
      E - The concrete type of the Throwable
      Parameters:
      throwable - The function that supplies the exception to throw
      Returns:
      a T object
      Throws:
      E - if any.
    • stream

      public Stream<T> stream()
      Streams the contained value, if any.
      Specified by:
      stream in class Option<T>
      Returns:
      a Stream object
    • unwrap

      public T unwrap() throws UnwrapException
      Gets the wrapped value. This method is allowed to throw a UnwrapException if the specific implementors requires so.

      Gets the wrapped value. This method is allowed to throw a UnwrapException if the specific implementors requires so.
      If you need a non-throwing version of unwrap use tryUnwrap.

      Returns:
      The wrapped value
      Throws:
      UnwrapException - if any.
      See Also: