Class DoubleOptional<T1,T2>
java.lang.Object
io.github.syst3ms.skriptparser.util.DoubleOptional<T1,T2>
- Type Parameters:
T1- the type of the first valueT2- the type of the second value
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T1,T2> DoubleOptional <T1, T2> empty()Returns an emptyDoubleOptionalinstance.filter(BiPredicate<? super T1, ? super T2> predicate) If both values are present and match the given predicate, returns aDoubleOptionaldescribing these values, otherwise returns an emptyDoubleOptional.firstOrElse(T1 other) If the first value is present, returns it, otherwise returnsother.firstOrElseThrow(Supplier<? extends X> exceptionSupplier) If the first value is present, returns it, otherwise throws an exception produced by the given exception-supplying function.<U,V> DoubleOptional <U, V> flatMap(BiFunction<? super T1, ? super T2, DoubleOptional<? extends U, ? extends V>> mapper) If both values are present, returns the result of applying the givenDoubleOptional-returning mapping function to both values, and otherwise returns an emptyDoubleOptional.<U> Optional<U> flatMapToOptional(BiFunction<? super T1, ? super T2, Optional<? extends U>> mapper) getFirst()If the first value is present, returns the value, otherwise throws aNoSuchElementException.If the second value is present, returns the value, otherwise throws aNoSuchElementException.voidifPresent(BiConsumer<? super T1, ? super T2> action) If both values are present, does the given action using both values, otherwise does nothing.voidifPresentOrElse(BiConsumer<? super T1, ? super T2> action, Runnable emptyAction) If both values are present, does the first action using both values, otherwise does the second action.booleanisEmpty()If either values are absent, returnstrue, otherwisefalse.booleanIf both values are present, returnstrue, otherwisefalse.<U,V> DoubleOptional <U, V> If both values are present, returns aDoubleOptionaldescribing the result (as if byofNullable(Object, Object)) of applying each given mapping function to its respective value, and otherwise returns an emptyDoubleOptional.<U> Optional<U> mapToOptional(BiFunction<? super T1, ? super T2, ? extends U> mapper) static <T1,T2> DoubleOptional <T1, T2> of(T1 first, T2 second) Returns anOptionaldescribing the given non-nullvalue.static <T1,T2> DoubleOptional <T1, T2> ofNullable(T1 first, T2 second) Returns aDoubleOptionaldescribing the given values, if both non-null, otherwise returns an emptyDoubleOptional.static <T1,T2> DoubleOptional <T1, T2> ofOptional(Optional<T1> first, Optional<T2> second) Returns aDoubleOptionaldescribing the values represented by twoOptionals if both are present, otherwise returns an emptyDoubleOptional.or(Supplier<? extends DoubleOptional<? extends T1, ? extends T2>> supplier) If both values are present, returns aDoubleOptionaldescribing them, otherwise returns aDoubleOptionalobtained from the given supplier function.secondOrElse(T2 other) If the second value is present, returns it, otherwise returnsother.secondOrElseThrow(Supplier<? extends X> exceptionSupplier) If the second value is present, returns it, otherwise throws an exception produced by the given exception-supplying function.
-
Method Details
-
empty
Returns an emptyDoubleOptionalinstance.- Type Parameters:
T1- the type of the first non-existent valueT2- the type of the second non-existent value- Returns:
- an empty
DoubleOptional
-
of
Returns anOptionaldescribing the given non-nullvalue.- Type Parameters:
T1- the type of the first valueT2- the type fo the second value- Parameters:
first- the first value to describe, which must be non-nullsecond- the second value to describe, which must be non-null- Returns:
- a
DoubleOptionalwith the value present - Throws:
NullPointerException- if either first or second arenull
-
ofNullable
Returns aDoubleOptionaldescribing the given values, if both non-null, otherwise returns an emptyDoubleOptional.- Type Parameters:
T1- the type of the first valueT2- the type of the second value- Parameters:
first- the first possiblynullvalue to describesecond- the secpond possiblynullvalue to describe- Returns:
- a
DoubleOptionalwith both values present if the specified values are both non-null, otherwise an emptyDoubleOptional
-
ofOptional
Returns aDoubleOptionaldescribing the values represented by twoOptionals if both are present, otherwise returns an emptyDoubleOptional.- Type Parameters:
T1- the type of the first valueT2- the type of the second value- Parameters:
first- a possibly emptyOptionaldescribing the first valuesecond- a possibly emptyOptionaldescribing the second value- Returns:
- a
DoubleOptionaldescribing the two values described by the twoOptionals, if both are present, otherwise an emptyDoubleOptional
-
getFirst
If the first value is present, returns the value, otherwise throws aNoSuchElementException.- Returns:
- the non-null first value of this
DoubleOptional - Throws:
NoSuchElementException- if no first value is present
-
getSecond
If the second value is present, returns the value, otherwise throws aNoSuchElementException.- Returns:
- the non-null second value of this
DoubleOptional - Throws:
NoSuchElementException- if no second value is present
-
isPresent
public boolean isPresent()If both values are present, returnstrue, otherwisefalse.- Returns:
trueif both values are present, otherwisefalse.
-
isEmpty
public boolean isEmpty()If either values are absent, returnstrue, otherwisefalse.- Returns:
trueif either values are absent, otherwisefalse
-
ifPresent
If both values are present, does the given action using both values, otherwise does nothing.- Parameters:
action- the action to be performed if both values are present
-
ifPresentOrElse
If both values are present, does the first action using both values, otherwise does the second action.- Parameters:
action- the action to be performed if both values are presentemptyAction- the action to be performed if either values are absent
-
filter
If both values are present and match the given predicate, returns aDoubleOptionaldescribing these values, otherwise returns an emptyDoubleOptional.- Parameters:
predicate- the predicate to test both values against, if present- Returns:
- a
DoubleOptionaldescribing these values, if they are present and match the given predicate, otherwise an emptyDoubleOptional
-
map
public <U,V> DoubleOptional<U,V> map(Function<? super T1, ? extends U> firstMapper, Function<? super T2, ? extends V> secondMapper) If both values are present, returns aDoubleOptionaldescribing the result (as if byofNullable(Object, Object)) of applying each given mapping function to its respective value, and otherwise returns an emptyDoubleOptional. If either mapping function returnsnull, the result will be an emptyDoubleOptional.- Type Parameters:
U- the new type of the first valueV- the new type of the second value- Parameters:
firstMapper- the mapping function to apply to the first value, if presentsecondMapper- the mapping function to apply to the second value, if present- Returns:
- a
DoubleOptionaldescribing the result of applying mapping functions to each of the values if present, and an emptyDoubleOptionalotherwise.
-
mapToOptional
-
flatMap
public <U,V> DoubleOptional<U,V> flatMap(BiFunction<? super T1, ? super T2, DoubleOptional<? extends U, ? extends V>> mapper) If both values are present, returns the result of applying the givenDoubleOptional-returning mapping function to both values, and otherwise returns an emptyDoubleOptional. This is similar tomap(Function, Function), but it doesn't wrap the result in an additionalDoubleOptional.- Type Parameters:
U- the type of the first value of the newDoubleOptionalV- the type of the second value of the newDoubleOptional- Parameters:
mapper- the mapping function taking in both values (if present) and returning aDoubleOptional- Returns:
- the result of applying the mapping function to both values if present, and an empty
DoubleOptionalotherwise - Throws:
NullPointerException- if the mapping function returnsnull
-
flatMapToOptional
public <U> Optional<U> flatMapToOptional(BiFunction<? super T1, ? super T2, Optional<? extends U>> mapper) If both values are present, returns the result of applying the givenOptional-returning mapping function to both values, and otherwise returns an emptyOptional. This is similar tomapToOptional(BiFunction), but it doesn't wrap the result in an additionalOptional.- Type Parameters:
U- the type of the newOptional- Parameters:
mapper- the mapping function taking in both values (if present) and returning anOptional- Returns:
- the result of applying the mapping function to both values if present, and an empty
Optionalotherwise - Throws:
NullPointerException- if the mapping function returnsnull
-
or
public DoubleOptional<T1,T2> or(Supplier<? extends DoubleOptional<? extends T1, ? extends T2>> supplier) If both values are present, returns aDoubleOptionaldescribing them, otherwise returns aDoubleOptionalobtained from the given supplier function.- Parameters:
supplier- the supplier producing theDoubleOptionalreturned if this one is empty- Returns:
- a
DoubleOptionaldescribing the two values if present, and otherwise theDoubleOptionalproduced by the given supplier function
-
firstOrElse
-
secondOrElse
-
firstOrElseThrow
If the first value is present, returns it, otherwise throws an exception produced by the given exception-supplying function.- Type Parameters:
X- the type of exception that may be thrown- Parameters:
exceptionSupplier- the function producing the exception to be thrown if the first value is not present- Returns:
- the first value if present
- Throws:
X- if the first value is not present
-
secondOrElseThrow
If the second value is present, returns it, otherwise throws an exception produced by the given exception-supplying function.- Type Parameters:
X- the type of exception that may be thrown- Parameters:
exceptionSupplier- the function producing the exception to be thrown if the second value is not present- Returns:
- the second value if present
- Throws:
X- if the second value is not present
-