Calls all plain EventListener event listeners including those from plain EventNode children event nodes of this event node with an event specified. @param event the event to pass as an argument of the calls @return this event node @since 1.0
(@NonNull E event)
| 216 | * @since 1.0 |
| 217 | */ |
| 218 | public @NonNull EventNode<E> call(@NonNull E event) { |
| 219 | if (!this.eventClass.isAssignableFrom(event.getClass())) { |
| 220 | throw new IllegalArgumentException("You cannot call an event in an event node, of which event class is" + |
| 221 | " not assignable from an event class of the event"); |
| 222 | } |
| 223 | |
| 224 | try (CollectionAcquisition<EventListener<? extends E>, ?> listenersAcquisition = this.listeners.acquireRead(); |
| 225 | CollectionAcquisition<EventNode<? extends E>, ?> childrenAcquisition = this.children.acquireRead()) { |
| 226 | List<EventListener<? extends E>> copiedListeners = new ArrayList<>(listenersAcquisition.collection()); |
| 227 | Collections.sort(copiedListeners); |
| 228 | copiedListeners.forEach(listener -> this.callListener(listener, event)); |
| 229 | |
| 230 | List<EventNode<? extends E>> copiedChildren = new ArrayList<>(childrenAcquisition.collection()); |
| 231 | Collections.sort(copiedChildren); |
| 232 | copiedChildren.forEach(node -> this.callChild(node, event)); |
| 233 | } |
| 234 | |
| 235 | return this; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Creates {@linkplain CollectionAcquisition a collection acquisition} of listeners that were registered to this |