/** * Construct a {@link FunctionList} which stores the result of transforming * each source element using the given forward {@link Function}. If the * reverse {@link Function} is not null, {@link #add(Object)}, * {@link #add(int, Object)} and {@link #set(int, Object)} will execute * as expected. * * <p> Note: an {@link AdvancedFunction} can be specified for the forward * {@link Function} which allows the implementor a chance to examine the * prior value that was mapped to a source element when it must be remapped * due to a modification (from a call to {@link List#set}). * * @param source the EventList to decorate with a function transformation * @param forward the function to execute on each source element * @param reverse the function to map elements of FunctionList back to * element values in the source list */ public FunctionList(EventList<S> source, Function<S,E> forward, Function<E,S> reverse) { super(source); updateForwardFunction(forward); setReverseFunction(reverse); // save a reference to the source elements this.sourceElements = new ArrayList<S>(source); // map all of the elements within source this.mappedElements = new ArrayList<E>(source.size()); for (int i = 0, n = source.size(); i < n; i++) { this.mappedElements.add(forward(source.get(i))); } source.addListEventListener(this); }
/** * Construct a {@link FunctionList} which stores the result of transforming * each source element using the given forward {@link Function}. If the * reverse {@link Function} is not null, {@link #add(Object)}, * {@link #add(int, Object)} and {@link #set(int, Object)} will execute * as expected. * * <p> Note: an {@link AdvancedFunction} can be specified for the forward * {@link Function} which allows the implementor a chance to examine the * prior value that was mapped to a source element when it must be remapped * due to a modification (from a call to {@link List#set}). * * @param source the EventList to decorate with a function transformation * @param forward the function to execute on each source element * @param reverse the function to map elements of FunctionList back to * element values in the source list */ public FunctionList(EventList<S> source, Function<S,E> forward, Function<E,S> reverse) { super(source); updateForwardFunction(forward); setReverseFunction(reverse); // save a reference to the source elements this.sourceElements = new ArrayList<S>(source); // map all of the elements within source this.mappedElements = new ArrayList<E>(source.size()); for (int i = 0, n = source.size(); i < n; i++) { this.mappedElements.add(forward(source.get(i))); } source.addListEventListener(this); }
/** * Construct a {@link FunctionList} which stores the result of transforming * each source element using the given forward {@link Function}. If the * reverse {@link Function} is not null, {@link #add(Object)}, * {@link #add(int, Object)} and {@link #set(int, Object)} will execute * as expected. * * <p> Note: an {@link AdvancedFunction} can be specified for the forward * {@link Function} which allows the implementor a chance to examine the * prior value that was mapped to a source element when it must be remapped * due to a modification (from a call to {@link List#set}). * * @param source the EventList to decorate with a function transformation * @param forward the function to execute on each source element * @param reverse the function to map elements of FunctionList back to * element values in the source list */ public FunctionList(EventList<S> source, Function<S,E> forward, Function<E,S> reverse) { super(source); updateForwardFunction(forward); setReverseFunction(reverse); // save a reference to the source elements this.sourceElements = new ArrayList<S>(source); // map all of the elements within source this.mappedElements = new ArrayList<E>(source.size()); for (int i = 0, n = source.size(); i < n; i++) { this.mappedElements.add(forward(source.get(i))); } source.addListEventListener(this); }