Project

General

Profile

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

    
71
}
(19-19/21)