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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
;
12 import java
.util
.Comparator
;
14 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
15 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
19 * @created Dec 14, 2010
22 public class ReferenceSortProvider
extends AbstractSortProvider
<Reference
> {
27 public ReferenceSortProvider() {
28 comparators
.put("Type", new ReferenceTypeComparator());
29 comparators
.put("Year", new ReferenceYearComparator());
32 private class ReferenceYearComparator
implements Comparator
<Reference
> {
38 private String
getYearString(Reference o
) {
39 TimePeriod datePublished
= o
== null ?
null : o
.getDatePublished();
40 return datePublished
== null?
null : datePublished
.toString();
44 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
46 public int compare(Reference o1
, Reference o2
) {
47 String yearString1
= getYearString(o1
);
48 String yearString2
= getYearString(o2
);
49 if (yearString1
== null) {
50 if (yearString2
== null) {
56 if (yearString2
== null) {
59 int returnVal
= yearString1
.compareToIgnoreCase(yearString2
);
61 return new TitleCacheComparator
<Reference
>().compare(o1
, o2
);
68 private class ReferenceTypeComparator
implements Comparator
<Reference
> {
71 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
73 public int compare(Reference o1
, Reference o2
) {
74 String typeString1
= o1
.getClass().toString();
75 String typeString2
= o2
.getClass().toString();
76 if (typeString1
== null) {
77 if (typeString2
== null) {
83 if (typeString2
== null) {
86 int returnVal
= typeString1
.compareToIgnoreCase(typeString2
);
88 return new TitleCacheComparator
<Reference
>().compare(o1
, o2
);