1 |
78222507
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2009 EDIT
|
3 |
df366db5
|
Katja Luther
|
* European Distributed Institute of Taxonomy
|
4 |
78222507
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
df366db5
|
Katja Luther
|
*
|
6 |
78222507
|
n.hoffmann
|
* 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 |
|
|
package eu.etaxonomy.taxeditor.model;
|
10 |
|
|
|
11 |
|
|
import java.util.Comparator;
|
12 |
|
|
|
13 |
|
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
14 |
|
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
15 |
|
|
|
16 |
|
|
/**
|
17 |
caaaa636
|
n.hoffmann
|
* Implements a {@link Comparator} for {@link DefinedTermBase} objects based on the term's label.
|
18 |
|
|
* The compare algorithm compares a term's label. Example: If used on an unsorted list of terms, the
|
19 |
|
|
* list will be alphabetically sorted by label afterwards.
|
20 |
df366db5
|
Katja Luther
|
*
|
21 |
78222507
|
n.hoffmann
|
* @author n.hoffmann
|
22 |
|
|
* @date Jan 18, 2012
|
23 |
|
|
*
|
24 |
|
|
*/
|
25 |
|
|
public class DefaultTermComparator<T extends DefinedTermBase> implements Comparator<T> {
|
26 |
|
|
@Override
|
27 |
|
|
public int compare(T o1, T o2) {
|
28 |
f1c17375
|
Katja Luther
|
if (o1 == o2){
|
29 |
|
|
return 0;
|
30 |
|
|
}
|
31 |
|
|
if (o1 == null){
|
32 |
|
|
return -1;
|
33 |
|
|
}
|
34 |
|
|
if (o2 == null){
|
35 |
|
|
return 1;
|
36 |
|
|
}
|
37 |
78222507
|
n.hoffmann
|
String label1 = o1.getLabel(CdmStore.getDefaultLanguage()) != null ? o1.getLabel(CdmStore.getDefaultLanguage()) : o1.getTitleCache();
|
38 |
|
|
String label2 = o2.getLabel(CdmStore.getDefaultLanguage()) != null ? o2.getLabel(CdmStore.getDefaultLanguage()) : o2.getTitleCache();
|
39 |
df366db5
|
Katja Luther
|
int result = label1.compareTo(label2);
|
40 |
|
|
if (result == 0){
|
41 |
|
|
return o1.getUuid().compareTo(o2.getUuid());
|
42 |
|
|
}
|
43 |
|
|
return result;
|
44 |
78222507
|
n.hoffmann
|
}
|
45 |
|
|
};
|