1 |
278a5e0a
|
Katja Luther
|
/**
|
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 |
|
|
|
15 |
|
|
/**
|
16 |
|
|
* @author k.luther
|
17 |
|
|
* @since 28.11.2018
|
18 |
|
|
*
|
19 |
|
|
*/
|
20 |
|
|
public class TaxonDistributionDtoComparator implements Comparator<TaxonDistributionDTO> {
|
21 |
|
|
|
22 |
|
|
/**
|
23 |
|
|
* {@inheritDoc}
|
24 |
|
|
*/
|
25 |
|
|
@Override
|
26 |
|
|
public int compare(TaxonDistributionDTO arg0, TaxonDistributionDTO arg1) {
|
27 |
|
|
if (arg0 == arg1){
|
28 |
|
|
return 0;
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
if (arg0.getTaxonUuid().equals(arg1.getTaxonUuid())){
|
32 |
|
|
return 0;
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
String name1 = arg0.getNameCache();
|
36 |
|
|
String name2 = arg1.getNameCache();
|
37 |
2e385b93
|
Katja Luther
|
Integer rankTax1 = arg0.getRankOrderIndex();
|
38 |
|
|
Integer rankTax2 = arg1.getRankOrderIndex();
|
39 |
278a5e0a
|
Katja Luther
|
|
40 |
|
|
if (rankTax1 == null && rankTax2 != null){
|
41 |
|
|
return 1;
|
42 |
|
|
}else if(rankTax2 == null && rankTax1 != null){
|
43 |
|
|
return -1;
|
44 |
|
|
}else if (rankTax1 == null && rankTax2 == null || rankTax1.equals(rankTax2)) {
|
45 |
|
|
//same rank, order by name
|
46 |
|
|
return name1.compareTo(name2);
|
47 |
2e385b93
|
Katja Luther
|
}else if (rankTax1 != null && rankTax1<rankTax2){
|
48 |
|
|
return -1;
|
49 |
278a5e0a
|
Katja Luther
|
}
|
50 |
|
|
|
51 |
|
|
return 0;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
}
|