Package com.minecolonies.api.util
Interface OptionalPredicate<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A predicate that can return success, failure, or undetermined.
-
Method Summary
Modifier and TypeMethodDescriptiondefault @NotNull OptionalPredicate<T> and(@NotNull OptionalPredicate<T> other) Performs the logical AND on two optional predicates, such that: - if both sides are empty, the result is empty - if one side is empty, the result is the other side - if both sides are non-empty, the result is the logical AND - if the left side is false, the right side is not evaluated (short circuit)default @NotNull OptionalPredicate<T> combine(@NotNull OptionalPredicate<T> other) If this predicate fails to produce a result, tries the next one instead.static <X> Optional<X> Combines two optional values, with short-circuiting.static <T> @NotNull OptionalPredicate<T> empty()A predicate that always returns empty.static <T> @NotNull OptionalPredicate<T> Convert the given predicate into an optional failure.default @NotNull OptionalPredicate<T> negate()Negates the predicate -- where the original returns true, this returns false, and vice versa.static <T> @NotNull OptionalPredicate<T> Creates a non-empty optional predicate.default @NotNull OptionalPredicate<T> or(@NotNull OptionalPredicate<T> other) Performs the logical OR on two optional predicates, such that: - if both sides are empty, the result is empty - if one side is empty, the result is the other side - if both sides are non-empty, the result is the logical OR - if the left side is true, the right side is not evaluated (short circuit)orElse(boolean fallback) Turns an OptionalPredicate into a regularPredicateby providing a default value returned when empty.static <T> @NotNull OptionalPredicate<T> Convert the given predicate into an optional success.Evaluates this predicate on the given argument.
-
Method Details
-
test
Evaluates this predicate on the given argument.- Parameters:
t- the input argument- Returns:
- true, false, or empty
-
empty
A predicate that always returns empty.- Type Parameters:
T- the input type- Returns:
- empty
-
of
Creates a non-empty optional predicate.- Type Parameters:
T- the input type- Parameters:
predicate- the input predicate- Returns:
- a non-empty optional predicate
-
passIf
Convert the given predicate into an optional success.- Type Parameters:
T- the input type- Parameters:
predicate- the input predicate- Returns:
- a predicate which returns true if the input predicate returns true, or empty if the input predicate returns false.
-
failIf
Convert the given predicate into an optional failure.- Type Parameters:
T- the input type- Parameters:
predicate- the input predicate- Returns:
- a predicate which returns false if the input predicate returns true, or empty if the input predicate returns false.
-
orElse
Turns an OptionalPredicate into a regularPredicateby providing a default value returned when empty.- Parameters:
fallback- the value to return when empty- Returns:
- a predicate that returns the original or fallback result
-
combine
@NotNull default @NotNull OptionalPredicate<T> combine(@NotNull @NotNull OptionalPredicate<T> other) If this predicate fails to produce a result, tries the next one instead.- Parameters:
other- the other predicate to try- Returns:
- the result from this predicate, or the result of the other if this returns empty
-
combine
static <X> Optional<X> combine(@NotNull @NotNull Optional<X> a, @NotNull @NotNull Supplier<Optional<X>> b) Combines two optional values, with short-circuiting. Similar toOptional.orElseGet(Supplier)except that the final result may still be empty.- Type Parameters:
X- the value type- Parameters:
a- the first optional valueb- a supplier to calculate the second optional value- Returns:
- the first value, if present; otherwise calculates and returns the second value
-
negate
Negates the predicate -- where the original returns true, this returns false, and vice versa. The empty result does not change.- Returns:
- the negated predicate.
-
and
Performs the logical AND on two optional predicates, such that: - if both sides are empty, the result is empty - if one side is empty, the result is the other side - if both sides are non-empty, the result is the logical AND - if the left side is false, the right side is not evaluated (short circuit)- Parameters:
other- the other optional predicate- Returns:
- the logical AND of both predicates
-
or
Performs the logical OR on two optional predicates, such that: - if both sides are empty, the result is empty - if one side is empty, the result is the other side - if both sides are non-empty, the result is the logical OR - if the left side is true, the right side is not evaluated (short circuit)- Parameters:
other- the other optional predicate- Returns:
- the logical OR of both predicates
-