aQute.lib.exceptions.BiPredicateWithException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.bndtools.headless.build.plugin.ant Show documentation
Show all versions of org.bndtools.headless.build.plugin.ant Show documentation
org.bndtools.headless.build.plugin.ant
package aQute.lib.exceptions;
import static java.util.Objects.requireNonNull;
import java.util.function.BiPredicate;
import java.util.function.BooleanSupplier;
/**
* BiPredicate interface that allows exceptions.
*
* @param the type of the first argument
* @param the type of the second argument
*/
@FunctionalInterface
public interface BiPredicateWithException {
boolean test(T t, U u) throws Exception;
default BiPredicate orElseThrow() {
return (t, u) -> {
try {
return test(t, u);
} catch (Exception e) {
throw Exceptions.duck(e);
}
};
}
default BiPredicate orElse(boolean orElse) {
return (t, u) -> {
try {
return test(t, u);
} catch (Exception e) {
return orElse;
}
};
}
default BiPredicate orElseGet(BooleanSupplier orElseGet) {
requireNonNull(orElseGet);
return (t, u) -> {
try {
return test(t, u);
} catch (Exception e) {
return orElseGet.getAsBoolean();
}
};
}
static BiPredicate asBiPredicate(BiPredicateWithException unchecked) {
return unchecked.orElseThrow();
}
static BiPredicate asBiPredicateOrElse(BiPredicateWithException unchecked, boolean orElse) {
return unchecked.orElse(orElse);
}
static BiPredicate asBiPredicateOrElseGet(BiPredicateWithException unchecked,
BooleanSupplier orElseGet) {
return unchecked.orElseGet(orElseGet);
}
}