Project

General

Profile

Download (1.2 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.compare.term;
10

    
11
import java.util.Comparator;
12

    
13
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
14
import eu.etaxonomy.cdm.model.term.OrderedTermBase;
15

    
16
/**
17
 * @author k.luther
18
 * @since 07.02.2018
19
 */
20
public class OrderedTermComparator <T extends DefinedTermBase<T>> implements Comparator<T>{
21

    
22
    @Override
23
    public int compare(T o1, T o2) {
24
        if (o1 instanceof OrderedTermBase && o2 instanceof OrderedTermBase){
25
            OrderedTermBase odt1 = (OrderedTermBase<?>) o1;
26
            OrderedTermBase odt2 = (OrderedTermBase<?>) o2;
27
            if (odt1.getVocabulary().equals(odt2.getVocabulary())){
28
                return - odt1.compareTo(odt2);
29
            }else{
30
                return odt1.getVocabulary().getTitleCache().compareTo(odt2.getVocabulary().getTitleCache());
31
            }
32
        }else{
33
            throw new IllegalStateException("One of the compared terms are not of the type OrderedTermBase");
34
        }
35
    }
36
}
(1-1/5)