
aQute.bnd.exceptions.PredicateWithException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.bnd.runtime.snapshot Show documentation
Show all versions of biz.aQute.bnd.runtime.snapshot Show documentation
biz.aQute.bnd.runtime.snapshot
The newest version!
package aQute.bnd.exceptions;
import static java.util.Objects.requireNonNull;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;
/**
* Predicate interface that allows exceptions.
*
* @param the type of the argument
*/
@FunctionalInterface
public interface PredicateWithException {
boolean test(T t) throws Exception;
default Predicate orElseThrow() {
return t -> {
try {
return test(t);
} catch (Exception e) {
throw Exceptions.duck(e);
}
};
}
default Predicate orElse(boolean orElse) {
return t -> {
try {
return test(t);
} catch (Exception e) {
return orElse;
}
};
}
default Predicate orElseGet(BooleanSupplier orElseGet) {
requireNonNull(orElseGet);
return t -> {
try {
return test(t);
} catch (Exception e) {
return orElseGet.getAsBoolean();
}
};
}
static Predicate asPredicate(PredicateWithException unchecked) {
return unchecked.orElseThrow();
}
static Predicate asPredicateOrElse(PredicateWithException unchecked, boolean orElse) {
return unchecked.orElse(orElse);
}
static Predicate asPredicateOrElseGet(PredicateWithException unchecked, BooleanSupplier orElseGet) {
return unchecked.orElseGet(orElseGet);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy