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

io.datakernel.async.AsyncPredicate Maven / Gradle / Ivy

Go to download

Efficient non-blocking network and file I/O, for building Node.js-like client/server applications with high performance requirements. It is similar to Event Loop in Node.js. Although Eventloop runs in a single thread, multiple event loops can be launched at the same time allowing for efficient CPU usage.

There is a newer version: 3.1.0
Show newest version
package io.datakernel.async;

import java.util.Objects;
import java.util.function.Predicate;

public interface AsyncPredicate {
	Stage test(T t);

	default AsyncPredicate negate() {
		return t -> this.test(t).thenApply(b -> !b);
	}

	default AsyncPredicate and(AsyncPredicate other) {
		Objects.requireNonNull(other);
		return t -> this.test(t).thenCompose(b -> b ? other.test(t) : Stage.of(Boolean.FALSE));
	}

	default AsyncPredicate and(Predicate other) {
		Objects.requireNonNull(other);
		return t -> this.test(t).thenApply(b -> b ? other.test(t) : Boolean.FALSE);
	}

	default AsyncPredicate or(Predicate other) {
		Objects.requireNonNull(other);
		return t -> this.test(t).thenApply(b -> b ? Boolean.TRUE : other.test(t));
	}

	default AsyncPredicate or(AsyncPredicate other) {
		Objects.requireNonNull(other);
		return t -> this.test(t).thenCompose(b -> b ? Stage.of(Boolean.TRUE) : other.test(t));
	}

	static  AsyncPredicate of(Predicate predicate) {
		return t -> Stage.of(predicate.test(t));
	}

	static  AsyncPredicate alwaysTrue() {
		return t -> Stage.of(Boolean.TRUE);
	}

	static  AsyncPredicate alwaysFalse() {
		return t -> Stage.of(Boolean.FALSE);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy