@Test public void testDiamondDependency() { SequenceDependenciesEventPublisher publisher = new SequenceDependenciesEventPublisher(); DependentSubjectListener a = new DependentSubjectListener("A", publisher); DependentSubjectListener b = new DependentSubjectListener("B", publisher); DependentSubjectListener c = new DependentSubjectListener("C", publisher); a.addListener(c); a.increment(10); assertEquals(10, a.latestRevision); assertEquals( 0, b.latestRevision); assertEquals(10, c.latestRevision); c.increment(5); assertEquals(10, a.latestRevision); assertEquals( 0, b.latestRevision); assertEquals(15, c.latestRevision); b.increment(20); assertEquals(10, a.latestRevision); assertEquals(20, b.latestRevision); assertEquals(15, c.latestRevision); b.addListener(c); assertEquals(10, a.latestRevision); assertEquals(20, b.latestRevision); assertEquals(20, c.latestRevision); b.increment(2); assertEquals(10, a.latestRevision); assertEquals(22, b.latestRevision); assertEquals(22, c.latestRevision); a.increment(15); assertEquals(25, a.latestRevision); assertEquals(22, b.latestRevision); assertEquals(25, c.latestRevision); a.addListener(b); assertEquals(25, a.latestRevision); assertEquals(25, b.latestRevision); assertEquals(25, c.latestRevision); a.increment(4); assertEquals(29, a.latestRevision); assertEquals(29, b.latestRevision); assertEquals(29, c.latestRevision); }
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);  }