Revision 7f1d6816
Added by Patrick Plitzner about 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionElementCompareWrapper.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.workingSet.matrix; |
10 | 10 |
|
11 |
import java.util.HashSet; |
|
12 |
import java.util.Set; |
|
13 |
import java.util.UUID; |
|
14 |
|
|
11 | 15 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
12 | 16 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
13 | 17 |
import eu.etaxonomy.cdm.model.description.QuantitativeData; |
... | ... | |
20 | 24 |
public class DescriptionElementCompareWrapper { |
21 | 25 |
|
22 | 26 |
private DescriptionElementBase element; |
27 |
private Set<UUID> stateUuids = new HashSet<>(); |
|
28 |
private Float min = null; |
|
29 |
private Float max = null; |
|
23 | 30 |
|
24 | 31 |
public DescriptionElementCompareWrapper(DescriptionElementBase element) { |
25 | 32 |
this.element = element; |
33 |
if(element.isInstanceOf(CategoricalData.class)){ |
|
34 |
CategoricalData elementData = (CategoricalData)element; |
|
35 |
elementData.getStatesOnly().forEach(state->stateUuids.add(state.getUuid())); |
|
36 |
} |
|
37 |
else if(element.isInstanceOf(QuantitativeData.class)){ |
|
38 |
QuantitativeData elementData = (QuantitativeData)element; |
|
39 |
min = elementData.getMin(); |
|
40 |
max = elementData.getMax(); |
|
41 |
} |
|
26 | 42 |
} |
27 | 43 |
|
28 | 44 |
public DescriptionElementBase unwrap() { |
29 | 45 |
return element; |
30 | 46 |
} |
31 | 47 |
|
32 |
public boolean equals(DescriptionElementCompareWrapper other) { |
|
33 |
DescriptionElementBase otherElement = other.unwrap(); |
|
34 |
//TODO: Implement more elaborate equals() method |
|
35 |
if(element.isInstanceOf(CategoricalData.class) && otherElement instanceof CategoricalData){ |
|
36 |
boolean equal = true; |
|
37 |
CategoricalData otherData = (CategoricalData)otherElement; |
|
38 |
CategoricalData elementData = (CategoricalData)element; |
|
39 |
equal &= elementData.getStatesOnly().equals(otherData.getStatesOnly()); |
|
40 |
return equal; |
|
48 |
/** |
|
49 |
* {@inheritDoc} |
|
50 |
*/ |
|
51 |
@Override |
|
52 |
public int hashCode() { |
|
53 |
final int prime = 31; |
|
54 |
int result = 1; |
|
55 |
result = prime * result + ((max == null) ? 0 : max.hashCode()); |
|
56 |
result = prime * result + ((min == null) ? 0 : min.hashCode()); |
|
57 |
result = prime * result + ((stateUuids == null) ? 0 : stateUuids.hashCode()); |
|
58 |
return result; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* {@inheritDoc} |
|
63 |
*/ |
|
64 |
@Override |
|
65 |
public boolean equals(Object obj) { |
|
66 |
if (this == obj) { |
|
67 |
return true; |
|
41 | 68 |
} |
42 |
if(element.isInstanceOf(QuantitativeData.class) && otherElement instanceof QuantitativeData){ |
|
43 |
boolean equal = true; |
|
44 |
QuantitativeData otherData = (QuantitativeData)otherElement; |
|
45 |
QuantitativeData elementData = (QuantitativeData)element; |
|
46 |
if(elementData.getMin()!=null && otherData.getMin()==null){ |
|
47 |
return false; |
|
48 |
} |
|
49 |
if(elementData.getMin()==null && otherData.getMin()!=null){ |
|
69 |
if (obj == null) { |
|
70 |
return false; |
|
71 |
} |
|
72 |
if (getClass() != obj.getClass()) { |
|
73 |
return false; |
|
74 |
} |
|
75 |
DescriptionElementCompareWrapper other = (DescriptionElementCompareWrapper) obj; |
|
76 |
if (max == null) { |
|
77 |
if (other.max != null) { |
|
50 | 78 |
return false; |
51 | 79 |
} |
52 |
if(elementData.getMax()==null && otherData.getMax()!=null){ |
|
80 |
} else if (!max.equals(other.max)) { |
|
81 |
return false; |
|
82 |
} |
|
83 |
if (min == null) { |
|
84 |
if (other.min != null) { |
|
53 | 85 |
return false; |
54 | 86 |
} |
55 |
if(elementData.getMax()!=null && otherData.getMax()==null){ |
|
87 |
} else if (!min.equals(other.min)) { |
|
88 |
return false; |
|
89 |
} |
|
90 |
if (stateUuids == null) { |
|
91 |
if (other.stateUuids != null) { |
|
56 | 92 |
return false; |
57 | 93 |
} |
58 |
if(elementData.getMin()!=null && otherData.getMin()!=null){ |
|
59 |
equal &= elementData.getMin().equals(otherData.getMin()); |
|
60 |
} |
|
61 |
if(elementData.getMax()!=null && otherData.getMax()!=null){ |
|
62 |
equal &= elementData.getMax().equals(otherData.getMax()); |
|
63 |
} |
|
64 |
return equal; |
|
94 |
} else if (!stateUuids.equals(other.stateUuids)) { |
|
95 |
return false; |
|
65 | 96 |
} |
66 |
return false;
|
|
97 |
return true;
|
|
67 | 98 |
} |
68 | 99 |
|
69 | 100 |
} |
Also available in: Unified diff
ref #7095 Optimize aggregation and display of description elements