- Type Parameters:
T- Type of the wrapped value.
- All Implemented Interfaces:
NullableOption<T>,Option<T>
Non-singleton implementation of NullableOption that must wrap a value
which may be null.
-
Field Summary
Fields inherited from class io.foxcapades.lib.opt.impl.FullOption
value -
Constructor Summary
ConstructorsConstructorDescriptionFullNullableOption(T value)Constructs a new option instance wrapping the given nullable value. -
Method Summary
Modifier and TypeMethodDescription@NotNull NullableOption<T>Calls the givenPredicateon the value wrapped by thisOption, if thisOptionis not empty.booleanisNull()Tests whether the wrapped value isnull.<R> @NotNull NullableOption<R>Calls the givenFunctionon the value wrapped by thisOptionif and only if thisOptionis not empty.<R> @NotNull NullableOption<R>Calls the givenFunctionifPresentif thisOptionis not empty, otherwise calls the givenSupplierifEmpty.@NotNull NonNullOption<T>Converts thisOptionto aNonNullOption.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.NullableOption
flatMap, flatMap, ifEmpty, ifPresent, isEmpty, isPresent, or, orElseThrow, orGet, orThrow, stream, unwrap, withMethods inherited from interface io.foxcapades.lib.opt.Option
valueEquals
-
Constructor Details
-
FullNullableOption
Constructs a new option instance wrapping the given nullable value.- Parameters:
value- Value to wrap.
-
-
Method Details
-
isNull
public boolean isNull()Description copied from interface:NullableOptionTests whether the wrapped value isnull.A return value of
truemeans that thisOptionis not empty and the value it wraps isnull.A return value of
falsemay mean either that thisOptionis empty, or that the wrapped value is notnull. To test if this is the case,NullableOption.isPresent()and/orNullableOption.isEmpty()should be used.- Specified by:
isNullin interfaceNullableOption<T>- Returns:
trueif thisOptionis both non-empty and is wrapping anullvalue.falseif this option is empty, or is not wrapping anullvalue.
-
map
@NotNull public <R> @NotNull NullableOption<R> map(@NotNull @NotNull Function<? super T,? extends R> fn)Description copied from interface:NullableOptionCalls the givenFunctionon the value wrapped by thisOptionif and only if thisOptionis not empty.IMPORTANT: Implementations of this interface allow wrapping
nullvalues. This means the givenFunctionshould be prepared to acceptnullvalues.The given
Functionmaynull.- Specified by:
mapin interfaceNullableOption<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.
-
map
@NotNull public <R> @NotNull NullableOption<R> map(@NotNull @NotNull Function<? super T,? extends R> ifPresent, @NotNull @NotNull Supplier<? extends R> ignored)Description copied from interface:NullableOptionCalls the givenFunctionifPresentif thisOptionis not empty, otherwise calls the givenSupplierifEmpty.IMPORTANT: Implementations of this interface allow wrapping
nullvalues. This means, if thisOptionis wrapping a null value, it will call theFunctionifPresent, passing in the wrappednullvalue. In this case,ifEmptywill not be called.The passed
FunctionifPresentmay returnnull, and should be prepared to accept a null input.If the called input function returns
null, the outputOptionwill be non-empty, wrapping anullvalue.- Specified by:
mapin interfaceNullableOption<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:NullableOptionCalls the givenPredicateon the value wrapped by thisOption, if thisOptionis not empty.The given
Predicatewill not be called if thisOptionis empty.If the given
Predicatereturnstrue, thisOptionwill be returned, otherwise an emptyOptionwill be returned.IMPORTANT: Implementations of this interface allow wrapping
nullvalues. This meansPredicatewill be called if theOptionis wrapping anullvalue, and will be passed the wrappednull.The given
Predicateshould be prepared to handle anullinput value.- Specified by:
filterin interfaceNullableOption<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.
-
toNonNullable
Description copied from interface:NullableOptionConverts thisOptionto aNonNullOption.The conversion happens as follows:
Option conversion rules. This Value Returns Not- nullNon-empty Optionwrapping thisOption's value.nullEmpty Optionempty Empty Option- Specified by:
toNonNullablein interfaceNullableOption<T>- Returns:
- A new
NonNullOptionwhich may be empty or non-empty based on the rules detailed above.
-