public class Catalog<K> extends Object
muli.Catalog
represents a relation between a
MuLi
and objects of type [K]
,
serving as keys.
It can be used as a multi-lingual map, i.e. as a catalog in both directions.
mulitexts: (K -/-> MuLi) catalogs: (language:String -/-> name:String -/-> K)Both structures are maintained synchronuously when calling the "put()" methods.
muli.Catalog
objects are mutable. Currently there is no
immutable derived class.
put()
methods add new relation elements to the existing maps.
This can result in an override of one or more currently
stored existing relation elements, but this is not checked.Modifier and Type | Class and Description |
---|---|
protected static class |
Catalog.Const
Wrapper class to prevent the translation OF AN ARGUMENT, eg.
|
Modifier and Type | Field and Description |
---|---|
protected Map<String,Map<String,K>> |
catalogs |
protected Class<K> |
keyClass
Currently only required for recursive application, when
translating ARGUMENTS of a format string.
|
protected Map<K,MuLi> |
mulitexts |
Modifier and Type | Method and Description |
---|---|
protected String |
_format(String text,
List<Object> args) |
protected String |
_format(String text,
Object... args)
The string formatting process as defined with
String.format(String,Object...) is applied. |
protected List<Object> |
_translateArgs(List<String> pref,
List<Object> args) |
boolean |
containsKey(K key) |
void |
dump(PrintStream s)
For DEBUGGING: dump Catalog to printstream.
|
@Opt MuLi |
get(K key)
Delivers an unmodifiable copy of the
MuLi for a given key object. |
MuLi.TextFound |
get(K key,
List<String> pref) |
MuLi.TextFound |
get(K key,
String... pref)
Delivers the name of a given key object in language chosen from a preference list.
|
@Opt String |
get(K key,
String lang)
Delivers the name of a given key object in a certain language.
|
K |
getKey(String lang,
String name)
Delivers the key object for a given name in a given language
|
Set<K> |
getKeys() |
Set<K> |
getKeys(MuLi muli)
Delivers all key objects for the (language, name) combinations
given by the
MuLi argument. |
Set<K> |
getKeys(String name)
Delivers all key objects for a given name in all languages.
|
K |
INSITU(K key,
List<String> variants)
Enters an "in-situ" definition into this translation catalog and returns
the (un-translated) key.
|
String |
insitu(K key,
List<String> langprefs,
List<String> variants)
Enters an "in-situ" definition into this translation catalog and returns
the translated text immediately.
|
String |
insitu(K key,
List<String> langprefs,
List<String> variants,
List<Object> args)
Enters an "in-situ" definition into this translation catalog and returns
the translated text immediately.
|
String |
insitu(K key,
List<String> langprefs,
List<String> variants,
Object... args) |
String |
insitu(K key,
List<String> langprefs,
String... pairs) |
protected Map<String,K> |
makeMap(String lang) |
protected MuLi |
makeMuli(K key) |
static Catalog.Const |
noTranslate(String s) |
void |
put(K key,
List<String> pairs)
Add one certain key object, and a list of languages and names
|
void |
put(K key,
MuLi muli)
Add one certain key object, and a MuLi mapping languages to names.
|
void |
put(K key,
String... pairs) |
void |
put(K key,
String lang,
String text)
Add one certain key object, one language and one name.
|
void |
putAll(Catalog<K> other)
Add the contents of a second catalog.
|
Map<String,K> |
readLanguageMap(String lang)
Delivers the map
String->K for a given language |
SortedSet<String> |
readLanguages()
Delivers the set of all contained languages
|
String |
readLanguagesString(String sep,
String sep2)
Delivers a list of all occuring languges, sorted alphabetically.
|
String |
translateAllAndFormatRobust(K key,
List<String> pref,
List<Object> args)
Translate the Key and all args by by calling
#translateRobust(K,List) . |
String |
translateAllAndFormatRobust(K key,
List<String> pref,
Object... args) |
String |
translateArgsAndFormatRobust(K key,
List<String> pref,
List<Object> args)
Do NOT translate the key, but call "toString()".
|
String |
translateArgsAndFormatRobust(K key,
List<String> pref,
Object... args) |
String |
translateKeyAndFormatRobust(K key,
List<String> pref,
List<Object> args)
Translate the Key by calling
#translateRobust(K,List) . |
String |
translateKeyAndFormatRobust(K key,
List<String> pref,
Object... args) |
String |
translateRobust(K key,
List<String> pref)
Translate the key into one of the languages of the list "pref".
|
String |
translateRobust(K key,
String... pref) |
protected Class<K> keyClass
@Opt public K getKey(String lang, String name)
null
in case the combination
of language and name has not been put.public Set<K> getKeys()
public Set<K> getKeys(String name)
public Set<K> getKeys(MuLi muli)
MuLi
argument. MuLi.syntheticLanguage
,name) matches ALL languages.public SortedSet<String> readLanguages()
public String readLanguagesString(String sep, String sep2)
sep
- the separator between two languges keys.public Map<String,K> readLanguageMap(String lang)
String->K
for a given language@Opt public @Opt MuLi get(K key)
MuLi
for a given key object.@Opt public @Opt String get(K key, String lang)
#get(K,String...)
which always returns some default!
Bad naming design! FIXME)null
if no such name had been stored.public boolean containsKey(K key)
@Opt public MuLi.TextFound get(K key, String... pref)
MuLi.get(String...)
, i.e. if
no language in the list matches, the index field in the
resulting TextFound
will be -1.@Opt public MuLi.TextFound get(K key, List<String> pref)
get(K,String...)
public String translateRobust(K key, List<String> pref)
public String translateRobust(K key, String... pref)
translateRobust(K,List)
public String translateArgsAndFormatRobust(K key, List<String> pref, List<Object> args)
#translateRobust(K,List)
.
Translating an "arg" means to apply #translateRobust(K,List)
iff
"arg" is instance of keyClass
, otherwise leave it unaltered.
public String translateArgsAndFormatRobust(K key, List<String> pref, Object... args)
translateArgsAndFormatRobust(K,List.List)
public String translateKeyAndFormatRobust(K key, List<String> pref, List<Object> args)
#translateRobust(K,List)
.
public String translateKeyAndFormatRobust(K key, List<String> pref, Object... args)
translateKeyAndFormatRobust(K,List,List)
public String translateAllAndFormatRobust(K key, List<String> pref, List<Object> args)
#translateRobust(K,List)
.
#translateRobust(K,List)
iff
"arg" is instance of keyClass
, otherwise leave it unaltered.
public String translateAllAndFormatRobust(K key, List<String> pref, Object... args)
translateAllAndFormatRobust(K,List,List)
protected String _format(String text, Object... args)
String.format(String,Object...)
is applied.
public K INSITU(K key, List<String> variants)
MuLiMessageReceiver
methods.
key
- variants
- list of PAIRS of String, each language code and textpublic String insitu(K key, List<String> langprefs, List<String> variants)
MuLiMessageReceiver
method,
because this implies a (second) translation step. For this case use INSITU(K, java.util.List<java.lang.String>)
.key
- langprefs
- list of language preferences for the retrieved text, as usualvariants
- list of PAIRS of String, each language code and textpublic String insitu(K key, List<String> langprefs, String... pairs)
insitu(Object,List,List)
public String insitu(K key, List<String> langprefs, List<String> variants, List<Object> args)
translateAllAndFormatRobust(K,List,List)
.
MuLiMessageReceiver
method,
because this implies a (second) translation step. For this case use INSITU(K, java.util.List<java.lang.String>)
.key
- langprefs
- list of language preferences, as usualvariants
- list of PAIRS of String, each language code and textargs
- objects formatted into the translated text by printf codespublic String insitu(K key, List<String> langprefs, List<String> variants, Object... args)
insitu(Object,List,List,List)
public void put(K key, String lang, String text)
Catalog
objects is not recommended:
put (k1, L1, text_1) put (k1, L2, text_2) put (k1, L1, text_1_new)... may lead to unintended combinations.
public void put(K key, List<String> pairs)
pairs
- sequence of key/value pairsIllegalArgumentException
- in case the number of Strings in not even.public void put(K key, MuLi muli)
public void putAll(Catalog<K> other)
public void dump(PrintStream s)
s
- PrintStream
to print to.public static Catalog.Const noTranslate(String s)
see also the complete user documentation .