1 package eu
.etaxonomy
.taxeditor
.ui
.section
.description
;
4 import java
.util
.Comparator
;
6 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
7 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceBase
;
8 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceType
;
9 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
16 public class SourceComparator
<T
extends OriginalSourceBase
> implements Comparator
<T
> {
18 public int compare(T o1
, T o2
) {
21 boolean isDescriptionElementSource1
= false;
22 boolean isDescriptionElementSource2
= false;
23 if (o1
instanceof DescriptionElementSource
){
24 isDescriptionElementSource1
= true;
26 if (o2
instanceof DescriptionElementSource
){
27 isDescriptionElementSource2
= true;
30 if (isDescriptionElementSource1
!= isDescriptionElementSource2
){
31 if (isDescriptionElementSource1
){
37 OriginalSourceType type1
= o1
.getType();
38 OriginalSourceType type2
= o2
.getType();
39 Reference citation1
= o1
.getCitation();
40 Reference citation2
= o2
.getCitation();
44 // the newly created should always be on top
56 // sort by type (Primary taxonomic > Primary Media > others
57 // alphabetically by reference title cache)
58 else if (type1
== null){
65 } else if (type2
== null){
67 } else if(type1
.equals(type2
)){
69 } else if (type1
.equals(OriginalSourceType
.PrimaryTaxonomicSource
)){
71 } else if (type2
.equals(OriginalSourceType
.PrimaryTaxonomicSource
)){
73 } else if (type1
.equals(OriginalSourceType
.PrimaryMediaSource
)){
75 } else if (type2
.equals(OriginalSourceType
.PrimaryMediaSource
)){
79 //sort by citation title cache if types are equal
81 if(citation1
!=null && citation2
!=null){
82 result
= citation1
.getTitleCache().compareTo(citation2
.getTitleCache());
85 if(o2
.getCreated()!=null && o1
.getCreated()!=null){
86 result
= o1
.getCreated().compareTo(o2
.getCreated());
87 }else if (o1
.getCreated() == null ){
88 if (o2
.getCreated() == null){
93 }else if (o2
.getCreated() == null){
98 return o1
.getUuid().compareTo(o2
.getUuid());