1
|
/**
|
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.util;
|
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
|
* @since 04.04.2016
|
24
|
*/
|
25
|
public class DistributionNodeByAreaOrderComparator implements Comparator<TreeNode<Set<Distribution>, NamedArea>>{
|
26
|
|
27
|
@Override
|
28
|
public int compare(TreeNode<Set<Distribution>, NamedArea> node1, TreeNode<Set<Distribution>, NamedArea> node2) {
|
29
|
if (node1.equals(node2)){
|
30
|
return 0;
|
31
|
}
|
32
|
|
33
|
NamedArea area1 = node1.getNodeId();
|
34
|
NamedArea area2 = node2.getNodeId();
|
35
|
if (area1 == null && area2 == null){
|
36
|
return 0;
|
37
|
}else if (area1 == null){
|
38
|
return -1;
|
39
|
}else if (area2 == null){
|
40
|
return 1;
|
41
|
}else{
|
42
|
return - area1.compareTo(area2); //term compare methods currently use wrong direction
|
43
|
}
|
44
|
}
|
45
|
}
|