FilteredList/SortedList
Martin Sladecek
martin.sladecek at oracle.com
Wed Jan 2 07:58:26 PST 2013
Hello,
I would like to start discussion about a new API for ObservableLists
that are filtered/sorted. This API was already in the repository before
2.0 was released, but was withdrawn (
http://javafx-jira.kenai.com/browse/RT-15302).
In the original API, there were 3 new classes: FilteredList, SortedList
and TransformationList (parent of the previous two). These 2 lists took
a different (Observable)List, acting as a view for that list, firing
change notifications when the view changed.
Since we have a different situation now, due to new (overlapping)
features in JDK 8, I'd like to propose a different API for FilteredList
and SortedList.
First of all, I don't think we need separate FilteredList and SortedList
classes anymore. With defender methods, we can have a similar approach
to JDK's stream(), having e.g. transform() method on ObservableList,
that would allow filtering & sorting of the list.
The original API allowed "batch" mode, but this is now basically covered
with List's stream(), although it's more cumbersome as you won't get a
List directly of a Stream, not to mention ObservableList, which is what
you need to pass as a model to various controls, like TableView.
Still, I'm not in favour of having this also in FX, but maybe something
like Iterable to ObservableList conversion method would ease the FX
development when using JDK 8 steams...
I want to keep TransformationList to serve both as a common parent for
all current and future "transformation" lists, but also returning
TransformationList on transform() call, having methods like filtered()
and sorted() directly on the TransformationList.
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.
Any comments?
Thanks,
-Martin
More information about the openjfx-dev
mailing list