E
- exception typeP
- parameter type@FunctionalInterface
public interface FragilePredicate1<E extends java.lang.Exception,P>
Fragile predicates can be chained to simulate boolean logic by
and(Predicate)
, or(Predicate)
,
xor(Predicate)
, and negate()
.
The chaining does not always work as expected from
standard Java expressions. Therefore, there are
versions of the above methods with an underscore suffix
which allow to widen the type: and_(Predicate)
,
or_(Predicate)
, xor_(Predicate)
.
There are also static methods which take care of the
type fiddling transparently: and(FragilePredicate1, FragilePredicate1)
,
FragilePredicate2
Modifier and Type | Method and Description |
---|---|
default <S> FragilePredicate1<E,S> |
adapted(java.util.function.Function<? super S,? extends P> mapper)
Use this predicate on a different type.
|
default <T extends P> |
and_(java.util.function.Predicate<T> other)
Combine this and another predicate with logical and.
|
static <T,X extends java.lang.Exception> |
and(FragilePredicate1<? extends X,? super T> pred1,
FragilePredicate1<? extends X,? super T> pred2)
Get a predicate which is the combination of two predicates
with a logical and.
|
default FragilePredicate1<E,P> |
and(java.util.function.Predicate<? super P> other)
Combine this and another predicate with logical and.
|
default FragilePredicate1<E,P> |
negate()
Get the negation of this predicate.
|
default <T extends P> |
or_(java.util.function.Predicate<T> other)
Combine this and another predicate with logical or.
|
static <T,X extends java.lang.Exception> |
or(FragilePredicate1<? extends X,? super T> pred1,
FragilePredicate1<? extends X,? super T> pred2)
Get a predicate which is the combination of two predicates
with a logical or.
|
default FragilePredicate1<E,P> |
or(java.util.function.Predicate<? super P> other)
Combine this and another predicate with logical or.
|
boolean |
test(P arg)
Test the argument and check whether it evaluates.
|
default boolean |
testNonNull(P argument,
boolean fallback)
Test the argument only if it is not
null , otherwise return the fallback. |
default <T extends P> |
xor_(java.util.function.Predicate<T> other)
Combine this and another predicate with logical exclusive or.
|
static <T,X extends java.lang.Exception> |
xor(FragilePredicate1<? extends X,? super T> pred1,
FragilePredicate1<? extends X,? super T> pred2)
Get a predicate which is the combination of two predicates
with a logical exclusive or.
|
default FragilePredicate1<E,P> |
xor(java.util.function.Predicate<? super P> other)
Combine this and another predicate with logical exclusive or.
|
boolean test(P arg) throws E extends java.lang.Exception
arg
- argument to checktrue
if the argument evaluates to true
,false
if notE
- checked exception thrown by implementationE extends java.lang.Exception
default boolean testNonNull(P argument, boolean fallback) throws E extends java.lang.Exception
null
, otherwise return the fallback.
Using this invocation it is guaranteed that test(Object)
will always be called with
a non-null argument.
argument
- argument of this functionfallback
- fallback returned if argument
is null
argument
,
or fallback
if argument
is nullE
- checked exception thrown by implementationE extends java.lang.Exception
@NotNull default FragilePredicate1<E,P> and(@NotNull java.util.function.Predicate<? super P> other)
false
the other one is
not evaluated.other
- other predicate to be chained with logical andand(FragilePredicate1, FragilePredicate1)
,
and_(Predicate)
@NotNull default <T extends P> FragilePredicate1<E,T> and_(@NotNull java.util.function.Predicate<T> other)
false
the other one is
not evaluated.
Compared to and(Predicate)
this method allows
to widen the type of this predicate to the one of the other predicate
like in standard Jave logical expressions, eg
Predicate1<Object> nonNull = o -> o != null;
Predicate1<String> notEmpty = s -> !s.isEmpty();
// Predicate1<???> bad = nonNull.and(notEmpty); // not possible as String is not a super type of Object
Predicate1<String> valid = nonMull.and_(notEmpty); // not nice, but it works
T
- type on which the other predicate operates, also the type of
the returned predicateother
- other predicateand(FragilePredicate1, FragilePredicate1)
,
and(Predicate)
@NotNull default FragilePredicate1<E,P> or(@NotNull java.util.function.Predicate<? super P> other)
true
the other one is
not evaluated.other
- the other predicate to be chained with logical oror(FragilePredicate1, FragilePredicate1)
,
or_(Predicate)
@NotNull default <T extends P> FragilePredicate1<E,T> or_(@NotNull java.util.function.Predicate<T> other)
true
the other one is
not evaluated.
Compared to or(Predicate)
this method allows
to widen the type of this predicate to the one of the other predicate
like in standard Jave logical expressions, eg
Predicate1<Object> isNull = o -> o == null;
Predicate1<String> isEmpty = s -> !s.isEmpty();
// Predicate1<???> bad = pred1.or(pred2); // not possible as String is not a super type of Object
Predicate1<String> useless = pred1.or_(pred2); // not nice, but it works
T
- type on which the other predicate operates, also the type of
the returned predicateother
- other predicateor(FragilePredicate1, FragilePredicate1)
,
or(Predicate)
@NotNull default FragilePredicate1<E,P> xor(@NotNull java.util.function.Predicate<? super P> other)
other
- the other predicate to be chained with logical exclusive orxor(FragilePredicate1, FragilePredicate1)
,
xor_(Predicate)
@NotNull default <T extends P> FragilePredicate1<E,T> xor_(@NotNull java.util.function.Predicate<T> other)
true
the other one is
not evaluated.
Compared to or(Predicate)
this method allows
widening the type of this predicate to the one of the other predicate
like in standard Jave logical expressions, eg
Predicate1<Object> isNull = o -> o == null;
Predicate1<String> isEmpty = s -> !s.isEmpty();
// Predicate1<???> bad = isNull.xor(isEmpty); // not possible as String is not a super type of Object
Predicate1<String> useless = isNull.xor_(isEmpty); // bad example, but it works
T
- type on which the other predicate operates, also the type of
the returned predicateother
- other predicatexor(FragilePredicate1, FragilePredicate1)
,
xor(Predicate)
@NotNull default FragilePredicate1<E,P> negate()
@NotNull default <S> FragilePredicate1<E,S> adapted(@NotNull java.util.function.Function<? super S,? extends P> mapper)
S
- different type on which the returned predicate operatesmapper
- mapper function which converts the different type to one this predicate accepts.@NotNull static <T,X extends java.lang.Exception> FragilePredicate1<X,T> and(@NotNull FragilePredicate1<? extends X,? super T> pred1, @NotNull FragilePredicate1<? extends X,? super T> pred2)
This method takes care of always creating a predicate of the correct type
without having to fiddle with and(Predicate)
or and_(Predicate)
depending on the types.
The result will use shortcut evaluation, so if this
predicate already returns false
the other one is
not evaluated.
T
- resulting type, which is the most extending type of both pred1
's
type and pred2
's type, so if neither type is extending the
other this method will not compileX
- common exception typepred1
- first predicatepred2
- second predicateand(Predicate)
,
and_(Predicate)
@NotNull static <T,X extends java.lang.Exception> FragilePredicate1<X,T> or(@NotNull FragilePredicate1<? extends X,? super T> pred1, @NotNull FragilePredicate1<? extends X,? super T> pred2)
This method takes care of always creating a predicate of the correct type
without having to fiddle with or(Predicate)
or or_(Predicate)
depending on the types.
The result will use shortcut evaluation, so if this
predicate already returns false
the other one is
not evaluated.
T
- resulting type, which is the most extending type of both pred1
's
type and pred2
's type, so if neither type is extending the
other this method will not compileX
- common exception typepred1
- first predicatepred2
- second predicateor(Predicate)
,
or_(Predicate)
@NotNull static <T,X extends java.lang.Exception> FragilePredicate1<X,T> xor(@NotNull FragilePredicate1<? extends X,? super T> pred1, @NotNull FragilePredicate1<? extends X,? super T> pred2)
This method takes care of always creating a predicate of the correct type
without having to fiddle with or(Predicate)
or or_(Predicate)
depending on the types.
The result will use shortcut evaluation, so if this
predicate already returns true
the other one is
not evaluated.
T
- resulting type, which is the most extending type of both pred1
's
type and pred2
's type, so if neither type is extending the
other this method will not compileX
- common exception typepred1
- first predicatepred2
- second predicatexor(Predicate)
,
xor_(Predicate)