This commit is contained in:
TheMode 2021-08-21 02:08:25 +02:00
parent 0ad763a813
commit cfbd655027

View File

@ -29,9 +29,9 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
private volatile int priority; private volatile int priority;
private volatile EventNodeImpl<? super T> parent; private volatile EventNodeImpl<? super T> parent;
protected EventNodeImpl(@NotNull String name, EventNodeImpl(@NotNull String name,
@NotNull EventFilter<T, ?> filter, @NotNull EventFilter<T, ?> filter,
@Nullable BiPredicate<T, Object> predicate) { @Nullable BiPredicate<T, Object> predicate) {
this.name = name; this.name = name;
this.filter = filter; this.filter = filter;
this.predicate = predicate; this.predicate = predicate;
@ -313,8 +313,8 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
private void recursiveUpdate(EventNodeImpl<E> targetNode) { private void recursiveUpdate(EventNodeImpl<E> targetNode) {
// Standalone listeners // Standalone listeners
forTargetEvents(eventType, type -> { forTargetEvents(eventType, type -> {
ListenerEntry<E> entry = targetNode.listenerMap.get(type); final ListenerEntry<E> entry = targetNode.listenerMap.get(type);
if (entry != null) appendEntries(listeners, entry, targetNode); if (entry != null) appendEntries(entry, targetNode);
}); });
// Mapped nodes // Mapped nodes
handleMappedNode(targetNode); handleMappedNode(targetNode);
@ -356,27 +356,27 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
} }
} }
static <E extends Event> void appendEntries(List<Consumer<E>> handleListeners, ListenerEntry<E> entry, EventNodeImpl<E> targetNode) { private void appendEntries(ListenerEntry<E> entry, EventNodeImpl<E> targetNode) {
final var filter = targetNode.filter; final var filter = targetNode.filter;
final var predicate = targetNode.predicate; final var predicate = targetNode.predicate;
// Normal listeners // Normal listeners
for (var listener : entry.listeners) { for (var listener : entry.listeners) {
if (predicate != null) { if (predicate != null) {
// Ensure that the event is valid before running // Ensure that the event is valid before running
handleListeners.add(e -> { this.listeners.add(e -> {
final var value = filter.getHandler(e); final var value = filter.getHandler(e);
if (!predicate.test(e, value)) return; if (!predicate.test(e, value)) return;
callListener(targetNode, listener, e); callListener(targetNode, listener, e);
}); });
} else { } else {
// No predicate, run directly // No predicate, run directly
handleListeners.add(e -> callListener(targetNode, listener, e)); this.listeners.add(e -> callListener(targetNode, listener, e));
} }
} }
// Bindings // Bindings
final var bindingConsumers = entry.bindingConsumers; final var bindingConsumers = entry.bindingConsumers;
if (!bindingConsumers.isEmpty()) { // Ensure no array clone if (!bindingConsumers.isEmpty()) { // Ensure no array clone
handleListeners.addAll(bindingConsumers); this.listeners.addAll(bindingConsumers);
} }
} }