@Test public void testCycleThrows() { SequenceDependenciesEventPublisher publisher = new SequenceDependenciesEventPublisher(); DependentSubjectListener a = new DependentSubjectListener("A", publisher); DependentSubjectListener b = new DependentSubjectListener("B", publisher); DependentSubjectListener c = new DependentSubjectListener("C", publisher); a.addListener(b); b.addListener(c); try { c.addListener(a); fail("Cycle not detected"); } catch(IllegalStateException e) { } publisher = new SequenceDependenciesEventPublisher(); DependentSubjectListener[] subjects = new DependentSubjectListener[10]; for(int i = 0; i < 10; i++) { subjects[i] = new DependentSubjectListener("" + i, publisher); if(i > 0) subjects[i-1].addListener(subjects[i]); } try { subjects[9].addListener(subjects[0]); fail("Cycle not detected"); } catch(IllegalStateException e) { } publisher = new SequenceDependenciesEventPublisher(); a = new DependentSubjectListener("A", publisher); try { a.addListener(a); fail("Cycle not detected"); } catch(IllegalStateException e) { } }
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);  }