@Test public void testListenForSingleEvent() { final List<TestEvent> caughtEvents = new ArrayList<TestEvent>(); final SoarEventManager manager = new SoarEventManager(); SoarEvents.listenForSingleEvent(manager, TestEvent.class, new SoarEventListener() { @Override public void onEvent(SoarEvent event) { caughtEvents.add((TestEvent) event); }}); assertEquals(0, caughtEvents.size()); final TestEvent event = new TestEvent(); manager.fireEvent(event); assertEquals(1, caughtEvents.size()); assertSame(event, caughtEvents.get(0)); manager.fireEvent(event); assertEquals(1, caughtEvents.size()); }
public static <T extends SoarEvent> void listenForSingleEvent(final SoarEventManager manager, final Class<T> klass, final SoarEventListener listener) { manager.addListener(klass, new SoarEventListener() { @Override public void onEvent(SoarEvent event) { try { listener.onEvent(event); } finally { manager.removeListener(klass, this); } }}); }
SoarEvents { public static <T extends SoarEvent> void listenForSingleEvent(final SoarEventManager manager, final Class<T> klass, final SoarEventListener listener) { manager.addListener(klass, new SoarEventListener() { @Override public void onEvent(SoarEvent event) { try { listener.onEvent(event); } finally { manager.removeListener(klass, this); } }}); } }
SoarEvents { public static <T extends SoarEvent> void listenForSingleEvent(final SoarEventManager manager, final Class<T> klass, final SoarEventListener listener) { manager.addListener(klass, new SoarEventListener() { @Override public void onEvent(SoarEvent event) { try { listener.onEvent(event); } finally { manager.removeListener(klass, this); } }}); }  }
SoarEvents { public static <T extends SoarEvent> void listenForSingleEvent(final SoarEventManager manager, final Class<T> klass, final SoarEventListener listener) { manager.addListener(klass, new SoarEventListener() { @Override public void onEvent(SoarEvent event) { try { listener.onEvent(event); } finally { manager.removeListener(klass, this); } }}); }  static void listenForSingleEvent(final SoarEventManager manager, final Class<T> klass, final SoarEventListener listener); }
SoarEvents { public static <T extends SoarEvent> void listenForSingleEvent(final SoarEventManager manager, final Class<T> klass, final SoarEventListener listener) { manager.addListener(klass, new SoarEventListener() { @Override public void onEvent(SoarEvent event) { try { listener.onEvent(event); } finally { manager.removeListener(klass, this); } }}); }  static void listenForSingleEvent(final SoarEventManager manager, final Class<T> klass, final SoarEventListener listener);  }