2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.description
;
11 import java
.util
.Comparator
;
13 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
14 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceBase
;
15 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceType
;
16 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
22 public class SourceComparator
<T
extends OriginalSourceBase
> implements Comparator
<T
> {
25 public int compare(T o1
, T o2
) {
27 //same and null compare, to be on the save side
30 }else if (o1
== null){
32 }else if (o2
== null){
36 boolean isDescriptionElementSource1
= false;
37 boolean isDescriptionElementSource2
= false;
38 if (o1
.isInstanceOf(DescriptionElementSource
.class)){
39 isDescriptionElementSource1
= true;
41 if (o2
.isInstanceOf(DescriptionElementSource
.class)){
42 isDescriptionElementSource2
= true;
44 if (isDescriptionElementSource1
!= isDescriptionElementSource2
){
45 if (isDescriptionElementSource1
){
52 // the newly created should always be on top
53 if (!o1
.isPersited() && o2
.isPersited()) {
55 } else if(o1
.isPersited() && !o2
.isPersited()){
59 // sort by type (Primary taxonomic > Primary Media > others
60 // alphabetically by reference title cache)
61 OriginalSourceType type1
= o1
.getType();
62 OriginalSourceType type2
= o2
.getType();
67 } else if (type2
== null){
69 } else if(type1
.equals(type2
)){
70 //continue with citation compare
71 } else if (type1
.equals(OriginalSourceType
.PrimaryTaxonomicSource
)){
73 } else if (type2
.equals(OriginalSourceType
.PrimaryTaxonomicSource
)){
75 } else if (type1
.equals(OriginalSourceType
.PrimaryMediaSource
)){
77 } else if (type2
.equals(OriginalSourceType
.PrimaryMediaSource
)){
83 //sort by citation title cache if types are equal
84 Reference citation1
= o1
.getCitation();
85 Reference citation2
= o2
.getCitation();
86 if(citation1
!=null && citation2
!=null){
87 result
= citation1
.getTitleCache().compareTo(citation2
.getTitleCache());
94 if(o2
.getCreated()!=null && o1
.getCreated()!=null){
95 result
= o1
.getCreated().compareTo(o2
.getCreated());
99 }else if (o1
.getCreated() == null){
100 if (o2
.getCreated() != null){
103 }else if (o2
.getCreated() == null){
108 return o1
.getUuid().compareTo(o2
.getUuid());