Project

General

Profile

Revision 2ebeb1a9

ID2ebeb1a9fbadc077a5e73c2563e60c73927cd40f
Parent df366db5
Child 57aa2fdb

Added by Patrick Plitzner over 3 years ago

ref #4232 refactoring for comparator

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/SourceComparator.java
22 22
        Reference citation1 = o1.getCitation();
23 23
        Reference citation2 = o2.getCitation();
24 24

  
25
        int result = 0;
26

  
25 27
        // the newly created should always be on top
26
        if (id1 == 0 && id2!=0) {
27
            return -1;
28
        }
29
        else if (id2==0) {
30
            if (id1 == 0){
31
                return 0;
32
            }else{
33
                return 1;
28
        if (id1 == 0){
29
            if(id2!=0) {
30
                result = -1;
34 31
            }
32
            else{
33
                result = 0;
34
            }
35
        } else if(id2==0){
36
            result = 1;
35 37
        }
36 38

  
37 39
        // sort by type (Primary taxonomic > Primary Media > others
38 40
        // alphabetically by reference title cache)
39
        int result = 0;
40

  
41
        if (type1 == null){
42
            result = 1;
41
        else if (type1 == null){
42
            if(type2==null){
43
                result = 0;
44
            }
45
            else{
46
                result = 1;
47
            }
43 48
        } else if (type2 == null){
44 49
            result = -1;
45
        } else if (type1.equals(type2)){
50
        } else if(type1.equals(type2)){
46 51
            result = 0;
47
        } else if (type1.equals(OriginalSourceType.PrimaryTaxonomicSource) && !type2.equals(OriginalSourceType.PrimaryTaxonomicSource)){
52
        } else if (type1.equals(OriginalSourceType.PrimaryTaxonomicSource)){
48 53
            result = -1;
49
        } else if (type2.equals(OriginalSourceType.PrimaryTaxonomicSource) && !type1.equals(OriginalSourceType.PrimaryTaxonomicSource)){
54
        } else if (type2.equals(OriginalSourceType.PrimaryTaxonomicSource)){
50 55
            result = 1;
51
        }else if (type1.equals(OriginalSourceType.PrimaryMediaSource) && !type2.equals(OriginalSourceType.PrimaryMediaSource)){
56
        } else if (type1.equals(OriginalSourceType.PrimaryMediaSource)){
52 57
            result = -1;
53
        } else if (type2.equals(OriginalSourceType.PrimaryMediaSource) && !type1.equals(OriginalSourceType.PrimaryMediaSource)){
58
        } else if (type2.equals(OriginalSourceType.PrimaryMediaSource)){
54 59
            result = 1;
55 60
        }
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
//        }
73 61

  
74
        //sort by citation title cache
62
        //sort by citation title cache if types are equal
75 63
        if (result == 0){
76 64
            if(citation1!=null && citation2!=null){
77 65
                result = citation1.getTitleCache().compareTo(citation2.getTitleCache());
......
84 72
                //default fallback
85 73
                return o1.getId() - o2.getId();
86 74
            }
87

  
88 75
        }
89

  
90 76
        return result;
91 77

  
92 78

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)