| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using System.Collections.Generic; |
| | 6 | |
|
| | 7 | | namespace GDX.DataTables.ColumnSorters |
| | 8 | | { |
| | 9 | | abstract class ColumnSorterBase |
| | 10 | | { |
| | 11 | | protected readonly int ColumnIdentifier; |
| | 12 | | protected readonly DataTableBase DataTable; |
| | 13 | | public readonly List<int> EqualIdentifiers; |
| | 14 | | readonly int m_SortDirection; |
| | 15 | | readonly bool m_SupportMultiSort; |
| | 16 | |
|
| 0 | 17 | | protected ColumnSorterBase(DataTableBase dataTable, int rowCount, int columnIdentifier, int sortDirection, |
| | 18 | | bool supportMultiSort = false) |
| 0 | 19 | | { |
| 0 | 20 | | DataTable = dataTable; |
| 0 | 21 | | ColumnIdentifier = columnIdentifier; |
| 0 | 22 | | m_SortDirection = sortDirection; |
| 0 | 23 | | m_SupportMultiSort = supportMultiSort; |
| 0 | 24 | | EqualIdentifiers = m_SupportMultiSort ? new List<int>(rowCount) : null; |
| 0 | 25 | | } |
| | 26 | |
|
| | 27 | | protected int ProcessCompare(int compare, int lhsIdentifier = -1, int rhsIdentifier = -1) |
| 0 | 28 | | { |
| 0 | 29 | | if (compare == 0) |
| 0 | 30 | | { |
| | 31 | | // Same |
| 0 | 32 | | if (!m_SupportMultiSort) |
| 0 | 33 | | { |
| 0 | 34 | | return 0; |
| | 35 | | } |
| | 36 | |
|
| 0 | 37 | | EqualIdentifiers.Add(lhsIdentifier); |
| 0 | 38 | | EqualIdentifiers.Add(rhsIdentifier); |
| | 39 | |
|
| 0 | 40 | | return 0; |
| | 41 | | } |
| | 42 | |
|
| 0 | 43 | | if (m_SortDirection == 0) |
| 0 | 44 | | { |
| 0 | 45 | | return compare * -1; |
| | 46 | | } |
| | 47 | |
|
| 0 | 48 | | return compare; |
| 0 | 49 | | } |
| | 50 | | } |
| | 51 | | } |