Package org.storynode.pigeon.option
Class None<T>
java.lang.Object
org.storynode.pigeon.option.Option<T>
org.storynode.pigeon.option.None<T>
- All Implemented Interfaces:
Wrapped<T>
Represents an
Option with no value- Author:
- Andrea Coronese
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean<U> Option<U> If a value is present, returns the result of applying the givenOptional-bearing mapping function to the value, otherwise returns an emptyOptional.inthashCode()voidExecutesfuncif this isSome, consuming the contained value.voidifPresentOrElse(Consumer<T> whenPresent, @NotNull Runnable otherwise) booleanisSome()Whether this option contains a value or not<U> Option<U> If a value is present, returns anOptiondescribing (as if byOption.some(T)) the result of applying the given mapping function to the value, otherwise returns an emptyOption.If a value is present, returns the value, otherwise returnsother.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 throwsNoSuchElementException.orElseThrow(@NotNull Supplier<E> throwable) If a value is present returns that value, otherwise throws the suppliedThrowable.stream()stream.toString()unwrap()Gets the wrapped value.
-
Constructor Details
-
None
protected None()Creates an option with no value in it
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
toString
-
isSome
public boolean isSome()Whether this option contains a value or not -
ifPresent
Executesfuncif this isSome, consuming the contained value. -
ifPresentOrElse
ExecuteswhenPresentif this isSome, consuming the contained value, or runsotherwiseif this isNone- Specified by:
ifPresentOrElsein classOption<T>- Parameters:
whenPresent- The function to execute if this isSomeotherwise- The function to execute if this isNone
-
map
If a value is present, returns anOptiondescribing (as if byOption.some(T)) the result of applying the given mapping function to the value, otherwise returns an emptyOption.If the mapping function returns a
nullresult then this method returns an emptyOption.- Specified by:
mapin classOption<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
Optiondescribing the result of applying a mapping function to the value of thisOption, if a value is present, otherwise an emptyOption
-
flatMap
If a value is present, returns the result of applying the givenOptional-bearing mapping function to the value, otherwise returns an emptyOptional.This method is similar to
Option.map(Function), but the mapping function is one whose result is already anOptional, and if invoked,flatMapdoes not wrap it within an additionalOptional.- Specified by:
flatMapin classOption<T>- Type Parameters:
U- The type of value of theOptionalreturned 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 thisOptional, if a value is present, otherwise an emptyOptional
-
orElseGet
If a value is present, returns the value, otherwise returns the result produced by the supplying function. -
orElse
If a value is present, returns the value, otherwise returnsother. -
orElseThrow
If a value is present returns that value, otherwise throwsNoSuchElementException.
Please note that this is mainly for API compatibility with
Optionalbut should be avoided in favour ofOption.orElse(Object)andOption.orElseGet(Supplier)- Specified by:
orElseThrowin classOption<T>- Returns:
- The contained value, if present
- Throws:
NoSuchElementException- When the option isNone
-
orElseThrow
If a value is present returns that value, otherwise throws the suppliedThrowable.
Please note that this is mainly for API compatibility with
Optionalbut should be avoided in favour ofOption.orElse(Object)andOption.orElseGet(Supplier)- Specified by:
orElseThrowin classOption<T>- Type Parameters:
E- The concrete type of theThrowable- Parameters:
throwable- The function that supplies the exception to throw- Returns:
- a T object
- Throws:
E- if any.
-
stream
stream. -
unwrap
Gets the wrapped value. This method is allowed to throw aUnwrapExceptionif the specific implementors requires so.- Returns:
- The wrapped value
- Throws:
UnwrapException- if any.
-