@Test public void testSetForwardFunction() { EventList<Integer> source = new BasicEventList<>(); FunctionList<Integer, String> intsToStrings = new FunctionList<>(source, new IntegerToString()); ListConsistencyListener.install(intsToStrings); source.add(ZERO); assertEquals("0", intsToStrings.get(0)); intsToStrings.setForwardFunction(new IntegerToCardinalityString()); assertEquals("0th", intsToStrings.get(0)); source.add(NINE); assertEquals("9th", intsToStrings.get(1)); intsToStrings.setForwardFunction(new IntegerToString()); assertEquals("0", intsToStrings.get(0)); assertEquals("9", intsToStrings.get(1)); try { intsToStrings.setForwardFunction(null); fail("failed to receive IllegalArgumentException for null forward function"); } catch (IllegalArgumentException e) { } }
public void setForwardFunction(Function<S,E> forward) { updateForwardFunction(forward); updates.beginEvent(true); for (int i = 0, n = source.size(); i < n; i++) { final E newValue = forward(source.get(i)); final E oldValue = this.mappedElements.set(i, newValue); updates.elementUpdated(i, oldValue, newValue); } updates.commitEvent(); }
FunctionList extends TransformedList<S, E> implements RandomAccess { public void setForwardFunction(Function<S,E> forward) { updateForwardFunction(forward); updates.beginEvent(true); for (int i = 0, n = source.size(); i < n; i++) { final E newValue = forward(source.get(i)); final E oldValue = this.mappedElements.set(i, newValue); updates.elementUpdated(i, oldValue, newValue); } updates.commitEvent(); } }
FunctionList extends TransformedList<S, E> implements RandomAccess { public void setForwardFunction(Function<S,E> forward) { updateForwardFunction(forward); updates.beginEvent(true); for (int i = 0, n = source.size(); i < n; i++) { final E newValue = forward(source.get(i)); final E oldValue = this.mappedElements.set(i, newValue); updates.elementUpdated(i, oldValue, newValue); } updates.commitEvent(); } FunctionList(EventList<S> source, Function<S,E> forward);  FunctionList(EventList<S> source, Function<S,E> forward, Function<E,S> reverse); }
FunctionList extends TransformedList<S, E> implements RandomAccess { public void setForwardFunction(Function<S,E> forward) { updateForwardFunction(forward); updates.beginEvent(true); for (int i = 0, n = source.size(); i < n; i++) { final E newValue = forward(source.get(i)); final E oldValue = this.mappedElements.set(i, newValue); updates.elementUpdated(i, oldValue, newValue); } updates.commitEvent(); } FunctionList(EventList<S> source, Function<S,E> forward);  FunctionList(EventList<S> source, Function<S,E> forward, Function<E,S> reverse); void setForwardFunction(Function<S,E> forward); Function<S,E> getForwardFunction(); void setReverseFunction(Function<E,S> reverse); Function<E,S> getReverseFunction(); @Override void listChanged(ListEvent<S> listChanges); @Override E get(int index); @Override E remove(int index); @Override E set(int index, E value); @Override void add(int index, E value); @Override boolean removeIf(Predicate<? super E> filter); }
FunctionList extends TransformedList<S, E> implements RandomAccess { public void setForwardFunction(Function<S,E> forward) { updateForwardFunction(forward); updates.beginEvent(true); for (int i = 0, n = source.size(); i < n; i++) { final E newValue = forward(source.get(i)); final E oldValue = this.mappedElements.set(i, newValue); updates.elementUpdated(i, oldValue, newValue); } updates.commitEvent(); } FunctionList(EventList<S> source, Function<S,E> forward);  FunctionList(EventList<S> source, Function<S,E> forward, Function<E,S> reverse); void setForwardFunction(Function<S,E> forward); Function<S,E> getForwardFunction(); void setReverseFunction(Function<E,S> reverse); Function<E,S> getReverseFunction(); @Override void listChanged(ListEvent<S> listChanges); @Override E get(int index); @Override E remove(int index); @Override E set(int index, E value); @Override void add(int index, E value); @Override boolean removeIf(Predicate<? super E> filter);  }