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