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

public Class GeneralAggregatedListBinding<T, S, U, R>

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

Represents a generic binding that aggregates results from a nested collection structure. This class listens to changes not only in the top-level observable list of type T but also in the nested observable lists of type S associated with each T. The binding performs aggregation operations over these lists to produce a final result of type R, making it ideal for applications with dynamic data models.

This class is designed to work with a stable source of ObservableLists provided by the itemToListFunction. It is crucial for the correct operation of this binding that the same instance of ObservableList is returned for any given item in the lifecycle of that item. Changing the underlying ObservableList instances during the lifecycle can lead to unpredictable behavior and potential memory leaks.

Important Considerations:

Field Summary

Modifier and TypeField and Description
private final Function<List<S>, U>
private final Function<Stream<U>, 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
GeneralAggregatedListBinding(ObservableList<T>
The observable list of source items. This list should be stable during the lifecycle of the binding, meaning that elements should not be replaced with different instances to ensure reliable behavior.
source
,
Function<T, ObservableList<S>>
A function that maps each element of the source list, T, to an observable list of S. This function must consistently return the same instance of ObservableList for any given item throughout its lifecycle to avoid erratic behavior and potential memory leaks.
itemToListFunction
,
Function<List<S>, U>
A function that aggregates a list of S into an intermediate result U, based on the current data in those lists.
aggregationFunction
,
Function<Stream<U>, R>
A function that aggregates a list of intermediate results U into the final result R, which represents the aggregate of the entire structure.
finalAggregationFunction
)

Constructs a new GeneralAggregatedListBinding.

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<List<S>, U> aggregationFunction
finalAggregationFunctionback to summary
private final Function<Stream<U>, R> finalAggregationFunction
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

GeneralAggregatedListBindingback to summary
public GeneralAggregatedListBinding(ObservableList<T> source, Function<T, ObservableList<S>> itemToListFunction, Function<List<S>, U> aggregationFunction, Function<Stream<U>, R> finalAggregationFunction)

Constructs a new GeneralAggregatedListBinding. This constructor initializes the binding based on a source list, a function to map each element of the source to an observable list, and two aggregation functions. It sets up listeners on the source list and all nested lists, allowing the binding to react dynamically to changes within these lists.

Parameters
source:ObservableList<T>

The observable list of source items. This list should be stable during the lifecycle of the binding, meaning that elements should not be replaced with different instances to ensure reliable behavior.

itemToListFunction:Function<T, ObservableList<S>>

A function that maps each element of the source list, T, to an observable list of S. This function must consistently return the same instance of ObservableList for any given item throughout its lifecycle to avoid erratic behavior and potential memory leaks.

aggregationFunction:Function<List<S>, U>

A function that aggregates a list of S into an intermediate result U, based on the current data in those lists.

finalAggregationFunction:Function<Stream<U>, R>

A function that aggregates a list of intermediate results U into the final result R, which represents the aggregate of the entire structure.

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)