Top Description Fields Constructors Methods
com.dlsc.gemsfx.binding

public Class AggregatedListBinding<T, S, R>

extends ObjectBinding<R>
Class Inheritance
Type Parameters
<T>
the type of the elements in the source list
<S>
the type of the elements in the nested lists
<R>
the type of the result computed from the stream of elements in the nested lists
Imports
javafx.beans.binding.ObjectBinding, javafx.beans.property.ObjectProperty, .SimpleListProperty, javafx.collections.ListChangeListener, .ObservableList, .WeakListChangeListener, java.util.List, .Objects, java.util.function.Function, java.util.stream.Stream

Binds an ObservableList of items to a computed value based on the elements of their associated nested ObservableLists. This binding listens for changes not only in the top-level list but also in the nested lists of each item. It aggregates or computes values dynamically as the lists change, making it ideal for applications where the data model is highly dynamic.

This class is designed to be used with a consistent source of ObservableLists provided by the itemToListFunction. The function must return the same ObservableList instance for any given item throughout its lifecycle to ensure correct behavior and prevent memory leaks.

Important Considerations:

Field Summary

Modifier and TypeField and Description
private final Function<Stream<S>, R>
private final Function<T, ObservableList<S>>
private final ListChangeListener<Object>
private final ObservableList<T>
private final ListChangeListener<T>
private final WeakListChangeListener<Object>
private final WeakListChangeListener<T>

Constructor Summary

AccessConstructor and Description
public
AggregatedListBinding(ObservableList<T>
the observable list of source items that should be stable (not dynamically replaced).
source
,
final Function<T, ObservableList<S>>
a function to retrieve an observable list from each source item, which must consistently return the same observable list instance for any given item throughout its lifecycle.
itemToListFunction
,
Function<Stream<S>, R>
a function to compute a result from all elements in the nested lists, based on current data in those lists.
aggregationFunction
)

Constructs a new AggregatedListBinding.

Method Summary

Modifier and TypeMethod and Description
protected R
computeValue()

Implements abstract javafx.beans.binding.ObjectBinding.computeValue.

Calculates the current value of this binding.

private void
private void
public void
dispose()

Overrides javafx.beans.binding.ObjectBinding.dispose.

Implements javafx.beans.binding.Binding.dispose.

A default implementation of dispose() that is empty.

private void
private void
Inherited from javafx.beans.binding.ObjectBinding:
addListeneraddListenerallowValidationbindgetgetDependenciesinvalidateisObservedisValidonInvalidatingremoveListenerremoveListenertoStringunbind

Field Detail

aggregationFunctionback to summary
private final Function<Stream<S>, R> aggregationFunction
itemToListFunctionback to summary
private final Function<T, ObservableList<S>> itemToListFunction
nestedListChangeListenerback to summary
private final ListChangeListener<Object> nestedListChangeListener
sourceback to summary
private final ObservableList<T> source
sourceListChangeListenerback to summary
private final ListChangeListener<T> sourceListChangeListener
weakNestedListChangeListenerback to summary
private final WeakListChangeListener<Object> weakNestedListChangeListener
weakSourceListChangeListenerback to summary
private final WeakListChangeListener<T> weakSourceListChangeListener

Constructor Detail

AggregatedListBindingback to summary
public AggregatedListBinding(ObservableList<T> source, final Function<T, ObservableList<S>> itemToListFunction, Function<Stream<S>, R> aggregationFunction)

Constructs a new AggregatedListBinding.

Parameters
source:ObservableList<T>

the observable list of source items that should be stable (not dynamically replaced).

itemToListFunction:Function<T, ObservableList<S>>

a function to retrieve an observable list from each source item, which must consistently return the same observable list instance for any given item throughout its lifecycle.

aggregationFunction:Function<Stream<S>, R>

a function to compute a result from all elements in the nested lists, based on current data in those lists.

Method Detail

computeValueback to summary
protected R computeValue()

Implements abstract javafx.beans.binding.ObjectBinding.computeValue.

Doc from javafx.beans.binding.ObjectBinding.computeValue.

Calculates the current value of this binding.

Classes extending ObjectBinding have to provide an implementation of computeValue.

Annotations
@Override
convertToListAndSafeAddListenerback to summary
private void convertToListAndSafeAddListener(T item)
convertToListAndSafeRemoveListenerback to summary
private void convertToListAndSafeRemoveListener(T item)
disposeback to summary
public void dispose()

Overrides javafx.beans.binding.ObjectBinding.dispose.

Implements javafx.beans.binding.Binding.dispose.

Doc from javafx.beans.binding.ObjectBinding.dispose.

A default implementation of dispose() that is empty.

Annotations
@Override
safeAddListenerback to summary
private void safeAddListener(ObservableList<S> list)
safeRemoveListenerback to summary
private void safeRemoveListener(ObservableList<S> list)