public final class EventHandlers
extends java.lang.Object
Predicate and EventHandlers
interfaces used to configure event collection with EventCollector.| Modifier and Type | Method and Description |
|---|---|
static <E> EventCollector.EventHandler<E> |
chain(java.util.Collection<java.util.function.Predicate<? super E>> filters)
Create an instance of the
EventCollector.EventHandler that chain specified delegates so that
next filter is called only if previous one had returned true. |
static <E> EventCollector.EventHandler<E> |
chain(java.util.function.Predicate<? super E>... filters)
Equal to the
chain(Collection) but with vararg for filter predicates. |
static <E> EventCollector.EventHandler<E> |
collectCallback(java.util.function.Consumer<E> consumer)
Method allows you to create a "listener" kind of handler that always returns
true on test
and calls specified consumer on EventCollector.EventHandler.eventCollected(Object)
Equal to functional(Predicate, Consumer) with a (p -> true) predicate. |
static <E> EventCollector.EventHandler<E> |
functional(java.util.function.Predicate<? super E> predicate,
java.util.function.Consumer<? super E> consumer)
Create an instance of the
EventCollector.EventHandler that will delegate it's functionality to the specified
functionals. |
static LatchEventHandler |
latch(int count)
Create and instance of the
LatchEventHandler with a CountDownLatch
initiated with the specified count. |
static <E> java.util.function.Predicate<E> |
manual(java.util.concurrent.atomic.AtomicBoolean flag)
Create a predicate that will delegate call to the specified
AtomicBoolean for any argument. |
static <E> java.util.function.Predicate<E> |
skip(long n)
Create a predicate that will return
N number of false results for any arguments. |
public static LatchEventHandler latch(int count)
LatchEventHandler with a CountDownLatch
initiated with the specified count.public static <E> java.util.function.Predicate<E> skip(long n)
N number of false results for any arguments.
Then it will start to return true for any argument.public static <E> java.util.function.Predicate<E> manual(java.util.concurrent.atomic.AtomicBoolean flag)
AtomicBoolean for any argument.
Result predicate will return the same value as received from the AtomicBoolean.get() method.@SafeVarargs public static <E> EventCollector.EventHandler<E> chain(java.util.function.Predicate<? super E>... filters)
chain(Collection) but with vararg for filter predicates.public static <E> EventCollector.EventHandler<E> chain(java.util.Collection<java.util.function.Predicate<? super E>> filters)
Create an instance of the EventCollector.EventHandler that chain specified delegates so that
next filter is called only if previous one had returned true.
Handler like this allows you to build complex logic for event filtering;
e.g. something like: "await 5 seconds" - then "skip 5 events". Since EventCollector
calls ALL the registered filters on each event it isn't possible to implement something like this
with basic functionality.
Note: since EventCollector.EventHandler is created, and not plain Predicate - you also can
specify other handlers as delegates and their EventCollector.EventHandler.eventCollected(Object) method will be called
when the same method of the created handler is called.
java.lang.NullPointerException - if specified collection contains nullsjava.lang.IllegalArgumentException - if less than 2 filters are specifiedpublic static <E> EventCollector.EventHandler<E> collectCallback(java.util.function.Consumer<E> consumer)
Method allows you to create a "listener" kind of handler that always returns true on test
and calls specified consumer on EventCollector.EventHandler.eventCollected(Object)
Equal to functional(Predicate, Consumer) with a (p -> true) predicate.
public static <E> EventCollector.EventHandler<E> functional(java.util.function.Predicate<? super E> predicate, java.util.function.Consumer<? super E> consumer)
Create an instance of the EventCollector.EventHandler that will delegate it's functionality to the specified
functionals. Each time Predicate.test(Object) is called - it will call specified predicate;
each time EventCollector.EventHandler.eventCollected(Object) is called it will call specified consumer.
Might be useful to implement simple handlers where functionality is based upon some local values.
collectCallback(Consumer)