Revision 82ca4447
Added by Andreas Müller about 8 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonComparator.java | ||
---|---|---|
18 | 18 |
|
19 | 19 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus; |
20 | 20 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; |
21 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
21 | 22 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
22 | 23 |
import eu.etaxonomy.cdm.model.name.ZoologicalName; |
23 | 24 |
import eu.etaxonomy.cdm.model.reference.Reference; |
... | ... | |
35 | 36 |
@SuppressWarnings("unused") |
36 | 37 |
private static final Logger logger = Logger.getLogger(TaxonComparator.class); |
37 | 38 |
|
39 |
private boolean includeRanks = false; |
|
40 |
|
|
41 |
/** |
|
42 |
* @param includeRanks |
|
43 |
*/ |
|
44 |
public TaxonComparator() { |
|
45 |
super(); |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* @param includeRanks |
|
50 |
*/ |
|
51 |
public TaxonComparator(boolean includeRanks) { |
|
52 |
super(); |
|
53 |
this.includeRanks = includeRanks; |
|
54 |
} |
|
55 |
|
|
56 |
|
|
38 | 57 |
/** |
39 | 58 |
* Returns an integer generated by comparing first the nomenclatural status and then the |
40 | 59 |
* {@link eu.etaxonomy.cdm.model.name.INomenclaturalReference#getYear() publication years} |
... | ... | |
198 | 217 |
result = intDate1.compareTo(intDate2); |
199 | 218 |
} |
200 | 219 |
|
201 |
if (result == 0){ |
|
220 |
if (result == 0 && includeRanks){ |
|
221 |
Rank rank1 = name1 == null? null : name1.getRank(); |
|
222 |
Rank rank2 = name2 == null? null : name2.getRank(); |
|
223 |
|
|
224 |
if (rank1 == null && rank2 == null){ |
|
225 |
result = 0; |
|
226 |
}else if (rank1 == null){ |
|
227 |
return 1; |
|
228 |
}else if (rank2 == null){ |
|
229 |
return -1; |
|
230 |
}else{ |
|
231 |
//for some strange reason compareTo for ranks returns 1 if rank2 is lower. So we add minus (-) |
|
232 |
result = - rank1.compareTo(rank2); |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
236 |
if (result == 0 && name1 != null && name2 != null){ |
|
202 | 237 |
result = name1.compareTo(name2); |
203 | 238 |
if (result != 0){ |
204 | 239 |
return result; |
Also available in: Unified diff
Include rank comparison in HomotypicGroupTaxonComparator #3338