java.lang.Object
org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByComparator<T>
Type Parameters:
T - The type of the base objects carried in the TreeList
All Implemented Interfaces:
Comparator<Object>, IGroupByComparator<T>

public class GroupByComparator<T> extends Object implements IGroupByComparator<T>
Comparator that is used to sort the TreeList based on the groupBy information. Necessary for building the tree structure correctly.
See Also:
  • Field Details

    • groupByModel

      protected final GroupByModel groupByModel
    • columnAccessor

      protected final IColumnAccessor<T> columnAccessor
    • sortModel

      protected ISortModel sortModel
    • treeLayer

      protected IUniqueIndexLayer treeLayer
    • summaryColumnCache

      protected Map<Integer,Boolean> summaryColumnCache
      Cache that is used to increase the performance on sorting. The information whether a column is a summary column is only retrieved once and not calculated everytime.
    • groupByObjectComparatorCache

      protected Map<GroupByObject,GroupByComparator<T>.org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByComparator.GroupByObjectValueCache> groupByObjectComparatorCache
      Cache that is used to increase the performance on sorting by summary values. Necessary because the summary value is not carried by the GroupByObject but retrieved from the GroupByDataLayer. Since the retrieval is done via row index rather than the GroupByObject, the row index needs to be calculated in order to get the correct values. This is done via List.indexOf(Object) which is quite time consuming. So this cache is used to reduce the amount of indexOf calls drastically.

      As this cache is only used to increase the performance on sorting, the life time of this cache is reduced to a sort operation. It therefore gets cleared on every structural change.

  • Constructor Details

    • GroupByComparator

      public GroupByComparator(GroupByModel groupByModel, IColumnAccessor<T> columnAccessor)
      Parameters:
      groupByModel - The GroupByModel necessary to retrieve information about the current groupBy state.
      columnAccessor - The IColumnAccessor necessary to retrieve the column values of elements.
    • GroupByComparator

      public GroupByComparator(GroupByModel groupByModel, IColumnAccessor<T> columnAccessor, GroupByDataLayer<T> dataLayer)
      Parameters:
      groupByModel - The GroupByModel necessary to retrieve information about the current groupBy state.
      columnAccessor - The IColumnAccessor necessary to retrieve the column values of elements.
      dataLayer - The GroupByDataLayer that should be used to retrieve groupBy summary values for sorting the tree structure. Can be null to avoid retrieving and inspecting summary values on sorting.
  • Method Details

    • compare

      public int compare(Object o1, Object o2)
      Specified by:
      compare in interface Comparator<T>
    • isTreeColumn

      protected boolean isTreeColumn(int columnIndex)
      Parameters:
      columnIndex - The column index of the column that should be checked.
      Returns:
      true if the column at the given index is the tree column, false if not or if no treeLayer reference is set to this GroupByComparator
    • getComparator

      protected Comparator getComparator(int columnIndex)
      Parameters:
      columnIndex - The column index of the column for which the Comparator is requested.
      Returns:
      The Comparator that should be used to compare the values for elements in the given column. Returns the DefaultComparator in case there is no ISortModel configured for this GroupByComparator or no Comparator found for the given column.
    • getSortModel

      public ISortModel getSortModel()
      Specified by:
      getSortModel in interface IGroupByComparator<T>
      Returns:
      The ISortModel that is used to retrieve the column value comparators and the sort direction in case a groupBy value is sorted which will directly affect the tree structure build. Can be null which leads to a static tree structure that only allows sorting for leafs within groups.
    • setSortModel

      public void setSortModel(ISortModel sortModel)
      Specified by:
      setSortModel in interface IGroupByComparator<T>
      Parameters:
      sortModel - The ISortModel that is used to retrieve the column value comparators and the sort direction in case a groupBy value is sorted which will directly affect the tree structure build. Can be null which leads to a static tree structure that only allows sorting for leafs within groups.
    • setTreeLayer

      public void setTreeLayer(IUniqueIndexLayer treeLayer)
      Specified by:
      setTreeLayer in interface IGroupByComparator<T>
      Parameters:
      treeLayer - The IUniqueIndexLayer that should be used to retrieve config labels for a column. Needed to be able to determine if the column which is used for sorting is the tree column. Can be null which avoids specialized handling of tree / non tree columns.
    • setDataLayer

      public void setDataLayer(GroupByDataLayer<T> dataLayer)
      Specified by:
      setDataLayer in interface IGroupByComparator<T>
      Parameters:
      dataLayer - The GroupByDataLayer that should be used to retrieve groupBy summary values for sorting the tree structure. Can be null to avoid retrieving and inspecting summary values on sorting.
    • clearCache

      public void clearCache()
      Description copied from interface: IGroupByComparator
      For performance reasons the IGroupByComparator might cache several information e.g. retrieved via GroupByDataLayer. This method is intended to clear those cached informations to avoid memory leaks or sorting based on old information.
      Specified by:
      clearCache in interface IGroupByComparator<T>
    • isSummaryColumn

      protected Boolean isSummaryColumn(GroupByObject groupBy, int columnIndex)
      Parameters:
      groupBy - The GroupByObject for which the cache information is requested. Needed to retrieve the information if it is not yet cached.
      columnIndex - The column for which the cache information is requested.
      Returns:
      true if the given column is a summary column, false if not
    • getSummaryValueFromCache

      protected Object getSummaryValueFromCache(GroupByObject groupBy, int columnIndex)
      Returns the cached summary value for the given GroupByObject and column index. If there is no cache information yet, it will be build.
      Parameters:
      groupBy - The GroupByObject for which the cache information is requested.
      columnIndex - The column for which the cache information is requested.
      Returns:
      The summary value for the given GroupByObject and column index or null in case there is no GroupByDataLayer configured in for this GroupByComparator.