Project

General

Profile

Download (2.16 KB) Statistics
| Branch: | Tag: | Revision:
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
 * @since 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
	@Override
42
    public int compare(T termbase1, T termbase2) throws RuntimeException{
43

    
44
	    if (termbase1.equals(termbase2)){
45
	        return 0;
46
	    }
47
		String label1 = makeCompareLabel(termbase1);
48
		String label2 = makeCompareLabel(termbase2);
49

    
50
		return label1.compareTo(label2);
51
	}
52

    
53
	private String makeCompareLabel(T termbase){
54
		String result;
55
		if (termbase == null){
56
			return "";
57
		}
58
		result = termbase.getLabel(compareLanguage);
59
		if (result == null){
60
			result = termbase.getLabel(defaultLanguage);
61
		}
62
		if (result == null){
63
			result = "";
64
		}
65
		result += termbase.getUuid().toString();
66
		return result;
67
	}
68

    
69
	/**
70
	 * @return the defaultLanguage
71
	 */
72
	public Language getDefaultLanguage() {
73
		return defaultLanguage;
74
	}
75

    
76
	/**
77
	 * @param defaultLanguage the defaultLanguage to set
78
	 */
79
	public void setDefaultLanguage(Language defaultLanguage) {
80
		this.defaultLanguage = defaultLanguage;
81
	}
82

    
83
	/**
84
	 * @return the compareLanguage
85
	 */
86
	public Language getCompareLanguage() {
87
		return compareLanguage;
88
	}
89

    
90
	/**
91
	 * @param compareLanguage the compareLanguage to set
92
	 */
93
	public void setCompareLanguage(Language compareLanguage) {
94
		this.compareLanguage = compareLanguage;
95
	}
96
}
(68-68/79)