From 2ebeb1a9fbadc077a5e73c2563e60c73927cd40f Mon Sep 17 00:00:00 2001 From: Patrick Plitzner Date: Thu, 9 Feb 2017 14:33:37 +0100 Subject: [PATCH] ref #4232 refactoring for comparator --- .../section/description/SourceComparator.java | 60 +++++++------------ 1 file changed, 23 insertions(+), 37 deletions(-) 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 2f3315053..d40e41084 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 @@ -22,56 +22,44 @@ public class SourceComparator implements Comparator { Reference citation1 = o1.getCitation(); Reference citation2 = o2.getCitation(); + int result = 0; + // the newly created should always be on top - if (id1 == 0 && id2!=0) { - return -1; - } - else if (id2==0) { - if (id1 == 0){ - return 0; - }else{ - return 1; + if (id1 == 0){ + if(id2!=0) { + result = -1; } + else{ + result = 0; + } + } else if(id2==0){ + result = 1; } // sort by type (Primary taxonomic > Primary Media > others // alphabetically by reference title cache) - int result = 0; - - if (type1 == null){ - result = 1; + else if (type1 == null){ + if(type2==null){ + result = 0; + } + else{ + result = 1; + } } else if (type2 == null){ result = -1; - } else if (type1.equals(type2)){ + } else if(type1.equals(type2)){ result = 0; - } else if (type1.equals(OriginalSourceType.PrimaryTaxonomicSource) && !type2.equals(OriginalSourceType.PrimaryTaxonomicSource)){ + } else if (type1.equals(OriginalSourceType.PrimaryTaxonomicSource)){ result = -1; - } else if (type2.equals(OriginalSourceType.PrimaryTaxonomicSource) && !type1.equals(OriginalSourceType.PrimaryTaxonomicSource)){ + } else if (type2.equals(OriginalSourceType.PrimaryTaxonomicSource)){ result = 1; - }else if (type1.equals(OriginalSourceType.PrimaryMediaSource) && !type2.equals(OriginalSourceType.PrimaryMediaSource)){ + } else if (type1.equals(OriginalSourceType.PrimaryMediaSource)){ result = -1; - } else if (type2.equals(OriginalSourceType.PrimaryMediaSource) && !type1.equals(OriginalSourceType.PrimaryMediaSource)){ + } else if (type2.equals(OriginalSourceType.PrimaryMediaSource)){ result = 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.PrimaryMediaSource))) { -// return -1; -// } -// if (type2 != null && type2.equals(OriginalSourceType.PrimaryMediaSource) -// && type1!=null && !type1.equals(OriginalSourceType.PrimaryMediaSource)) { -// return 1; -// } - //sort by citation title cache + //sort by citation title cache if types are equal if (result == 0){ if(citation1!=null && citation2!=null){ result = citation1.getTitleCache().compareTo(citation2.getTitleCache()); @@ -84,9 +72,7 @@ public class SourceComparator implements Comparator { //default fallback return o1.getId() - o2.getId(); } - } - return result; -- 2.34.1