From d3abb0aca3ef6d8631597fd05319bf7cd6a33861 Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 4 Nov 2021 15:54:36 +0100 Subject: [PATCH] Improve parameter naming for listener registration --- .../java/dev/kske/eventbus/core/EventBus.java | 59 ++++++++++--------- .../eventbus/core/handler/EventHandler.java | 2 +- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/event-bus-core/src/main/java/dev/kske/eventbus/core/EventBus.java b/event-bus-core/src/main/java/dev/kske/eventbus/core/EventBus.java index ec467f8..42060b7 100644 --- a/event-bus-core/src/main/java/dev/kske/eventbus/core/EventBus.java +++ b/event-bus-core/src/main/java/dev/kske/eventbus/core/EventBus.java @@ -256,67 +256,68 @@ public final class EventBus { * Registers a callback listener, which is a consumer that is invoked when an event occurs. The * listener is not polymorphic and has the {@link #DEFAULT_PRIORITY}. * - * @param the event type the listener listens for - * @param eventType the event type the listener listens for - * @param callback the callback that is invoked when an event occurs + * @param the event type the listener listens for + * @param eventType the event type the listener listens for + * @param eventListener the callback that is invoked when an event occurs * @since 1.2.0 * @see #registerListener(Class, Consumer, boolean, int) */ - public void registerListener(Class eventType, Consumer callback) { - registerListener(eventType, callback, false, DEFAULT_PRIORITY); + public void registerListener(Class eventType, Consumer eventListener) { + registerListener(eventType, eventListener, false, DEFAULT_PRIORITY); } /** * Registers a callback listener, which is a consumer that is invoked when an event occurs. The * listener has the {@link #DEFAULT_PRIORITY}. * - * @param the event type the listener listens for - * @param eventType the event type the listener listens for - * @param callback the callback that is invoked when an event occurs - * @param polymorphic whether the listener is also invoked for subtypes of the event type + * @param the event type the listener listens for + * @param eventType the event type the listener listens for + * @param eventListener the callback that is invoked when an event occurs + * @param polymorphic whether the listener is also invoked for subtypes of the event type * @since 1.2.0 * @see #registerListener(Class, Consumer, boolean, int) */ - public void registerListener(Class eventType, Consumer callback, + public void registerListener(Class eventType, Consumer eventListener, boolean polymorphic) { - registerListener(eventType, callback, polymorphic, DEFAULT_PRIORITY); + registerListener(eventType, eventListener, polymorphic, DEFAULT_PRIORITY); } /** * Registers a callback listener, which is a consumer that is invoked when an event occurs. The * listener is not polymorphic. * - * @param the event type the listener listens for - * @param eventType the event type the listener listens for - * @param callback the callback that is invoked when an event occurs - * @param priority the priority to assign to the listener + * @param the event type the listener listens for + * @param eventType the event type the listener listens for + * @param eventListener the callback that is invoked when an event occurs + * @param priority the priority to assign to the listener * @since 1.2.0 * @see #registerListener(Class, Consumer, boolean, int) */ - public void registerListener(Class eventType, Consumer callback, int priority) { - registerListener(eventType, callback, false, priority); + public void registerListener(Class eventType, Consumer eventListener, int priority) { + registerListener(eventType, eventListener, false, priority); } /** * Registers a callback listener, which is a consumer that is invoked when an event occurs. * - * @param the event type the listener listens for - * @param eventType the event type the listener listens for - * @param callback the callback that is invoked when an event occurs - * @param polymorphic whether the listener is also invoked for subtypes of the event type - * @param priority the priority to assign to the listener + * @param the event type the listener listens for + * @param eventType the event type the listener listens for + * @param eventListener the callback that is invoked when an event occurs + * @param polymorphic whether the listener is also invoked for subtypes of the event type + * @param priority the priority to assign to the listener * @since 1.2.0 */ - public void registerListener(Class eventType, Consumer callback, boolean polymorphic, + public void registerListener(Class eventType, Consumer eventListener, + boolean polymorphic, int priority) { - Objects.requireNonNull(callback); - if (registeredListeners.contains(callback)) - throw new EventBusException(callback + " already registered!"); + Objects.requireNonNull(eventListener); + if (registeredListeners.contains(eventListener)) + throw new EventBusException(eventListener + " already registered!"); logger.log(Level.INFO, "Registering callback event listener {0}", - callback.getClass().getName()); + eventListener.getClass().getName()); - registeredListeners.add(callback); - bindHandler(new CallbackEventHandler(eventType, callback, polymorphic, priority)); + registeredListeners.add(eventListener); + bindHandler(new CallbackEventHandler(eventType, eventListener, polymorphic, priority)); } /** diff --git a/event-bus-core/src/main/java/dev/kske/eventbus/core/handler/EventHandler.java b/event-bus-core/src/main/java/dev/kske/eventbus/core/handler/EventHandler.java index 60fc059..30147a6 100644 --- a/event-bus-core/src/main/java/dev/kske/eventbus/core/handler/EventHandler.java +++ b/event-bus-core/src/main/java/dev/kske/eventbus/core/handler/EventHandler.java @@ -45,7 +45,7 @@ public interface EventHandler { int getPriority(); /** - * @return whether this handler is polymorphic + * @return whether this handler also accepts subtypes of the event type * @since 1.2.0 * @see Polymorphic */