From: Patrick Plitzner
Date: Wed, 13 Apr 2016 15:40:06 +0000 (+0200)
Subject: Enhance source comparator #3185
X-Git-Tag: 4.0.0^2~25
X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/97cae9c275268172954f7f2344d35b19ac3a3455?ds=sidebyside
Enhance source comparator #3185
---
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/SourceComparator.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/SourceComparator.java
index 5353ec3dc..02c78468f 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/SourceComparator.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/SourceComparator.java
@@ -26,26 +26,27 @@ public class SourceComparator implements Comparator {
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 {
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