Project

General

Profile

Download (1.14 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.model.common;
10

    
11
import java.util.Comparator;
12

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

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

    
37
    }
38

    
39
}
(56-56/80)