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>
public class GroupByComparator<T> extends Object implements IGroupByComparator<T>
Comparator
that is used to sort theTreeList
based on the groupBy information. Necessary for building the tree structure correctly.- See Also:
GroupByTreeFormat
-
-
Field Summary
Fields Modifier and Type Field Description protected IColumnAccessor<T>
columnAccessor
protected GroupByModel
groupByModel
protected Map<GroupByObject,org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByComparator.GroupByObjectValueCache>
groupByObjectComparatorCache
Cache that is used to increase the performance on sorting by summary values.protected ISortModel
sortModel
protected Map<Integer,Boolean>
summaryColumnCache
Cache that is used to increase the performance on sorting.protected IUniqueIndexLayer
treeLayer
-
Constructor Summary
Constructors Constructor Description GroupByComparator(GroupByModel groupByModel, IColumnAccessor<T> columnAccessor)
GroupByComparator(GroupByModel groupByModel, IColumnAccessor<T> columnAccessor, GroupByDataLayer<T> dataLayer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearCache()
For performance reasons theIGroupByComparator
might cache several information e.g.int
compare(Object o1, Object o2)
protected Comparator
getComparator(int columnIndex)
ISortModel
getSortModel()
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 Detail
-
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,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 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 Detail
-
GroupByComparator
public GroupByComparator(GroupByModel groupByModel, IColumnAccessor<T> columnAccessor)
- 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 Detail
-
compare
public int compare(Object o1, Object o2)
- 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
protected Comparator getComparator(int columnIndex)
- 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
public ISortModel 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
public void setSortModel(ISortModel sortModel)
- 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
public void setTreeLayer(IUniqueIndexLayer treeLayer)
- 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
public void setDataLayer(GroupByDataLayer<T> dataLayer)
- 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
protected Boolean isSummaryColumn(GroupByObject groupBy, int columnIndex)
- 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
protected Object getSummaryValueFromCache(GroupByObject groupBy, int columnIndex)
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
.
-
-