Project

General

Profile

Download (1.38 KB) Statistics
| Branch: | Tag: | Revision:
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.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
 \* @since 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
        if (node1.equals(node2)){
31
            return 0;
32
        }
33

    
34
        NamedArea area1 = node1.getNodeId();
35
        NamedArea area2 = node2.getNodeId();
36
        if (area1 == null && area2 == null){
37
            return 0;
38
        }else if (area1 == null){
39
            return -1;
40
        }else if (area2 == null){
41
            return 1;
42
        }else{
43
            return - area1.compareTo(area2);  //term compare methods currently use wrong direction
44
        }
45
    }
46
}
(4-4/6)