net.corda.client.fxutils

## Class AggregatedList<A,E,K>

- net.corda.client.fxutils.AggregatedList<A,E,K>

-     public class AggregatedList<A,E,K>

  Given an ObservableList and a grouping key K, `class AggregatedList` groups the elements by the key into a fresh ObservableList for each group and exposes the groups as an observable list of As by calling assemble on each.

  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)

  See Also:
    `class AggregatedList`

- - ### Constructor Summary

    Constructors
    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 and a grouping key K, `class AggregatedList` groups the elements by the key into a fresh ObservableList for each group and exposes the groups as an observable list of As by calling assemble on each.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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)`

- - ### Constructor Detail

    - #### AggregatedList

          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 ObservableList and a grouping key K, `class AggregatedList` groups the elements by the key into a fresh ObservableList for each group and exposes the groups as an observable list of As by calling assemble on each.

      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)

      Parameters:
        `list` - The underlying list.
        `toKey` - Function to extract the key from an element.
        `assemble` - Function to assemble the aggregation into the exposed A.
      See Also:
        `class AggregatedList`

  - ### Method Detail

    - #### get

          public A get(int index)

    - #### getSourceIndex

          public int getSourceIndex(int index)

      We cannot implement this as aggregations are one to many

    - #### getSize

          public int getSize()

    - #### size

          public int size()

    - #### sourceChanged

          public void sourceChanged(javafx.collections.ListChangeListener.Change<? extends E> c)

    - #### getToKey

          public kotlin.jvm.functions.Function1<E,K> getToKey()

    - #### getAssemble

          public kotlin.jvm.functions.Function2<K,javafx.collections.ObservableList,A> getAssemble()

    - #### removeAt

          public java.lang.Object removeAt(int p)

    - #### remove

          public java.lang.Object remove(int p)