Enhance source comparator #3185
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 13 Apr 2016 15:40:06 +0000 (17:40 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 13 Apr 2016 15:40:06 +0000 (17:40 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/SourceComparator.java

index 5353ec3dcc46435601ca24c979f218a0d735384a..02c78468f038d4ab143288f22d7745997c953189 100644 (file)
@@ -26,26 +26,27 @@ public class SourceComparator implements Comparator<OriginalSourceBase> {
         if (id1 == 0 && id2!=0) {
             return -1;
         }
-        if (id1 != 0 && id2==0) {
+        else if (id2==0) {
             return 1;
         }
 
         // sort by type (Primary taxonomic > Primary Media > others
         // alphabetically by reference title cache)
         if (type1 != null && type1.equals(OriginalSourceType.PrimaryTaxonomicSource)
-                && type2 != null && !type2.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
+                && (type2 == null || !type2.equals(OriginalSourceType.PrimaryTaxonomicSource))) {
             return -1;
         }
-        if (type1 != null && !type1.equals(OriginalSourceType.PrimaryTaxonomicSource)
+        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)) {
+
+        if ((type1 == null || type1.equals(OriginalSourceType.PrimaryMediaSource))
+                && (type2==null || !type2.equals(OriginalSourceType.PrimaryMediaSource))) {
             return -1;
         }
         if (type2 != null && type2.equals(OriginalSourceType.PrimaryMediaSource)
-                && type1!=null && !type1.equals(OriginalSourceType.PrimaryTaxonomicSource)) {
+                && type1!=null && !type1.equals(OriginalSourceType.PrimaryMediaSource)) {
             return 1;
         }
 
@@ -53,6 +54,13 @@ public class SourceComparator implements Comparator<OriginalSourceBase> {
         if(citation1!=null && citation2!=null){
             return citation1.getTitleCache().compareTo(citation2.getTitleCache());
         }
-        return o2.getCreated().compareTo(o1.getCreated());
+
+        if(o2.getCreated()!=null && o1.getCreated()!=null){
+            return o2.getCreated().compareTo(o1.getCreated());
+        }
+
+        //default fallback
+        return o1.getId() - o2.getId();
+
     }
 }
\ No newline at end of file