1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider;
|
11
|
|
12
|
import java.util.Comparator;
|
13
|
|
14
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
15
|
|
16
|
/**
|
17
|
* <p>IdentifiableEntityComparator class.</p>
|
18
|
*
|
19
|
* @author p.ciardelli
|
20
|
* @created 19.08.2009
|
21
|
* @version 1.0
|
22
|
*/
|
23
|
public class TitleCacheComparator<T extends IIdentifiableEntity> implements Comparator<T> {
|
24
|
|
25
|
private boolean fIgnoreCase;
|
26
|
|
27
|
private String getTitleCache(T o) {
|
28
|
return o == null ? null : o.getTitleCache();
|
29
|
}
|
30
|
|
31
|
/* (non-Javadoc)
|
32
|
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
33
|
*/
|
34
|
/** {@inheritDoc} */
|
35
|
@Override
|
36
|
public int compare(T o1, T o2) {
|
37
|
String titleCache1 = getTitleCache(o1);
|
38
|
String titleCache2 = getTitleCache(o2);
|
39
|
if (titleCache1 == null && titleCache2 == null) {
|
40
|
return 0;
|
41
|
}
|
42
|
if (titleCache1 == null) {
|
43
|
return -1;
|
44
|
}
|
45
|
if (titleCache2 == null) {
|
46
|
return 1;
|
47
|
}
|
48
|
int result = fIgnoreCase ? titleCache1.compareToIgnoreCase(titleCache2) :
|
49
|
titleCache1.compareTo(titleCache2);
|
50
|
|
51
|
if (result == 0){
|
52
|
result = o1.getUuid().compareTo(o2.getUuid());
|
53
|
}
|
54
|
return result;
|
55
|
}
|
56
|
}
|