- Type Parameters:
T- Generic type of this option.
- All Implemented Interfaces:
NonNullOption<T>,Option<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether some other object is "equal to" this one.@NotNull NonNullOption<T>Calls the givenPredicateon the value wrapped by thisOption, if thisOptionis not empty.<R> @NotNull Option<R>Calls the givenFunctionif thisOptionis not empty.<R> @NotNull Option<R>flatMap(@NotNull Function<? super T,? extends Option<? extends R>> ifPresent, @NotNull Supplier<? extends Option<? extends R>> ifEmpty)Calls the given mappingFunctionifPresentif thisOptionis not empty, otherwise calls the givenSupplierifEmpty.inthashCode()Returns a hash code value for this object.@NotNull NonNullOption<T>Executes the givenRunnableif and only if thisOptionis empty.@NotNull NonNullOption<T>Executes the givenConsumerwith the value wrapped by thisOptionif thisOptionis not empty.static <T> NonNullOption<T>instance()Returns the singletonEmptyNonNullinstance.booleanisEmpty()Tests whether thisOptiondoes not contain a value.booleanTests whether thisOptioncontains a value.<R> @NotNull NonNullOption<R>Calls the givenFunctionon the value wrapped by thisOptionif and only if thisOptionis not empty.<R> @NotNull NonNullOption<R>Calls the givenFunctionifPresentif thisOptionis not empty, otherwise calls the givenSupplierifEmpty.Returns either the value wrapped by thisOption, if it is not empty, or the given value if thisOptionis empty.orElseThrow(@NotNull Supplier<? extends E> fn)Returns the value wrapped by thisOptionif it is not empty, otherwise throws theExceptionreturned by the givenSupplier.Returns either the value wrapped by thisOption, if it is not empty, or the value returned by the givenSupplier.orThrow(E err)Returns the value wrapped by thisOptionif it is not empty, otherwise throws the givenExceptionvalue.stream()Creates a newStreamcontaining either one value, if thisOptionis not empty, or containing zero values if thisOptionis empty.@NotNull NullableOption<T>Converts thisNonNullOptioninto an instance ofNullableOption.@NotNull NullableOption<T>toNullable(boolean emptyToNull)Converts thisNonNullOptioninto an instance ofNullableOption.toString()Returns a string representation of this record class.unwrap()Attempts to unwrap thisOption's value.booleanvalueEquals(@Nullable Object value)Returns whether the value wrapped by this option equals the given input value.@NotNull NonNullOption<T>Executes the givenConsumerifPresenton the wrapped value if thisOptionis not empty, otherwise calls the givenRunnableifEmpty.
-
Constructor Details
-
EmptyNonNull
public EmptyNonNull()Creates an instance of aEmptyNonNullrecord class.
-
-
Method Details
-
instance
Returns the singletonEmptyNonNullinstance.- Type Parameters:
T- Generic type of the returned option.- Returns:
- The singleton
EmptyNonNullinstance.
-
isPresent
public boolean isPresent()Description copied from interface:NonNullOptionTests whether thisOptioncontains a value.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues. -
isEmpty
public boolean isEmpty()Description copied from interface:NonNullOptionTests whether thisOptiondoes not contain a value.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues. -
unwrap
Description copied from interface:NonNullOptionAttempts to unwrap thisOption's value. If this option is empty, this method throws anUnwrapException.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues.- Specified by:
unwrapin interfaceNonNullOption<T>- Specified by:
unwrapin interfaceOption<T>- Returns:
- The value wrapped by this
Option. - Throws:
UnwrapException- If this method is called on an emptyOption.
-
or
Description copied from interface:NonNullOptionReturns either the value wrapped by thisOption, if it is not empty, or the given value if thisOptionis empty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues. -
orGet
Description copied from interface:NonNullOptionReturns either the value wrapped by thisOption, if it is not empty, or the value returned by the givenSupplier.The given
Supplierwill not be called if thisOptionis not empty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues.- Specified by:
orGetin interfaceNonNullOption<T>- Specified by:
orGetin interfaceOption<T>- Parameters:
fn-Supplierfor the fallback value.This argument must not be null.
The value returned by the given
Suppliermay be null.- Returns:
- Either the value wrapped by this
Option, or the value returned by the givenSupplier.
-
orThrow
Description copied from interface:NonNullOptionReturns the value wrapped by thisOptionif it is not empty, otherwise throws the givenExceptionvalue.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues.- Specified by:
orThrowin interfaceNonNullOption<T>- Specified by:
orThrowin interfaceOption<T>- Type Parameters:
E- Type of theExceptionvalue that will be thrown if thisOptionis empty.- Parameters:
err-Exceptionto throw if thisOptionis empty.This argument must not be null.
- Returns:
- The value wrapped by this
Option. Individual implementations decide whethernullvalues may be wrapped and returned. - Throws:
E- Thrown if thisOptionis empty.
-
orElseThrow
Description copied from interface:NonNullOptionReturns the value wrapped by thisOptionif it is not empty, otherwise throws theExceptionreturned by the givenSupplier.The given
Supplierwill not be called if thisOptionis not empty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues.- Specified by:
orElseThrowin interfaceNonNullOption<T>- Specified by:
orElseThrowin interfaceOption<T>- Type Parameters:
E- Type of the exception that will be returned by the givenSupplierand thrown.- Parameters:
fn-Supplierfor theExceptionto throw if thisOptionis empty.This argument must not be
null.This
Suppliermust not returnnull.- Returns:
- The value wrapped by this
Option. - Throws:
E- If thisOptionis empty.
-
map
@NotNull public <R> @NotNull NonNullOption<R> map(@NotNull @NotNull Function<? super T,? extends R> fn)Description copied from interface:NonNullOptionCalls the givenFunctionon the value wrapped by thisOptionif and only if thisOptionis not empty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues.If the given function returns
nullan emptyOptionwill be returned. If the given function does not returnnulla newOptionwill be returned wrapping the result value of the call to the givenFunction.- Specified by:
mapin interfaceNonNullOption<T>- Specified by:
mapin interfaceOption<T>- Type Parameters:
R- The return type of the given mappingFunction.- Parameters:
fn- Function to call on the value wrapped by thisOption.This argument must not be
null- Returns:
- A new
Optionof generic typeR. ThisOptionwill be empty if the return value offnwasnull, otherwise the returnedOptionwill be wrapping the value returned by the givenFunction.
-
map
@NotNull public <R> @NotNull NonNullOption<R> map(@NotNull @NotNull Function<? super T,? extends R> ifPresent, @NotNull @NotNull Supplier<? extends R> ifEmpty)Description copied from interface:NonNullOptionCalls the givenFunctionifPresentif thisOptionis not empty, otherwise calls the givenSupplierifEmpty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues.- Specified by:
mapin interfaceNonNullOption<T>- Specified by:
mapin interfaceOption<T>- Type Parameters:
R- Generic type of the returnedOption.- Parameters:
ifPresent- Mapping function to call on the value wrapped by thisOption.This argument must not be
null.This function will only be called if this
Optionis not empty.ifEmpty- Value supplier to call when thisOptionis empty.This argument must not be
null.- Returns:
- A new
Optionof generic typeR.
-
flatMap
@NotNull public <R> @NotNull Option<R> flatMap(@NotNull @NotNull Function<? super T,? extends Option<? extends R>> fn)Description copied from interface:NonNullOptionCalls the givenFunctionif thisOptionis not empty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues.- Specified by:
flatMapin interfaceNonNullOption<T>- Specified by:
flatMapin interfaceOption<T>- Type Parameters:
R- Generic type of the returnedOption.- Parameters:
fn- Mapping function to call if thisOptionis not empty.This argument must not be null.
This function must not return null
This function will not be called if this
Optionis empty.- Returns:
- A new
Optionof generic typeR.
-
flatMap
@NotNull public <R> @NotNull Option<R> flatMap(@NotNull @NotNull Function<? super T,? extends Option<? extends R>> ifPresent, @NotNull @NotNull Supplier<? extends Option<? extends R>> ifEmpty)Description copied from interface:NonNullOptionCalls the given mappingFunctionifPresentif thisOptionis not empty, otherwise calls the givenSupplierifEmpty. IMPORTANT: Implementations of this interface do not allow wrappingnullvalues.- Specified by:
flatMapin interfaceNonNullOption<T>- Specified by:
flatMapin interfaceOption<T>- Type Parameters:
R- Generic type for the returnedOption.- Parameters:
ifPresent- Mapping function to call if thisOptionis not empty.This argument must not be
null.This function must not return
null.ifEmpty- Supplier function to call if thisOptionis empty.This argument must not be null.
This value must not return null.
- Returns:
- A new
Optionof generic typeR.
-
stream
Description copied from interface:NonNullOptionCreates a newStreamcontaining either one value, if thisOptionis not empty, or containing zero values if thisOptionis empty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues. -
ifPresent
Description copied from interface:NonNullOptionExecutes the givenConsumerwith the value wrapped by thisOptionif thisOptionis not empty.The given function will not be called if this
Optionis empty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues. -
ifEmpty
Description copied from interface:NonNullOptionExecutes the givenRunnableif and only if thisOptionis empty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues. -
with
@NotNull public @NotNull NonNullOption<T> with(@NotNull @NotNull Consumer<? super T> ifPresent, @NotNull @NotNull Runnable ifEmpty)Description copied from interface:NonNullOptionExecutes the givenConsumerifPresenton the wrapped value if thisOptionis not empty, otherwise calls the givenRunnableifEmpty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues.- Specified by:
within interfaceNonNullOption<T>- Specified by:
within interfaceOption<T>- Parameters:
ifPresent-Consumerto call with the value wrapped by thisOptionif thisOptionis not empty.This argument must not be null.
ifEmpty-Runnableto call if thisOptionis empty.This argument must not be null.
- Returns:
- This
Optioninstance.
-
filter
Description copied from interface:NonNullOptionCalls the givenPredicateon the value wrapped by thisOption, if thisOptionis not empty.IMPORTANT: Implementations of this interface do not allow wrapping
nullvalues.- Specified by:
filterin interfaceNonNullOption<T>- Specified by:
filterin interfaceOption<T>- Parameters:
fn-Predicateto apply to the value wrapped by thisOptionif thisOptionis not empty.This value must not be null.
- Returns:
- This
Optionif the givenPredicatereturnstrue, otherwise an emptyOption.
-
valueEquals
Description copied from interface:OptionReturns whether the value wrapped by this option equals the given input value.For empty options, this method will always return
false.- Specified by:
valueEqualsin interfaceOption<T>- Parameters:
value- Value to compare against the wrapped value.- Returns:
- Whether the given value equals the value wrapped by this option.
If this option is empty, this value will always be
false. If this option allowsnullvalues and is wrapping anullvalue, this method will only returntrueif the given input is alsonull.
-
toNullable
Description copied from interface:NonNullOptionConverts thisNonNullOptioninto an instance ofNullableOption.If the current
Optionis empty, the returnedOptionwill also be empty.This method is equivalent to calling
toNullable(false).- Specified by:
toNullablein interfaceNonNullOption<T>- Returns:
- A
NullableOptionthat is either empty or wrapping the same value as thisOption.
-
toNullable
Description copied from interface:NonNullOptionConverts thisNonNullOptioninto an instance ofNullableOption.If the current option is not empty, the returned
Optionwill wrap the same value as thisOption.If the current option is empty, either a new
NullableOptionwrappingnullor an emptyOptionwill be returned depending on the value ofemptyToNull.If
emptyToNull == true && this.isEmpty(), then aNullableOptionthat is not-empty, wrapping the valuenullwill be returned.If
emptyToNull == false && this.isEmpty(), then an empty option will be returned.- Specified by:
toNullablein interfaceNonNullOption<T>- Parameters:
emptyToNull- Flag indicating whether an empty option instance should be converted to a null wrapping option or an empty option.- Returns:
- A new option that will be wrapping this option's value, null, or will be empty.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal.
-