Project

General

Profile

Download (1.32 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2016 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.model.common;
10

    
11
import java.util.Comparator;
12

    
13
import eu.etaxonomy.cdm.common.CdmUtils;
14

    
15
/**
16
 * @author k.luther
17
 * @date 08.06.2016
18
 *
19
 */
20
public class TermIdInVocabularyComparator<T extends DefinedTermBase<?>> implements Comparator<T> {
21

    
22
    /* (non-Javadoc)
23
     * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
24
     */
25
    @Override
26
    public int compare(T term1, T term2) {
27
        String label1;
28
        String label2;
29
        if (term1 == term2){
30
            return 0;
31
        }
32
        if (term1 == null){
33
            return 1;
34
        }
35
        if (term2 == null){
36
            return -1;
37
        }
38
        if (term1.getIdInVocabulary() == null){
39
            label1 = CdmUtils.Nz(term1.getTitleCache());
40
        }else{
41
            label1 = CdmUtils.Nz(term1.getIdInVocabulary());
42
        }
43
        if (term2.getIdInVocabulary() == null){
44
            label2 = CdmUtils.Nz(term2.getTitleCache());
45
        }else{
46
            label2 = CdmUtils.Nz(term2.getIdInVocabulary());
47
        }
48

    
49
        return  label1.compareTo(label2);
50
    }
51

    
52

    
53

    
54
}
(63-63/75)