### Question:
FunctionList extends TransformedList<S, E> implements RandomAccess { @Override public void add(int index, E value) { source.add(index, reverse(value)); } 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);  }### Answer:
@Test public void testAdd() { EventList<Integer> source = new BasicEventList<>(); FunctionList<Integer, String> intsToStrings = new FunctionList<>(source, new IntegerToString(), new StringToInteger()); ListConsistencyListener.install(intsToStrings); source.add(ZERO); source.add(ONE); source.add(TWO); assertEquals("0", intsToStrings.get(0)); assertEquals("1", intsToStrings.get(1)); assertEquals("2", intsToStrings.get(2)); intsToStrings.add("3"); intsToStrings.add("4"); intsToStrings.add("5"); assertEquals("3", intsToStrings.get(3)); assertEquals("4", intsToStrings.get(4)); assertEquals("5", intsToStrings.get(5)); intsToStrings.add(0, "8"); assertEquals("8", intsToStrings.get(0)); source = new BasicEventList<>(); intsToStrings = new FunctionList<>(source, new IntegerToString()); source.add(ZERO); assertEquals("0", intsToStrings.get(0)); try { intsToStrings.add("3"); fail("failed to receive an IllegalStateException for a call to add with no reverse function specified"); } catch (IllegalStateException e) {} try { intsToStrings.add(2, "3"); fail("failed to receive an IllegalStateException for a call to add with no reverse function specified"); } catch (IllegalStateException e) {} }
@Test public void testReorder() { SortedList<Integer> source = new SortedList<>(new BasicEventList<Integer>(), null); FunctionList<Integer, String> intsToStrings = new FunctionList<>(source, new AdvancedIntegerToString(), new StringToInteger()); ListConsistencyListener consistencyListener = ListConsistencyListener.install(intsToStrings); source.add(ONE); source.add(ZERO); assertEquals(2, consistencyListener.getEventCount()); source.setComparator(GlazedLists.comparableComparator()); assertEquals(3, consistencyListener.getEventCount()); }