@Test public void testRemovesAndAddsDuringEvent() { SequenceDependenciesEventPublisher publisher = new SequenceDependenciesEventPublisher(); SimpleSubjectListener a = new SimpleSubjectListener("A", publisher); SimpleSubjectListener b = new SimpleSubjectListener("B", publisher); SimpleSubjectListener c = new SimpleSubjectListener("C", publisher); SimpleSubjectListener d = new SimpleSubjectListener("D", publisher); a.addListener(b); b.setRunOnceRunnable(new AddListenerRunnable(b, c)); a.setValue("Saskatchwan"); assertEquals(1, b.getReceivedEvents().size()); assertEquals(0, c.getReceivedEvents().size()); a.setValue("Tiger-Cats"); assertEquals(2, b.getReceivedEvents().size()); assertEquals(1, c.getReceivedEvents().size()); b.setRunOnceRunnable(new RemoveListenerRunnable(b, c)); a.setValue("Blue Bombers"); assertEquals(3, b.getReceivedEvents().size()); assertEquals(2, c.getReceivedEvents().size()); a.setValue("Stampeders"); assertEquals(4, b.getReceivedEvents().size()); assertEquals(2, c.getReceivedEvents().size()); a.addListener(c); b.setRunOnceRunnable(new AddListenerRunnable(c, d)); a.setValue("Argonauts"); assertEquals(3, c.getReceivedEvents().size()); assertEquals(0, d.getReceivedEvents().size()); a.setValue("Lions"); assertEquals(4, c.getReceivedEvents().size()); assertEquals(1, d.getReceivedEvents().size()); b.setRunOnceRunnable(new RemoveListenerRunnable(c, d)); a.setValue("Eskimos"); assertEquals(5, c.getReceivedEvents().size()); assertEquals(2, d.getReceivedEvents().size()); a.setValue("Alouettes"); assertEquals(6, c.getReceivedEvents().size()); assertEquals(2, d.getReceivedEvents().size()); }
public synchronized <Subject,Listener,Event> void addListener(Subject subject, Listener listener, EventFormat<Subject,Listener,Event> eventFormat) { List<SubjectAndListener> unordered = updateListEventListeners(subject, listener, null, eventFormat); subjectAndListeners = orderSubjectsAndListeners(unordered); }
SequenceDependenciesEventPublisher implements ListEventPublisher, Serializable { public synchronized <Subject,Listener,Event> void addListener(Subject subject, Listener listener, EventFormat<Subject,Listener,Event> eventFormat) { List<SubjectAndListener> unordered = updateListEventListeners(subject, listener, null, eventFormat); subjectAndListeners = orderSubjectsAndListeners(unordered); } }
SequenceDependenciesEventPublisher implements ListEventPublisher, Serializable { public synchronized <Subject,Listener,Event> void addListener(Subject subject, Listener listener, EventFormat<Subject,Listener,Event> eventFormat) { List<SubjectAndListener> unordered = updateListEventListeners(subject, listener, null, eventFormat); subjectAndListeners = orderSubjectsAndListeners(unordered); }  }
SequenceDependenciesEventPublisher implements ListEventPublisher, Serializable { public synchronized <Subject,Listener,Event> void addListener(Subject subject, Listener listener, EventFormat<Subject,Listener,Event> eventFormat) { List<SubjectAndListener> unordered = updateListEventListeners(subject, listener, null, eventFormat); subjectAndListeners = orderSubjectsAndListeners(unordered); }  synchronized void addListener(Subject subject, Listener listener, EventFormat<Subject,Listener,Event> eventFormat); synchronized void removeListener(Object subject, Object listener); @Override void setRelatedListener(Object subject, Object relatedListener); @Override void clearRelatedListener(Object subject, Object relatedListener); @Override void addDependency(EventList dependency, ListEventListener listener); @Override void removeDependency(EventList dependency, ListEventListener listener); @Override void setRelatedSubject(Object listener, Object relatedSubject); @Override void clearRelatedSubject(Object listener); synchronized List<Listener> getListeners(Object subject); void fireEvent(Subject subject, Event event, EventFormat<Subject,Listener,Event> eventFormat); }
SequenceDependenciesEventPublisher implements ListEventPublisher, Serializable { public synchronized <Subject,Listener,Event> void addListener(Subject subject, Listener listener, EventFormat<Subject,Listener,Event> eventFormat) { List<SubjectAndListener> unordered = updateListEventListeners(subject, listener, null, eventFormat); subjectAndListeners = orderSubjectsAndListeners(unordered); }  synchronized void addListener(Subject subject, Listener listener, EventFormat<Subject,Listener,Event> eventFormat); synchronized void removeListener(Object subject, Object listener); @Override void setRelatedListener(Object subject, Object relatedListener); @Override void clearRelatedListener(Object subject, Object relatedListener); @Override void addDependency(EventList dependency, ListEventListener listener); @Override void removeDependency(EventList dependency, ListEventListener listener); @Override void setRelatedSubject(Object listener, Object relatedSubject); @Override void clearRelatedSubject(Object listener); synchronized List<Listener> getListeners(Object subject); void fireEvent(Subject subject, Event event, EventFormat<Subject,Listener,Event> eventFormat);  }