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.cdm.model.common;
|
11
|
|
12
|
import java.util.Comparator;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
|
17
|
/**
|
18
|
* @author a.mueller
|
19
|
* @created 14.05.2008
|
20
|
* @version 1.0
|
21
|
*/
|
22
|
public class TermLanguageComparator<T extends TermBase> implements Comparator<T> {
|
23
|
@SuppressWarnings("unused")
|
24
|
private static Logger logger = Logger.getLogger(TermLanguageComparator.class);
|
25
|
|
26
|
private Language defaultLanguage = Language.DEFAULT();
|
27
|
private Language compareLanguage = Language.DEFAULT();
|
28
|
|
29
|
|
30
|
|
31
|
/**
|
32
|
*
|
33
|
*/
|
34
|
public TermLanguageComparator() {
|
35
|
// TODO Auto-generated constructor stub
|
36
|
}
|
37
|
|
38
|
/* (non-Javadoc)
|
39
|
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
40
|
*/
|
41
|
public int compare(T termbase1, T termbase2) throws RuntimeException{
|
42
|
String label1 = makeCompareLabel(termbase1);
|
43
|
String label2 = makeCompareLabel(termbase2);
|
44
|
|
45
|
return label1.compareTo(label2);
|
46
|
}
|
47
|
|
48
|
private String makeCompareLabel(T termbase){
|
49
|
String result;
|
50
|
if (termbase == null){
|
51
|
return "";
|
52
|
}
|
53
|
result = termbase.getLabel(compareLanguage);
|
54
|
if (result == null){
|
55
|
result = termbase.getLabel(defaultLanguage);
|
56
|
}
|
57
|
if (result == null){
|
58
|
result = "";
|
59
|
}
|
60
|
result += termbase.getUuid().toString();
|
61
|
return result;
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* @return the defaultLanguage
|
66
|
*/
|
67
|
public Language getDefaultLanguage() {
|
68
|
return defaultLanguage;
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* @param defaultLanguage the defaultLanguage to set
|
73
|
*/
|
74
|
public void setDefaultLanguage(Language defaultLanguage) {
|
75
|
this.defaultLanguage = defaultLanguage;
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* @return the compareLanguage
|
80
|
*/
|
81
|
public Language getCompareLanguage() {
|
82
|
return compareLanguage;
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* @param compareLanguage the compareLanguage to set
|
87
|
*/
|
88
|
public void setCompareLanguage(Language compareLanguage) {
|
89
|
this.compareLanguage = compareLanguage;
|
90
|
}
|
91
|
}
|