Correctly implement compare contract #3185
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 4 Apr 2016 15:14:39 +0000 (17:14 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 4 Apr 2016 15:14:39 +0000 (17:14 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementSourceSection.java

index 708236672dc660c0ca3d1d898b5e0935fd92c237..314810d764fc78cee73a9f21975338442d1f958c 100644 (file)
@@ -74,41 +74,37 @@ public class DescriptionElementSourceSection extends
                 Reference citation2 = o2.getCitation();
 
                 // the newly created should always be on top
-                if (id1 == 0) {
+                if (id1 == 0 && id2!=0) {
                     return -1;
                 }
-                if (id2 == 0) {
+                if (id1 != 0 && id2==0) {
                     return 1;
                 }
 
                 // sort by type (Primary taxonomic > Primary Media > others
                 // alphabetically by reference title cache)
-                if (type1 != null && type1.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
-                    return -1;
+                if (type1 != null && type1.equals(OriginalSourceType.PrimaryTaxonomicSource)
+                               && type2 != null && !type2.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
+                       return -1;
+                }
+                if (type1 != null && !type1.equals(OriginalSourceType.PrimaryTaxonomicSource)
+                               && type2 != null && type2.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
+                       return 1;
                 }
                 if (type1 != null && type1.equals(OriginalSourceType.PrimaryMediaSource)
                         && type2!=null && !type2.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
                     return -1;
                 }
-                if (type2 != null && type2.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
-                    return 1;
-                }
                 if (type2 != null && type2.equals(OriginalSourceType.PrimaryMediaSource)
                         && type1!=null && !type1.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
                     return 1;
                 }
 
                 //sort by citation title cache
-                if(citation1==null){
-                    return -1;
-                }
-                if(citation2==null){
-                    return 1;
-                }
                 if(citation1!=null && citation2!=null){
                     return citation1.getTitleCache().compareTo(citation2.getTitleCache());
                 }
-                return 0;
+                return o2.getCreated().compareTo(o1.getCreated());
             }
         });
         return sources;