blob: f3a9b049b575648a53b2794297f3fcbb80a30788 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*******************************************************************************
* Copyright (c) 2012, 2013 Original authors and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Original authors and others - initial API and implementation
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy;
import org.eclipse.nebula.widgets.nattable.config.DefaultComparator;
/**
* This class is used to add tree items that are added to the tree path for grouping purposes.
* Contains the value that is used for grouping and the grouping index to ensure the correct
* ordering.
*/
public class GroupByObject implements Comparable<GroupByObject> {
/**
* The order index of the grouping.
*/
private final Integer groupByIndex;
/**
* The value that is used for grouping.
*/
private final Object value;
/**
* @param groupByIndex The order index of the grouping.
* @param value The value that is used for grouping.
*/
public GroupByObject(int groupByIndex, Object value) {
this.groupByIndex = groupByIndex;
this.value = value;
}
/**
* @return The order index of the grouping.
*/
public int getGroupByIndex() {
return groupByIndex;
}
/**
* @return The value that is used for grouping.
*/
public Object getValue() {
return value;
}
@Override
public String toString() {
//Without adjusting a lot of API and adding dependencies to the DataLayer and the ConfigRegistry
//we can not get the IDataConverter here. It might be solvable with the next generation because
//we can then inject the necessary values. Until then you should consider implementing toString()
return value.toString();
}
@Override
public int compareTo(GroupByObject o) {
//if we have several groupings, the comparison is performed on the group by order
int result = this.groupByIndex.compareTo(o.groupByIndex);
if (result == 0) {
//if the datatypes are not the same here, comparison is not possible
if (this.value == null || o.value == null || this.value.getClass().equals(o.value.getClass())) {
result = DefaultComparator.getInstance().compare(value, o.value);
}
}
return result;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + groupByIndex;
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
GroupByObject other = (GroupByObject) obj;
if (groupByIndex != other.groupByIndex)
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
}
|