1 package eu
.etaxonomy
.taxeditor
.ui
.section
.description
;
4 import java
.util
.Comparator
;
6 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceBase
;
7 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
8 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
15 public class SourceComparator
implements Comparator
<OriginalSourceBase
> {
17 public int compare(OriginalSourceBase o1
, OriginalSourceBase o2
) {
20 OriginalSourceType type1
= o1
.getType();
21 OriginalSourceType type2
= o2
.getType();
22 Reference citation1
= o1
.getCitation();
23 Reference citation2
= o2
.getCitation();
27 // the newly created should always be on top
39 // sort by type (Primary taxonomic > Primary Media > others
40 // alphabetically by reference title cache)
41 else if (type1
== null){
48 } else if (type2
== null){
50 } else if(type1
.equals(type2
)){
52 } else if (type1
.equals(OriginalSourceType
.PrimaryTaxonomicSource
)){
54 } else if (type2
.equals(OriginalSourceType
.PrimaryTaxonomicSource
)){
56 } else if (type1
.equals(OriginalSourceType
.PrimaryMediaSource
)){
58 } else if (type2
.equals(OriginalSourceType
.PrimaryMediaSource
)){
62 //sort by citation title cache if types are equal
64 if(citation1
!=null && citation2
!=null){
65 result
= citation1
.getTitleCache().compareTo(citation2
.getTitleCache());
68 if(o2
.getCreated()!=null && o1
.getCreated()!=null){
69 result
= o2
.getCreated().compareTo(o1
.getCreated());
73 return o1
.getId() - o2
.getId();