Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/IdentifiableEntityComparator.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
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. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.annotatedlineeditor; |
|
12 |
|
|
13 |
import java.util.Comparator; |
|
14 |
|
|
15 |
import org.apache.log4j.Logger; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
18 |
|
|
19 |
/** |
|
20 |
* @author p.ciardelli |
|
21 |
* @created 19.08.2009 |
|
22 |
* @version 1.0 |
|
23 |
*/ |
|
24 |
public class IdentifiableEntityComparator implements Comparator { |
|
25 |
private static final Logger logger = Logger |
|
26 |
.getLogger(IdentifiableEntityComparator.class); |
|
27 |
|
|
28 |
private boolean fIgnoreCase; |
|
29 |
|
|
30 |
private String getTitleCache(Object o) { |
|
31 |
return o == null || !(o instanceof IdentifiableEntity) ? |
|
32 |
null : ((IdentifiableEntity) o).getTitleCache(); |
|
33 |
} |
|
34 |
|
|
35 |
/* (non-Javadoc) |
|
36 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
|
37 |
*/ |
|
38 |
public int compare(Object o1, Object o2) { |
|
39 |
String titleCache1 = getTitleCache(o1); |
|
40 |
String titleCache2 = getTitleCache(o2); |
|
41 |
if (titleCache1 == null && titleCache2 == null) { |
|
42 |
return 0; |
|
43 |
} |
|
44 |
if (titleCache1 == null) { |
|
45 |
return -1; |
|
46 |
} |
|
47 |
if (titleCache2 == null) { |
|
48 |
return 1; |
|
49 |
} |
|
50 |
return fIgnoreCase ? titleCache1.compareToIgnoreCase(titleCache2) : |
|
51 |
titleCache1.compareTo(titleCache2); |
|
52 |
} |
|
53 |
} |
|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
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. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.annotatedlineeditor; |
|
12 |
|
|
13 |
import java.util.Comparator; |
|
14 |
|
|
15 |
import org.apache.log4j.Logger; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
18 |
|
|
19 |
/** |
|
20 |
* <p>IdentifiableEntityComparator class.</p> |
|
21 |
* |
|
22 |
* @author p.ciardelli |
|
23 |
* @created 19.08.2009 |
|
24 |
* @version 1.0 |
|
25 |
*/ |
|
26 |
public class IdentifiableEntityComparator implements Comparator { |
|
27 |
private static final Logger logger = Logger |
|
28 |
.getLogger(IdentifiableEntityComparator.class); |
|
29 |
|
|
30 |
private boolean fIgnoreCase; |
|
31 |
|
|
32 |
private String getTitleCache(Object o) { |
|
33 |
return o == null || !(o instanceof IdentifiableEntity) ? |
|
34 |
null : ((IdentifiableEntity) o).getTitleCache(); |
|
35 |
} |
|
36 |
|
|
37 |
/* (non-Javadoc) |
|
38 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
|
39 |
*/ |
|
40 |
/** {@inheritDoc} */ |
|
41 |
public int compare(Object o1, Object o2) { |
|
42 |
String titleCache1 = getTitleCache(o1); |
|
43 |
String titleCache2 = getTitleCache(o2); |
|
44 |
if (titleCache1 == null && titleCache2 == null) { |
|
45 |
return 0; |
|
46 |
} |
|
47 |
if (titleCache1 == null) { |
|
48 |
return -1; |
|
49 |
} |
|
50 |
if (titleCache2 == null) { |
|
51 |
return 1; |
|
52 |
} |
|
53 |
return fIgnoreCase ? titleCache1.compareToIgnoreCase(titleCache2) : |
|
54 |
titleCache1.compareTo(titleCache2); |
|
55 |
} |
|
56 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation