Project

General

Profile

Revision 884eaed4

ID884eaed4313022d9f8cb36a4a484a8891bbf1468
Parent 104cb37f
Child b6cbd329

Added by Katja Luther almost 2 years ago

ref #7234: new comparator for orderedTerms also in different vocabularies

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/OrderedTermComparator.java
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
 * @date 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
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)