@Test public void testRemove() throws InterruptedException { final AtomicInteger i = new AtomicInteger(0); SwiftEventListener<Object> listener = new SwiftEventListener<Object>() { @Override public void on(Object data) { i.getAndIncrement(); } }; SwiftEventDispatcher.listen(Evt.EVT1, listener); SwiftEventDispatcher.remove(listener); SwiftEventDispatcher.asyncFire(Evt.EVT1); Assert.assertEquals(0, i.get()); Thread.sleep(1000); }
public static void remove(SwiftEventListener<?> listener) { if (listener == null) { return; } synchronized (EVENTS) { for (List<SwiftEventListener> listeners : EVENTS.values()) { Iterator<SwiftEventListener> itr = listeners.iterator(); while (itr.hasNext()) { if (itr.next() == listener) { itr.remove(); } } } } }
SwiftEventDispatcher { public static void remove(SwiftEventListener<?> listener) { if (listener == null) { return; } synchronized (EVENTS) { for (List<SwiftEventListener> listeners : EVENTS.values()) { Iterator<SwiftEventListener> itr = listeners.iterator(); while (itr.hasNext()) { if (itr.next() == listener) { itr.remove(); } } } } } }
SwiftEventDispatcher { public static void remove(SwiftEventListener<?> listener) { if (listener == null) { return; } synchronized (EVENTS) { for (List<SwiftEventListener> listeners : EVENTS.values()) { Iterator<SwiftEventListener> itr = listeners.iterator(); while (itr.hasNext()) { if (itr.next() == listener) { itr.remove(); } } } } }  }
SwiftEventDispatcher { public static void remove(SwiftEventListener<?> listener) { if (listener == null) { return; } synchronized (EVENTS) { for (List<SwiftEventListener> listeners : EVENTS.values()) { Iterator<SwiftEventListener> itr = listeners.iterator(); while (itr.hasNext()) { if (itr.next() == listener) { itr.remove(); } } } } }  static void listen(SwiftEvent event, SwiftEventListener<?> listener); static void remove(SwiftEventListener<?> listener); static void asyncFire(final SwiftEvent event, final T content); static void asyncFire(SwiftEvent event); static void syncFire(final SwiftEvent event, final T content); static void syncFire(SwiftEvent event); }
SwiftEventDispatcher { public static void remove(SwiftEventListener<?> listener) { if (listener == null) { return; } synchronized (EVENTS) { for (List<SwiftEventListener> listeners : EVENTS.values()) { Iterator<SwiftEventListener> itr = listeners.iterator(); while (itr.hasNext()) { if (itr.next() == listener) { itr.remove(); } } } } }  static void listen(SwiftEvent event, SwiftEventListener<?> listener); static void remove(SwiftEventListener<?> listener); static void asyncFire(final SwiftEvent event, final T content); static void asyncFire(SwiftEvent event); static void syncFire(final SwiftEvent event, final T content); static void syncFire(SwiftEvent event);  }