diff --git a/core/src/main/java/org/ogcs/event/EventListenerSet.java b/core/src/main/java/org/ogcs/event/EventListenerSet.java index bb37e89..e91e06b 100644 --- a/core/src/main/java/org/ogcs/event/EventListenerSet.java +++ b/core/src/main/java/org/ogcs/event/EventListenerSet.java @@ -20,7 +20,7 @@ import java.util.Set; /** - * + * The {@link EventListener} collection. * @author TinyZ. * @since 1.0 */ @@ -50,6 +50,10 @@ public EventListener[] listeners() { return listeners.toArray(new EventListener[listeners.size()]); } + public boolean isEmpty() { + return listeners.isEmpty(); + } + public int size() { return listeners.size(); } diff --git a/core/src/main/java/org/ogcs/event/MultiListenerEventDispatcher.java b/core/src/main/java/org/ogcs/event/MultiListenerEventDispatcher.java index 63ab0bd..b124c16 100644 --- a/core/src/main/java/org/ogcs/event/MultiListenerEventDispatcher.java +++ b/core/src/main/java/org/ogcs/event/MultiListenerEventDispatcher.java @@ -97,7 +97,11 @@ public void removeEventListener(Object type, EventListener listener) { return; } if (listeners instanceof EventListenerSet) { - ((EventListenerSet) listeners).remove(listener); + EventListenerSet set = (EventListenerSet) listeners; + set.remove(listener); + if (set.isEmpty()) { + map.remove(type); + } } else if (listeners.equals(listener)) { map.remove(type); }