ref #5714 The last two terms are always "Other" followed by "Unknown"
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 7 Feb 2017 18:26:19 +0000 (19:26 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 8 Feb 2017 13:11:28 +0000 (14:11 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/supplemental/AbstractOriginalSourceElement.java

index 92dd2fdb5d4f0d76ec8a43ed7488c4f2853aab1f..d122962ce24dd26b7b8095e072c85222a090112a 100644 (file)
@@ -64,7 +64,9 @@ public abstract class AbstractOriginalSourceElement<T extends OriginalSourceBase
 
        /**
         * Sorts source type combo alphabetically <b>except</b> for PrimaryTaxonomicSource resp.
-        * PrimaryMediaSource which are alway on top depending on the IdentifiableSource;
+        * PrimaryMediaSource which are always on top depending on the IdentifiableSource;
+        * <br>
+        * The last two are always "Other" followed by "Unknown"
         * @author pplitzner
         * @date Jan 6, 2017
         *
@@ -82,49 +84,63 @@ public abstract class AbstractOriginalSourceElement<T extends OriginalSourceBase
          */
         @Override
         public int compare(OriginalSourceType o1, OriginalSourceType o2) {
-            if(o1!=null && o2==null){
-                return 1;
+            if(o1==null){
+                if(o2==null){
+                    return 0;
+                }
+                else{
+                    return -1;
+                }
             }
-            else if(o1==null && o2!=null){
-                return -1;
+            if(o2==null){
+                return 1;
             }
-            else if(o1!=null && o2 !=null){
-                //both are either taxonomic or media
-                if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource)
-                        && o2.equals(OriginalSourceType.PrimaryMediaSource)){
-                    if(entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){
-                        return 1;
-                    }
-                    else{
-                        return -1;
-                    }
+            //both are either taxonomic or media
+            else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource)
+                    && o2.equals(OriginalSourceType.PrimaryMediaSource)){
+                if(entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){
+                    return 1;
                 }
-                else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource)
-                        && o1.equals(OriginalSourceType.PrimaryMediaSource)){
-                    if(entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){
-                        return -1;
-                    }
-                    else{
-                        return 1;
-                    }
+                else{
+                    return -1;
+                }
+            }
+            else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource)
+                    && o1.equals(OriginalSourceType.PrimaryMediaSource)){
+                if(entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){
+                    return -1;
                 }
-                //one is not taxonomic or media
                 else{
-                    if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource)
-                            ||o1.equals(OriginalSourceType.PrimaryMediaSource)){
-                        return -1;
+                    return 1;
+                }
+            }
+            //one is not taxonomic or media
+            else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource)
+                    ||o1.equals(OriginalSourceType.PrimaryMediaSource)){
+                return -1;
 
-                    }
-                    else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource)
-                            || o2.equals(OriginalSourceType.PrimaryMediaSource)){
-                        return 1;
-                    }
-                    String message1 = o1.getKey();
-                    String message2 = o2.getKey();
-                    return message1.compareTo(message2);
+            }
+            else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource)
+                    || o2.equals(OriginalSourceType.PrimaryMediaSource)){
+                return 1;
+            }
+            //The last two are always "Other" followed by "Unknown"
+            else if(o1.equals(OriginalSourceType.Other)){
+                if(o2.equals(OriginalSourceType.Unknown)){
+                    return -11;
                 }
+                else{
+                    return 1;
+                }
+            }
+            if(o2.equals(OriginalSourceType.Other)){
+                return 1;
+            }
+            else{
+                String message1 = o1.getKey();
+                String message2 = o2.getKey();
+                return message1.compareTo(message2);
             }
-            return 0;
         }
 
        }