@Test public void testPropertyChanges() throws Exception { final EventList<String> source = new BasicEventList<>(); final PropertyChangeCounter counter = new PropertyChangeCounter(); final Calculation<String> elementAt = Calculations.elementAt(source, 0, "default"); elementAt.addPropertyChangeListener(counter); assertEquals("default", elementAt.getValue()); assertEquals(0, counter.getCountAndReset()); source.add("a"); assertEquals("a", elementAt.getValue()); assertEquals(1, counter.getCountAndReset()); source.add("b"); assertEquals("a", elementAt.getValue()); assertEquals(0, counter.getCountAndReset()); source.set(0, "c"); assertEquals("c", elementAt.getValue()); assertEquals(1, counter.getCountAndReset()); source.set(1, "d"); assertEquals("c", elementAt.getValue()); assertEquals(0, counter.getCountAndReset()); source.remove(0); assertEquals("d", elementAt.getValue()); assertEquals(1, counter.getCountAndReset()); source.remove(0); assertEquals("default", elementAt.getValue()); assertEquals(1, counter.getCountAndReset()); }
public ElementAt(EventList<E> source, int index, E defaultValue) { super(source.size() > index ? source.get(index) : defaultValue); this.source = source; this.index = index; this.defaultValue = defaultValue; this.source.addListEventListener(this); }
ElementAt extends AbstractCalculation<E> implements ListEventListener<E> { public ElementAt(EventList<E> source, int index, E defaultValue) { super(source.size() > index ? source.get(index) : defaultValue); this.source = source; this.index = index; this.defaultValue = defaultValue; this.source.addListEventListener(this); } }
ElementAt extends AbstractCalculation<E> implements ListEventListener<E> { public ElementAt(EventList<E> source, int index, E defaultValue) { super(source.size() > index ? source.get(index) : defaultValue); this.source = source; this.index = index; this.defaultValue = defaultValue; this.source.addListEventListener(this); } ElementAt(EventList<E> source, int index, E defaultValue); }
ElementAt extends AbstractCalculation<E> implements ListEventListener<E> { public ElementAt(EventList<E> source, int index, E defaultValue) { super(source.size() > index ? source.get(index) : defaultValue); this.source = source; this.index = index; this.defaultValue = defaultValue; this.source.addListEventListener(this); } ElementAt(EventList<E> source, int index, E defaultValue); @Override void dispose(); @Override void listChanged(ListEvent<E> listChanges); }
ElementAt extends AbstractCalculation<E> implements ListEventListener<E> { public ElementAt(EventList<E> source, int index, E defaultValue) { super(source.size() > index ? source.get(index) : defaultValue); this.source = source; this.index = index; this.defaultValue = defaultValue; this.source.addListEventListener(this); } ElementAt(EventList<E> source, int index, E defaultValue); @Override void dispose(); @Override void listChanged(ListEvent<E> listChanges);  }