1
|
/**
|
2
|
* Copyright (C) 2018 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.taxeditor.editor.view.checklist.e4;
|
10
|
|
11
|
import java.util.Comparator;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
|
14
|
import eu.etaxonomy.cdm.model.name.Rank;
|
15
|
|
16
|
/**
|
17
|
* @author k.luther
|
18
|
* @since 28.11.2018
|
19
|
*
|
20
|
*/
|
21
|
public class TaxonDistributionDtoComparator implements Comparator<TaxonDistributionDTO> {
|
22
|
|
23
|
/**
|
24
|
* {@inheritDoc}
|
25
|
*/
|
26
|
@Override
|
27
|
public int compare(TaxonDistributionDTO arg0, TaxonDistributionDTO arg1) {
|
28
|
if (arg0 == arg1){
|
29
|
return 0;
|
30
|
}
|
31
|
|
32
|
if (arg0.getTaxonUuid().equals(arg1.getTaxonUuid())){
|
33
|
return 0;
|
34
|
}
|
35
|
|
36
|
String name1 = arg0.getNameCache();
|
37
|
String name2 = arg1.getNameCache();
|
38
|
Rank rankTax1 = arg0.getRank();
|
39
|
Rank rankTax2 = arg1.getRank();
|
40
|
|
41
|
if (rankTax1 == null && rankTax2 != null){
|
42
|
return 1;
|
43
|
}else if(rankTax2 == null && rankTax1 != null){
|
44
|
return -1;
|
45
|
}else if (rankTax1 != null && rankTax1.isHigher(rankTax2)){
|
46
|
return -1;
|
47
|
}else if (rankTax1 == null && rankTax2 == null || rankTax1.equals(rankTax2)) {
|
48
|
//same rank, order by name
|
49
|
return name1.compareTo(name2);
|
50
|
}
|
51
|
|
52
|
return 0;
|
53
|
}
|
54
|
|
55
|
}
|