1 |
363387d2
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 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.api.utility;
|
10 |
|
|
|
11 |
|
|
import java.util.Comparator;
|
12 |
|
|
import java.util.Set;
|
13 |
|
|
|
14 |
|
|
import eu.etaxonomy.cdm.common.TreeNode;
|
15 |
|
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
16 |
|
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
17 |
|
|
|
18 |
|
|
/**
|
19 |
|
|
* Comparator to order distribution tree nodes according to the "natural" order
|
20 |
|
|
* defined by the ordered {@link NamedArea} vocabulary.
|
21 |
|
|
*
|
22 |
|
|
* @author a.mueller
|
23 |
|
|
* @date 04.04.2016
|
24 |
|
|
*
|
25 |
|
|
*/
|
26 |
|
|
public class DistributionNodeByAreaOrderComparator implements Comparator<TreeNode<Set<Distribution>, NamedArea>>{
|
27 |
|
|
|
28 |
|
|
@Override
|
29 |
|
|
public int compare(TreeNode<Set<Distribution>, NamedArea> node1, TreeNode<Set<Distribution>, NamedArea> node2) {
|
30 |
|
|
NamedArea area1 = node1.getNodeId();
|
31 |
|
|
NamedArea area2 = node2.getNodeId();
|
32 |
|
|
if (area1 == null && area2 == null){
|
33 |
|
|
return 0;
|
34 |
|
|
}else if (area1 == null){
|
35 |
|
|
return -1;
|
36 |
|
|
}else if (area2 == null){
|
37 |
|
|
return 1;
|
38 |
|
|
}else{
|
39 |
8dae61ea
|
Andreas Müller
|
return - area1.compareTo(area2); //term compare methods currently use wrong direction
|
40 |
363387d2
|
Andreas Müller
|
}
|
41 |
|
|
}
|
42 |
|
|
}
|