Concatenated observable list

Nir Lisker nlisker at gmail.com
Sat Dec 31 20:43:20 UTC 2022


We can do better than that. Instead of introducing methods for specific
operations, like concat and retain, we can offer bulk operations on
collections. When John H. proposed the fluent bindings additions, we
discussed doing the same for collections after that.

At the very least, we can have a method that takes an observable collection
and a function that specifies the operation you want to perform. This will
be a lot more flexible.

I have been playing around with adding ObservableCollection as a first step
so that we don't need to multiply the methods for sets and lists. It's also
useful for an observableValues() on ObservableMap. I hit a few backwards
compatibility issues there.

I can share later some mock API I created as a sort of end goal, but it's
incomplete.

On Sat, Dec 31, 2022 at 8:15 PM Michael Strauß <michaelstrau2 at gmail.com>
wrote:

> FXCollections.concat(ObservableList...) can be used to create a new
> ObservableList that contains the concatenation of all elements of the
> source lists. This is useful to initialize the contents of the new
> ObservableList, but the returned list is not kept in sync with the
> source lists.
>
> I'm proposing to add a new method:
> FXCollections.concatenatedObservableList(ObservableList...)
>
> Like FXCollections.concat, it returns a list that contains the
> concatenation of all elements of the source lists. However, in this
> case the returned list is unmodifiable and is always kept in sync with
> the source lists. This can be useful to create a list where only parts
> of the list are under the control of the author, and other parts are
> derived from other lists.
>
> I'm interested to hear your thoughts on this. Here's the proposed
> specification of the new method:
>
> /**
>  * Creates a new unmodifiable {@code ObservableList} that contains
>  * the concatenation of the contents of the specified observable lists.
>  * In contrast to {@link #concat(ObservableList[])}, the list returned from
>  * this method is updated when any of the source lists are changed.
>  *
>  * @param lists the source lists
>  * @param <E> the element type
>  * @return an {@code ObservableList} that contains the concatenation
>  *         of the contents of {@code lists}
>  * @throws IndexOutOfBoundsException if the sum of the number of
>  *         elements contained in all source lists exceeds
>  *         {@link Integer#MAX_VALUE}
>  */
> @SafeVarargs
> public static <E> ObservableList<E> concatenatedObservableList(
>         ObservableList<E>... lists)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20221231/dc1f2909/attachment.htm>


More information about the openjfx-dev mailing list