Project

General

Profile

Download (1.86 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.taxon;
10

    
11
import java.io.Serializable;
12
import java.util.Comparator;
13
import java.util.UUID;
14

    
15
import eu.etaxonomy.cdm.model.name.Rank;
16

    
17
/**
18
 * @author k.luther
19
 \* @since 06.12.2017
20
 *
21
 */
22
public class UuidAndTitleCacheTaxonComparator implements Serializable, Comparator<Object[]>{
23

    
24

    
25
    private static final long serialVersionUID = 6000794425983318091L;
26

    
27

    
28
    @Override
29
    public int compare(Object[] o1, Object[] o2) {
30
        //same UUID
31

    
32
        if (o1[0].equals(o2[0])){
33
            return 0;
34
        }
35

    
36
        //Rank
37
        Rank rankTax1 = (Rank)o1[3];
38
        Rank rankTax2 = (Rank)o2[3];
39

    
40
        String titleCache1 = (String)o1[2];
41
        String titleCache2 = (String)o2[2];
42
        //first compare ranks, if ranks are equal (or both null) compare names or taxon title cache if names are null
43
        if (rankTax1 == null && rankTax2 != null){
44
            return 1;
45
        }else if(rankTax2 == null && rankTax1 != null){
46
            return -1;
47
        }else if (rankTax1 != null && rankTax1.isHigher(rankTax2)){
48
            return -1;
49
        }else if (rankTax1 == null && rankTax2 == null || rankTax1.equals(rankTax2)) {
50
            if (titleCache1 != null && titleCache2 != null){
51
                //same rank, order by titleCache
52
                int result = titleCache1.compareTo(titleCache2);
53
                if (result == 0){
54
                    return ((UUID)o1[0]).compareTo((UUID)o2[0]);
55
                }else{
56
                    return result;
57
                }
58
            }
59
        }else{
60
            //rankTax2.isHigher(rankTax1)
61
            return 1;
62
        }
63
        return 0;
64
        }
65

    
66
}
(19-19/21)