feat: isRegistered method on IBus

This commit is contained in:
zaaarf 2024-06-04 23:01:35 +02:00
parent 216159feec
commit 3dc755f0c7
No known key found for this signature in database
GPG key ID: C91CFF9E2262BBA1
2 changed files with 14 additions and 1 deletions

View file

@ -63,6 +63,12 @@ public class GEB implements IBus {
); );
} }
@Override
public boolean isRegistered(IListener listener) {
Set<IListener> listeners = this.listenerMap.get(listener.getClass());
return listeners != null && listeners.contains(listener);
}
/** /**
* Dispatches an event, calling all of its listeners that are subscribed to this bus. * Dispatches an event, calling all of its listeners that are subscribed to this bus.
* @param event the event to fire * @param event the event to fire

View file

@ -13,11 +13,18 @@ public interface IBus {
void registerListener(IListener listener); void registerListener(IListener listener);
/** /**
* Unregister a listener from the bus. * Unregisters a listener from the bus.
* @param listener the listener * @param listener the listener
*/ */
void unregisterListener(IListener listener); void unregisterListener(IListener listener);
/**
* Tells you whether a listener is currently registered.
* Ideally this should be efficient.
* @return true if the listener is registered
*/
boolean isRegistered(IListener listener);
/** /**
* Dispatches an event, calling all of its listeners that are subscribed to this bus. * Dispatches an event, calling all of its listeners that are subscribed to this bus.
* @param event the event to fire * @param event the event to fire