@Test public void testAddListener() throws Exception { JEventListeners<JEventListener<? extends TestEvent2>, TestEvent2> listeners = Listeners.newEventListenersBuilderFor(TestEvent2.class).onCallerThread().withHardReferences().create(); final TestEventListener2 l2 = new TestEventListener2(); final TestEventListener2 l3 = new TestEventListener2(); Assert.assertTrue(listeners.addListener(l2)); Assert.assertFalse(listeners.addListener(l2)); Assert.assertFalse(listeners.addListener(l2)); Assert.assertTrue(listeners.addListener(l3)); listeners.fireEvent(new TestEvent2()); Assert.assertEquals(1, l2.getCount()); Assert.assertEquals(1, l3.getCount()); }
@Override public boolean addListener(@Nonnull L listener) { if (!baseEventType.isAssignableFrom(listener.getEventType())) { throw new IllegalArgumentException("Current listener cannot be added, because will never be fired!"); } return listeners.addListener(listener); }
EventListenersImpl implements JEventListeners<L, E> { @Override public boolean addListener(@Nonnull L listener) { if (!baseEventType.isAssignableFrom(listener.getEventType())) { throw new IllegalArgumentException("Current listener cannot be added, because will never be fired!"); } return listeners.addListener(listener); } }
EventListenersImpl implements JEventListeners<L, E> { @Override public boolean addListener(@Nonnull L listener) { if (!baseEventType.isAssignableFrom(listener.getEventType())) { throw new IllegalArgumentException("Current listener cannot be added, because will never be fired!"); } return listeners.addListener(listener); } private  EventListenersImpl(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, int eventThreadsCount); private  EventListenersImpl(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, @Nullable Executor eventExecutor); }
EventListenersImpl implements JEventListeners<L, E> { @Override public boolean addListener(@Nonnull L listener) { if (!baseEventType.isAssignableFrom(listener.getEventType())) { throw new IllegalArgumentException("Current listener cannot be added, because will never be fired!"); } return listeners.addListener(listener); } private  EventListenersImpl(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, int eventThreadsCount); private  EventListenersImpl(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, @Nullable Executor eventExecutor); @Nonnull static EventListenersImpl<L, JEvent> newSingleThread(@Nonnull JListeners<L> listeners); @Nonnull static EventListenersImpl<L, E> newSingleThread(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType); @Nonnull static EventListenersImpl<L, E> newInstance(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, int eventThreadsCount); @Nonnull static EventListenersImpl<L, E> newInstance(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, @Nonnull Executor executor); @Override void fireEvent(@Nonnull final E event); @Override void fireEvents(@Nonnull final Collection<E> events); @Override boolean addListener(@Nonnull L listener); @Override boolean removeListener(@Nonnull L listener); @Override void removeListeners(); }
EventListenersImpl implements JEventListeners<L, E> { @Override public boolean addListener(@Nonnull L listener) { if (!baseEventType.isAssignableFrom(listener.getEventType())) { throw new IllegalArgumentException("Current listener cannot be added, because will never be fired!"); } return listeners.addListener(listener); } private  EventListenersImpl(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, int eventThreadsCount); private  EventListenersImpl(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, @Nullable Executor eventExecutor); @Nonnull static EventListenersImpl<L, JEvent> newSingleThread(@Nonnull JListeners<L> listeners); @Nonnull static EventListenersImpl<L, E> newSingleThread(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType); @Nonnull static EventListenersImpl<L, E> newInstance(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, int eventThreadsCount); @Nonnull static EventListenersImpl<L, E> newInstance(@Nonnull JListeners<L> listeners, @Nonnull Class<E> baseEventType, @Nonnull Executor executor); @Override void fireEvent(@Nonnull final E event); @Override void fireEvents(@Nonnull final Collection<E> events); @Override boolean addListener(@Nonnull L listener); @Override boolean removeListener(@Nonnull L listener); @Override void removeListeners();  }