-// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
-
package eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider;
import java.util.Comparator;
/**
* @author n.hoffmann
* @created Dec 14, 2010
- * @version 1.0
*/
public class ReferenceSortProvider extends AbstractSortProvider<Reference> {
- /**
- *
- */
public ReferenceSortProvider() {
comparators.put("Type", new ReferenceTypeComparator());
comparators.put("Year", new ReferenceYearComparator());
}
private class ReferenceYearComparator implements Comparator<Reference> {
-
- /**
- * @param o1
- * @return
- */
+
private String getYearString(Reference o) {
- TimePeriod datePublished = o == null ? null : o.getDatePublished();
+ TimePeriod datePublished = o == null ? null : o.getDatePublished();
return datePublished == null? null : datePublished.toString();
}
-
- /* (non-Javadoc)
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- public int compare(Reference o1, Reference o2) {
+
+ @Override
+ public int compare(Reference o1, Reference o2) {
String yearString1 = getYearString(o1);
String yearString2 = getYearString(o2);
if (yearString1 == null) {
}
int returnVal = yearString1.compareToIgnoreCase(yearString2);
if (returnVal == 0) {
- return new TitleCacheComparator<Reference>().compare(o1, o2);
- } else {
- return returnVal;
+ returnVal = new TitleCacheComparator<Reference>().compare(o1, o2);
+
}
- }
+ return returnVal;
+ }
}
-
+
private class ReferenceTypeComparator implements Comparator<Reference> {
-
- /* (non-Javadoc)
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- public int compare(Reference o1, Reference o2) {
+
+ @Override
+ public int compare(Reference o1, Reference o2) {
String typeString1 = o1.getClass().toString();
String typeString2 = o2.getClass().toString();
if (typeString1 == null) {
}
int returnVal = typeString1.compareToIgnoreCase(typeString2);
if (returnVal == 0) {
+ //the TitleCacheComparator already fulfills the comparator contract
return new TitleCacheComparator<Reference>().compare(o1, o2);
} else {
return returnVal;
}
- }
+ }
}
-
-
-}
+}
\ No newline at end of file