Class GroupByComparator<T>
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>
Comparator
that is used to sort the TreeList
based on the
groupBy information. Necessary for building the tree structure correctly.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final IColumnAccessor<T>
protected final GroupByModel
protected Map<GroupByObject,
GroupByComparator<T>.org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByComparator.GroupByObjectValueCache> Cache that is used to increase the performance on sorting by summary values.protected ISortModel
Cache that is used to increase the performance on sorting.protected IUniqueIndexLayer
-
Constructor Summary
ConstructorDescriptionGroupByComparator
(GroupByModel groupByModel, IColumnAccessor<T> columnAccessor) GroupByComparator
(GroupByModel groupByModel, IColumnAccessor<T> columnAccessor, GroupByDataLayer<T> dataLayer) -
Method Summary
Modifier and TypeMethodDescriptionvoid
For performance reasons theIGroupByComparator
might cache several information e.g.int
protected Comparator
getComparator
(int columnIndex) protected Object
getSummaryValueFromCache
(GroupByObject groupBy, int columnIndex) Returns the cached summary value for the givenGroupByObject
and column index.protected Boolean
isSummaryColumn
(GroupByObject groupBy, int columnIndex) protected boolean
isTreeColumn
(int columnIndex) void
setDataLayer
(GroupByDataLayer<T> dataLayer) void
setSortModel
(ISortModel sortModel) void
setTreeLayer
(IUniqueIndexLayer treeLayer) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
groupByModel
-
columnAccessor
-
sortModel
-
treeLayer
-
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> groupByObjectComparatorCacheCache that is used to increase the performance on sorting by summary values. Necessary because the summary value is not carried by theGroupByObject
but retrieved from theGroupByDataLayer
. Since the retrieval is done via row index rather than theGroupByObject
, the row index needs to be calculated in order to get the correct values. This is done viaList.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
- Parameters:
groupByModel
- TheGroupByModel
necessary to retrieve information about the current groupBy state.columnAccessor
- TheIColumnAccessor
necessary to retrieve the column values of elements.
-
GroupByComparator
public GroupByComparator(GroupByModel groupByModel, IColumnAccessor<T> columnAccessor, GroupByDataLayer<T> dataLayer) - Parameters:
groupByModel
- TheGroupByModel
necessary to retrieve information about the current groupBy state.columnAccessor
- TheIColumnAccessor
necessary to retrieve the column values of elements.dataLayer
- TheGroupByDataLayer
that should be used to retrieve groupBy summary values for sorting the tree structure. Can benull
to avoid retrieving and inspecting summary values on sorting.
-
-
Method Details
-
compare
- Specified by:
compare
in interfaceComparator<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 thisGroupByComparator
-
getComparator
- Parameters:
columnIndex
- The column index of the column for which theComparator
is requested.- Returns:
- The
Comparator
that should be used to compare the values for elements in the given column. Returns theDefaultComparator
in case there is noISortModel
configured for thisGroupByComparator
or noComparator
found for the given column.
-
getSortModel
- Specified by:
getSortModel
in interfaceIGroupByComparator<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 benull
which leads to a static tree structure that only allows sorting for leafs within groups.
-
setSortModel
- Specified by:
setSortModel
in interfaceIGroupByComparator<T>
- Parameters:
sortModel
- TheISortModel
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 benull
which leads to a static tree structure that only allows sorting for leafs within groups.
-
setTreeLayer
- Specified by:
setTreeLayer
in interfaceIGroupByComparator<T>
- Parameters:
treeLayer
- TheIUniqueIndexLayer
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 benull
which avoids specialized handling of tree / non tree columns.
-
setDataLayer
- Specified by:
setDataLayer
in interfaceIGroupByComparator<T>
- Parameters:
dataLayer
- TheGroupByDataLayer
that should be used to retrieve groupBy summary values for sorting the tree structure. Can benull
to avoid retrieving and inspecting summary values on sorting.
-
clearCache
public void clearCache()Description copied from interface:IGroupByComparator
For performance reasons theIGroupByComparator
might cache several information e.g. retrieved viaGroupByDataLayer
. This method is intended to clear those cached informations to avoid memory leaks or sorting based on old information.- Specified by:
clearCache
in interfaceIGroupByComparator<T>
-
isSummaryColumn
- Parameters:
groupBy
- TheGroupByObject
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
Returns the cached summary value for the givenGroupByObject
and column index. If there is no cache information yet, it will be build.- Parameters:
groupBy
- TheGroupByObject
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 ornull
in case there is noGroupByDataLayer
configured in for thisGroupByComparator
.
-