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;
}
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