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.HashMap;
|
13
|
import java.util.List;
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
|
17
|
/**
|
18
|
* @author m.doering
|
19
|
* Special array that takes care that all LanguageString elements have a unique language
|
20
|
*/
|
21
|
public class MultilanguageSet extends HashMap<Language, LanguageString> {
|
22
|
|
23
|
private static final long serialVersionUID = 7876604337076705862L;
|
24
|
|
25
|
static Logger logger = Logger.getLogger(MultilanguageSet.class);
|
26
|
|
27
|
/**
|
28
|
* Factory method
|
29
|
* @return
|
30
|
*/
|
31
|
public static MultilanguageSet NewInstance(){
|
32
|
MultilanguageSet result = new MultilanguageSet();
|
33
|
return result;
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* Factory method
|
38
|
* @return
|
39
|
*/
|
40
|
public static MultilanguageSet NewInstance(LanguageString languageString){
|
41
|
MultilanguageSet result = new MultilanguageSet(languageString);
|
42
|
return result;
|
43
|
}
|
44
|
|
45
|
public MultilanguageSet(){
|
46
|
super();
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Constructor
|
51
|
*/
|
52
|
protected MultilanguageSet (LanguageString languageString){
|
53
|
super();
|
54
|
this.add(languageString);
|
55
|
}
|
56
|
|
57
|
public String getText(Language language){
|
58
|
LanguageString languageString = super.get(language);
|
59
|
if (languageString != null){
|
60
|
return languageString.getText();
|
61
|
}else {
|
62
|
return null;
|
63
|
}
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* @param languageString
|
68
|
* @return String the previous text in the MultilanguageSet that was associated with the language
|
69
|
* defined in languageString, or null if there was no such text before. (A null return can also indicate that the text was previously null.)
|
70
|
*/
|
71
|
public LanguageString add(LanguageString languageString){
|
72
|
if (languageString == null){
|
73
|
return null;
|
74
|
}else{
|
75
|
// Language language = languageString.getLanguage();
|
76
|
// String text = languageString.getText();
|
77
|
// String result =this.put(languageString.getLanguage(), languageString.getText());
|
78
|
// return result;
|
79
|
// }
|
80
|
return this.put(languageString.getLanguage(), languageString);
|
81
|
}
|
82
|
}
|
83
|
|
84
|
|
85
|
/**
|
86
|
*
|
87
|
* @param languages
|
88
|
* @return
|
89
|
*/
|
90
|
public LanguageString getPreferredLanguageString(List<Language> languages){
|
91
|
|
92
|
LanguageString languageString = null;
|
93
|
for (Language language : languages) {
|
94
|
languageString = super.get(language);
|
95
|
if(languageString != null){
|
96
|
return languageString;
|
97
|
}
|
98
|
}
|
99
|
return super.get(Language.DEFAULT());
|
100
|
}
|
101
|
|
102
|
|
103
|
}
|