io.activej.promise.PromisePredicates Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activej-promise Show documentation
Show all versions of activej-promise Show documentation
A convenient way to organize asynchronous code.
Promises are a faster and more efficient version of JavaScript's Promise and Java's CompletionStage's.
package io.activej.promise;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
@SuppressWarnings("unchecked")
public class PromisePredicates {
private static final BiPredicate, Exception> IS_COMPLETE = (t, e) -> true;
private static final BiPredicate, Exception> IS_RESULT = (t, e) -> e == null;
private static final BiPredicate, Exception> IS_EXCEPTION = (t, e) -> e != null;
public static BiPredicate super T, Exception> isComplete() {
return (BiPredicate super T, Exception>) IS_COMPLETE;
}
public static BiPredicate super T, Exception> isResult() {
return (BiPredicate super T, Exception>) IS_RESULT;
}
public static BiPredicate super T, Exception> isResult(Predicate super T> predicate) {
return (t, e) -> e == null && predicate.test(t);
}
public static BiPredicate super T, Exception> isResultOrException(Predicate super T> predicate) {
return (t, e) -> e != null || predicate.test(t);
}
public static BiPredicate super T, Exception> isException() {
return (BiPredicate super T, Exception>) IS_EXCEPTION;
}
public static BiPredicate super T, Exception> isException(Predicate predicate) {
return (t, e) -> e != null && predicate.test(e);
}
public static BiPredicate super T, Exception> isException(Class extends Exception> errorClass) {
return isException(e -> errorClass.isAssignableFrom(e.getClass()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy