Project

General

Profile

Download (1.3 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.service;
10

    
11
import java.util.Comparator;
12
import java.util.Set;
13

    
14
import org.apache.commons.lang.StringUtils;
15

    
16
import eu.etaxonomy.cdm.common.TreeNode;
17
import eu.etaxonomy.cdm.model.description.Distribution;
18
import eu.etaxonomy.cdm.model.location.NamedArea;
19

    
20
public class DistributionNodeByAreaLabelComparator implements Comparator<TreeNode<Set<Distribution>, NamedArea>>{
21
    @Override
22
    public int compare(TreeNode<Set<Distribution>, NamedArea> node1, TreeNode<Set<Distribution>, NamedArea> node2) {
23
        String label1 = node1.getNodeId().getLabel();
24
        String label2 = node2.getNodeId().getLabel();
25
        if (StringUtils.isBlank(label1)){
26
            label1 = node1.getNodeId().getUuid().toString();
27
        }
28
        if (StringUtils.isBlank(label2)){
29
            label2 = node2.getNodeId().getUuid().toString();
30
        }
31
        int result = label1.compareTo(label2);
32

    
33
        if (result == 0){
34
            result = node1.getNodeId().getUuid().compareTo(node2.getNodeId().getUuid());
35
        }
36
        return result;
37
    }
38
}
(17-17/101)