public class AggregatedList<A,E,K>
Given an ObservableListclass AggregatedList
groups the elements by the key into a fresh
ObservableList
Changes done to elements of the input list are reflected in the observable list of the respective group, whereas additions/removals of elements in the underlying list are reflected in the exposed ObservableList by adding/deleting aggregations as expected.
The ordering of the exposed list is based on the hashCode of keys. The ordering of the groups themselves is based on the hashCode of elements.
Warning: If there are two elements E in the source list that have the same hashCode then it is not deterministic which one will be removed if one is removed from the source list!
Example: val statesGroupedByCurrency = AggregatedList(states, { state -> state.currency }) { currency, group -> object { val currency = currency val states = group } }
The above creates an observable list of (currency, statesOfCurrency) pairs.
Note that update events to the source list are discarded, assuming the key of elements does not change. TODO Should we handle this case? It requires additional bookkeeping of sourceIndex->(aggregationIndex, groupIndex)
class AggregatedList
Constructor and Description |
---|
AggregatedList(javafx.collections.ObservableList<? extends E> list,
kotlin.jvm.functions.Function1<? super E,? extends K> toKey,
kotlin.jvm.functions.Function2<? super K,? super javafx.collections.ObservableList<E>,? extends A> assemble)
Given an ObservableList
class AggregatedList groups the elements by the key into a fresh
ObservableList |
Modifier and Type | Method and Description |
---|---|
A |
get(int index) |
kotlin.jvm.functions.Function2<K,javafx.collections.ObservableList,A> |
getAssemble() |
int |
getSize() |
int |
getSourceIndex(int index)
We cannot implement this as aggregations are one to many
|
kotlin.jvm.functions.Function1<E,K> |
getToKey() |
java.lang.Object |
remove(int p) |
java.lang.Object |
removeAt(int p) |
int |
size() |
void |
sourceChanged(javafx.collections.ListChangeListener.Change<? extends E> c) |
public AggregatedList(javafx.collections.ObservableList<? extends E> list, kotlin.jvm.functions.Function1<? super E,? extends K> toKey, kotlin.jvm.functions.Function2<? super K,? super javafx.collections.ObservableList<E>,? extends A> assemble)
Given an ObservableListclass AggregatedList
groups the elements by the key into a fresh
ObservableList
Changes done to elements of the input list are reflected in the observable list of the respective group, whereas additions/removals of elements in the underlying list are reflected in the exposed ObservableList by adding/deleting aggregations as expected.
The ordering of the exposed list is based on the hashCode of keys. The ordering of the groups themselves is based on the hashCode of elements.
Warning: If there are two elements E in the source list that have the same hashCode then it is not deterministic which one will be removed if one is removed from the source list!
Example: val statesGroupedByCurrency = AggregatedList(states, { state -> state.currency }) { currency, group -> object { val currency = currency val states = group } }
The above creates an observable list of (currency, statesOfCurrency) pairs.
Note that update events to the source list are discarded, assuming the key of elements does not change. TODO Should we handle this case? It requires additional bookkeeping of sourceIndex->(aggregationIndex, groupIndex)
list
- The underlying list.toKey
- Function to extract the key from an element.assemble
- Function to assemble the aggregation into the exposed A.class AggregatedList
public A get(int index)
public int getSourceIndex(int index)
We cannot implement this as aggregations are one to many
public int getSize()
public int size()
public void sourceChanged(javafx.collections.ListChangeListener.Change<? extends E> c)
public kotlin.jvm.functions.Function1<E,K> getToKey()
public kotlin.jvm.functions.Function2<K,javafx.collections.ObservableList,A> getAssemble()
public java.lang.Object removeAt(int p)
public java.lang.Object remove(int p)