3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
;
13 import java
.util
.Comparator
;
15 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
16 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
20 * @created Dec 14, 2010
23 public class ReferenceSortProvider
extends AbstractSortProvider
<Reference
> {
28 public ReferenceSortProvider() {
29 comparators
.put("Type", new ReferenceTypeComparator());
30 comparators
.put("Year", new ReferenceYearComparator());
33 private class ReferenceYearComparator
implements Comparator
<Reference
> {
39 private String
getYearString(Reference o
) {
40 TimePeriod datePublished
= o
== null ?
null : o
.getDatePublished();
41 return datePublished
== null?
null : datePublished
.toString();
45 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
47 public int compare(Reference o1
, Reference o2
) {
48 String yearString1
= getYearString(o1
);
49 String yearString2
= getYearString(o2
);
50 if (yearString1
== null) {
51 if (yearString2
== null) {
57 if (yearString2
== null) {
60 int returnVal
= yearString1
.compareToIgnoreCase(yearString2
);
62 return new TitleCacheComparator
<Reference
>().compare(o1
, o2
);
69 private class ReferenceTypeComparator
implements Comparator
<Reference
> {
72 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
74 public int compare(Reference o1
, Reference o2
) {
75 String typeString1
= o1
.getClass().toString();
76 String typeString2
= o2
.getClass().toString();
77 if (typeString1
== null) {
78 if (typeString2
== null) {
84 if (typeString2
== null) {
87 int returnVal
= typeString1
.compareToIgnoreCase(typeString2
);
89 return new TitleCacheComparator
<Reference
>().compare(o1
, o2
);