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