- Type Parameters:
T- Type of the wrapped value.
- All Implemented Interfaces:
NonNullOption<T>,Option<T>
Non singleton implementation of NonNullOption that must wrap a non
null value.
-
Field Summary
Fields inherited from class io.foxcapades.lib.opt.impl.FullOption
value -
Constructor Summary
ConstructorsConstructorDescriptionFullNonNullOption(T value)Constructs a new non-empty option wrapping a non-null value. -
Method Summary
Modifier and TypeMethodDescription@NotNull NonNullOption<T>Calls the givenPredicateon the value wrapped by thisOption, if thisOptionis not empty.<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.@NotNull NullableOption<T>Converts thisNonNullOptioninto an instance ofNullableOption.@NotNull NullableOption<T>toNullable(boolean emptyToNull)Converts thisNonNullOptioninto an instance ofNullableOption.Methods inherited from class io.foxcapades.lib.opt.impl.FullOption
flatMap, flatMap, ifEmpty, ifPresent, isEmpty, isPresent, or, orElseThrow, orGet, orThrow, stream, unwrap, valueEquals, withMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.foxcapades.lib.opt.NonNullOption
flatMap, flatMap, ifEmpty, ifPresent, isEmpty, isPresent, or, orElseThrow, orGet, orThrow, stream, unwrap, withMethods inherited from interface io.foxcapades.lib.opt.Option
valueEquals
-
Constructor Details
-
FullNonNullOption
Constructs a new non-empty option wrapping a non-null value.- Parameters:
value- Value to wrap.- Throws:
NullPointerException- if the given value isnull.
-
-
Method Details
-
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> ignored)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.ignored- Value supplier to call when thisOptionis empty.This argument must not be
null.- Returns:
- A new
Optionof generic typeR.
-
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.
-
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.
-