Project

General

Profile

Download (1.21 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
 \* @since 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.equals(term2)){
30
            return 0;
31
        }
32

    
33
        if (term1.getIdInVocabulary() == null){
34
            label1 = CdmUtils.Nz(term1.getTitleCache());
35
        }else{
36
            label1 = CdmUtils.Nz(term1.getIdInVocabulary());
37
        }
38
        if (term2.getIdInVocabulary() == null){
39
            label2 = CdmUtils.Nz(term2.getTitleCache());
40
        }else{
41
            label2 = CdmUtils.Nz(term2.getIdInVocabulary());
42
        }
43

    
44
        return  label1.compareTo(label2);
45
    }
46

    
47

    
48

    
49
}
(67-67/79)