Project

General

Profile

Revision fc758deb

IDfc758debf75ebd48300372eccaf05a5ba5688034
Parent 9d215095
Child bdcfdeab

Added by Katja Luther over 3 years ago

ref #4232: adapt comparator to comaparator contract

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/SourceComparator.java
27 27
            return -1;
28 28
        }
29 29
        else if (id2==0) {
30
            return 1;
30
            if (id1 == 0){
31
                return 0;
32
            }else{
33
                return 1;
34
            }
31 35
        }
32 36

  
33 37
        // sort by type (Primary taxonomic > Primary Media > others
34 38
        // alphabetically by reference title cache)
35
        if (type1 != null && type1.equals(OriginalSourceType.PrimaryTaxonomicSource)
36
                && (type2 == null || !type2.equals(OriginalSourceType.PrimaryTaxonomicSource))) {
37
            return -1;
38
        }
39
        if ((type1 == null || !type1.equals(OriginalSourceType.PrimaryTaxonomicSource))
40
                && type2 != null && type2.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
41
            return 1;
42
        }
39
        int result = 0;
43 40

  
44
        if ((type1 == null || type1.equals(OriginalSourceType.PrimaryMediaSource))
45
                && (type2==null || !type2.equals(OriginalSourceType.PrimaryMediaSource))) {
46
            return -1;
47
        }
48
        if (type2 != null && type2.equals(OriginalSourceType.PrimaryMediaSource)
49
                && type1!=null && !type1.equals(OriginalSourceType.PrimaryMediaSource)) {
50
            return 1;
41
        if (type1 == null){
42
            result = 1;
43
        } else if (type2 == null){
44
            result = -1;
45
        } else if (type1.equals(type2)){
46
            result = 0;
47
        } else if (type1.equals(OriginalSourceType.PrimaryTaxonomicSource) && !type2.equals(OriginalSourceType.PrimaryTaxonomicSource)){
48
            result = -1;
49
        } else if (type2.equals(OriginalSourceType.PrimaryTaxonomicSource) && !type1.equals(OriginalSourceType.PrimaryTaxonomicSource)){
50
            result = 1;
51
        }else if (type1.equals(OriginalSourceType.PrimaryMediaSource) && !type2.equals(OriginalSourceType.PrimaryMediaSource)){
52
            result = -1;
53
        } else if (type2.equals(OriginalSourceType.PrimaryMediaSource) && !type1.equals(OriginalSourceType.PrimaryMediaSource)){
54
            result = 1;
51 55
        }
56
//        if (type1 != null && type1.equals(OriginalSourceType.PrimaryTaxonomicSource)
57
//                && (type2 == null || !type2.equals(OriginalSourceType.PrimaryTaxonomicSource))) {
58
//            return -1;
59
//        }
60
//        if ((type1 == null || !type1.equals(OriginalSourceType.PrimaryTaxonomicSource))
61
//                && type2 != null && type2.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
62
//            return 1;
63
//        }
64
//
65
//        if ((type1 == null || type1.equals(OriginalSourceType.PrimaryMediaSource))
66
//                && (type2==null || !type2.equals(OriginalSourceType.PrimaryMediaSource))) {
67
//            return -1;
68
//        }
69
//        if (type2 != null && type2.equals(OriginalSourceType.PrimaryMediaSource)
70
//                && type1!=null && !type1.equals(OriginalSourceType.PrimaryMediaSource)) {
71
//            return 1;
72
//        }
52 73

  
53 74
        //sort by citation title cache
54
        if(citation1!=null && citation2!=null){
55
            return citation1.getTitleCache().compareTo(citation2.getTitleCache());
56
        }
75
        if (result == 0){
76
            if(citation1!=null && citation2!=null){
77
                result = citation1.getTitleCache().compareTo(citation2.getTitleCache());
78
            }
79

  
80
            if(o2.getCreated()!=null && o1.getCreated()!=null){
81
                result = o2.getCreated().compareTo(o1.getCreated());
82
            }
83
            if (result == 0){
84
                //default fallback
85
                return o1.getId() - o2.getId();
86
            }
57 87

  
58
        if(o2.getCreated()!=null && o1.getCreated()!=null){
59
            return o2.getCreated().compareTo(o1.getCreated());
60 88
        }
61 89

  
62
        //default fallback
63
        return o1.getId() - o2.getId();
90
        return result;
91

  
64 92

  
65 93
    }
66 94
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)