1
|
/**
|
2
|
* Copyright (C) 2009 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
|
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
|
* 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
|
*
|
21
|
* @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
|
if (o1 == o2){
|
29
|
return 0;
|
30
|
}
|
31
|
if (o1 == null){
|
32
|
return -1;
|
33
|
}
|
34
|
if (o2 == null){
|
35
|
return 1;
|
36
|
}
|
37
|
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
|
return label1.compareTo(label2);
|
40
|
}
|
41
|
};
|