FilteredList/SortedList

Richard Bair richard.bair at oracle.com
Tue Jan 8 09:04:53 PST 2013


The other end of the conversation has drifted into making sure the requirements match what TableView needs. However on a pure "collections" based API discussion:

> So overall, the new API would look like this:
> 
> public abstract class TransformationList<E, F> implements ObservableList<E> {
> 
>    protected TransformationList(ObservableList<? extends F> source);
> 
>    public final ObservableList<? extends F> getDirectSource();
> 
>    // The first non-transformation list in the chain.
>    public final ObservableList<?> getOriginalSource();
> 
>    // Called when a change from the source is triggered.
>    protected abstract void onSourceChanged(Change<? extends F> c);
> 
>    // Maps the index of this list's element to an index in the direct source list.
>    public abstract int getSourceIndex(int index);
> 
>    public final int getOriginalSourceIndex(int index);
> 
>    public final TransformationList<E, E> filtered(Predicate<? super E> predicate);
> 
>    public final TransformationList<E, E> sorted(Comparator<? super E> comparator);
> 
> }
> 
> ObservableList<E> interface would get a new defender method:
> 
> public TransformationList<E, E> transform();
> 
> this would return TransformationList representation of the current list.
> 
> Another appoach would be to have filtered(), sorted() directly on ObservableList as a defender methods, which would remove the necessity of calling transform() before filtered()/sorted(), but I find the first one more consistent with JDK API.

I like the TransformationList class, although it seems like methods for mapping from source index & original source index to current index is needed for symmetry with getSourceIndex and getOriginalSourceIndex. I like the names "filtered" and "sorted" because they imply it is continuously filtered / sorted as opposed to occurring only one time (that is the case I hope? Maybe not? How would it be implemented in the general case? If it is a one-time filter / sort, then it should just say "filter" and "sort" as it is a verb not an adjective -- that is, it describes the operation to perform rather than a state of the resulting list).

I don't much find need of the transform() method, it does seem like filtered / sorted should just go on ObservableList via defender methods. This of course couldn't be done until we switch building from 1.7 over to 1.8.

Richard


More information about the openjfx-dev mailing list