All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.activej.promise.PromisePredicates Maven / Gradle / Ivy

Go to download

A convenient way to organize asynchronous code. Promises are a faster and more efficient version of JavaScript's Promise and Java's CompletionStage's.

There is a newer version: 6.0-rc2
Show newest version
package io.activej.promise;

import java.util.function.BiPredicate;
import java.util.function.Predicate;

@SuppressWarnings("unchecked")
public class PromisePredicates {
	private static final BiPredicate IS_COMPLETE = (t, e) -> true;
	private static final BiPredicate IS_RESULT = (t, e) -> e == null;
	private static final BiPredicate IS_EXCEPTION = (t, e) -> e != null;

	public static  BiPredicate isComplete() {
		return (BiPredicate) IS_COMPLETE;
	}

	public static  BiPredicate isResult() {
		return (BiPredicate) IS_RESULT;
	}

	public static  BiPredicate isResult(Predicate predicate) {
		return (t, e) -> e == null && predicate.test(t);
	}

	public static  BiPredicate isResultOrException(Predicate predicate) {
		return (t, e) -> e != null || predicate.test(t);
	}

	public static  BiPredicate isException() {
		return (BiPredicate) IS_EXCEPTION;
	}

	public static  BiPredicate isException(Predicate predicate) {
		return (t, e) -> e != null && predicate.test(e);
	}

	public static  BiPredicate isException(Class errorClass) {
		return isException(e -> errorClass.isAssignableFrom(e.getClass()));
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy