1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.model.name;
|
10
|
|
11
|
import java.util.Comparator;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
14
|
|
15
|
/**
|
16
|
* @author k.luther
|
17
|
* @since 21.03.2017
|
18
|
*
|
19
|
*/
|
20
|
public class TypeComparator implements Comparator<TypeDesignationBase<?>> {
|
21
|
|
22
|
/**
|
23
|
* {@inheritDoc}
|
24
|
*/
|
25
|
@Override
|
26
|
public int compare(TypeDesignationBase<?> o1, TypeDesignationBase<?> o2) {
|
27
|
/*
|
28
|
* Sortierung:
|
29
|
1. Status der Typen: a) holo, lecto, neo, syn, b) epi, paralecto, c) para (wenn überhaupt) – die jeweiligen iso immer direct mit dazu
|
30
|
2. Land
|
31
|
3. Sammler
|
32
|
4. Nummer
|
33
|
|
34
|
Aufbau der Typusinformationen:
|
35
|
Land: Lokalität mit Höhe und Koordinaten; Datum; Sammler Nummer (Herbar/Barcode, Typusart; Herbar/Barcode, Typusart …)
|
36
|
|
37
|
*/
|
38
|
int result = 0;
|
39
|
if(o1 == null && o2 == null){
|
40
|
return result;
|
41
|
}
|
42
|
if (o1 == null){
|
43
|
return -1;
|
44
|
}
|
45
|
if (o2 == null){
|
46
|
return 1;
|
47
|
}
|
48
|
|
49
|
TypeDesignationStatusBase<?> status1 = getStatus(o1);
|
50
|
TypeDesignationStatusBase<?> status2 = getStatus(o2);
|
51
|
|
52
|
result = compareStatus(status1, status2);
|
53
|
if (result != 0){
|
54
|
return result;
|
55
|
}
|
56
|
|
57
|
// result = compareLand(o1, o2);
|
58
|
// if (result != 0){
|
59
|
// return result;
|
60
|
// }
|
61
|
// result = compareCollector(status1, status2);
|
62
|
// if (result != 0){
|
63
|
// return result;
|
64
|
// }
|
65
|
//
|
66
|
// result = compareNumber(status1, status2);
|
67
|
|
68
|
|
69
|
return result;
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* @param o1
|
74
|
* @return
|
75
|
*/
|
76
|
private TypeDesignationStatusBase<?> getStatus(TypeDesignationBase<?> td) {
|
77
|
if (td.isInstanceOf(TypeDesignationBase.class)){
|
78
|
return CdmBase.deproxy(td, TypeDesignationBase.class).getTypeStatus();
|
79
|
}else{
|
80
|
return null;
|
81
|
}
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* @param status1
|
86
|
* @param status2
|
87
|
* @return
|
88
|
*/
|
89
|
private int compareNumber(SpecimenTypeDesignation status1, SpecimenTypeDesignation status2) {
|
90
|
// TODO Auto-generated method stub
|
91
|
return 0;
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* @param status1
|
96
|
* @param status2
|
97
|
* @return
|
98
|
*/
|
99
|
private int compareCollector(SpecimenTypeDesignation status1, SpecimenTypeDesignation status2) {
|
100
|
// TODO Auto-generated method stub
|
101
|
return 0;
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* @param status1
|
106
|
* @param status2
|
107
|
* @return
|
108
|
*/
|
109
|
private int compareLand(SpecimenTypeDesignation type1, SpecimenTypeDesignation type2) {
|
110
|
return 0;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* @param status1
|
115
|
* @param status2
|
116
|
* @return
|
117
|
*/
|
118
|
private int compareStatus(TypeDesignationStatusBase status1, TypeDesignationStatusBase status2) {
|
119
|
//Status der Typen: a) holo, lecto, neo, syn, b) epi, paralecto, c) para (wenn überhaupt) – die jeweiligen iso immer direct mit dazu
|
120
|
|
121
|
|
122
|
if (status1 == status2){
|
123
|
return 0;
|
124
|
}
|
125
|
|
126
|
if (status1 == null){
|
127
|
return -1;
|
128
|
}
|
129
|
if (status2 == null){
|
130
|
return 1;
|
131
|
}
|
132
|
|
133
|
if (status1.getOrderIndex() > status2.getOrderIndex()){
|
134
|
return 1;
|
135
|
}
|
136
|
|
137
|
if (status2.getOrderIndex() > status1.getOrderIndex()){
|
138
|
return -1;
|
139
|
}
|
140
|
|
141
|
// if (isHighestType(status1) && isHighestType(status2)){
|
142
|
// return 0;
|
143
|
// }
|
144
|
// if (isHighestType(status1) && !isHighestType(status2)){
|
145
|
// return 1;
|
146
|
// }
|
147
|
// if (isHighestType(status2) && !isHighestType(status1)) {
|
148
|
// return -1;
|
149
|
// }
|
150
|
//
|
151
|
// if (isSecondLevel(status1) && isSecondLevel(status2)){
|
152
|
// return 0;
|
153
|
// }
|
154
|
// if (isSecondLevel(status1) && !isSecondLevel(status2)){
|
155
|
// return 1;
|
156
|
// }
|
157
|
//
|
158
|
// if (isSecondLevel(status2) && !isSecondLevel(status1)){
|
159
|
// return -1;
|
160
|
// }
|
161
|
//
|
162
|
// if (status1.equals(SpecimenTypeDesignationStatus.PARATYPE()) && isUndefinedLevel(status2)){
|
163
|
// return 1;
|
164
|
// }
|
165
|
// if (status2.equals(SpecimenTypeDesignationStatus.PARATYPE()) && isUndefinedLevel(status1)){
|
166
|
// return -1;
|
167
|
// }
|
168
|
//
|
169
|
// if (isUndefinedLevel(status1) && isUndefinedLevel(status2)){
|
170
|
// return 0;
|
171
|
// }
|
172
|
|
173
|
return 0;
|
174
|
}
|
175
|
|
176
|
private boolean isHighestType(SpecimenTypeDesignationStatus status){
|
177
|
if (status.equals(SpecimenTypeDesignationStatus.LECTOTYPE())
|
178
|
|| status.equals(SpecimenTypeDesignationStatus.HOLOTYPE())
|
179
|
|| status.equals(SpecimenTypeDesignationStatus.NEOTYPE())
|
180
|
|| status.equals(SpecimenTypeDesignationStatus.SYNTYPE())){
|
181
|
return true;
|
182
|
}else{
|
183
|
return false;
|
184
|
}
|
185
|
}
|
186
|
|
187
|
private boolean isSecondLevel(SpecimenTypeDesignationStatus status){
|
188
|
if (status.equals(SpecimenTypeDesignationStatus.EPITYPE())
|
189
|
|| status.equals(SpecimenTypeDesignationStatus.PARALECTOTYPE())){
|
190
|
return true;
|
191
|
}else{
|
192
|
return false;
|
193
|
}
|
194
|
}
|
195
|
|
196
|
private boolean isUndefinedLevel(SpecimenTypeDesignationStatus status){
|
197
|
if (status.equals(SpecimenTypeDesignationStatus.TYPE())
|
198
|
|| status.equals(SpecimenTypeDesignationStatus.UNSPECIFIC())){
|
199
|
return true;
|
200
|
}else{
|
201
|
return false;
|
202
|
}
|
203
|
}
|
204
|
}
|