|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectAbstractInternationalString
DefaultInternationalString
@ThreadSafe public class DefaultInternationalString
An international string using a map of strings for different locales. Strings for new locales can be added, but existing strings can't be removed or modified. This behavior is a compromise between making constructions easier, and being suitable for use in immutable objects.
| utility/geotk-utility (download) | View source code for this class |
| Constructor Summary | |
|---|---|
DefaultInternationalString()
Creates an initially empty international string. |
|
DefaultInternationalString(Map<Locale,String> strings)
Creates an international string initialized with the given localized strings. |
|
DefaultInternationalString(String string)
Creates an international string initialized with the given string. |
|
| Method Summary | |
|---|---|
void |
add(Locale locale,
String string)
Adds a string for the given locale. |
boolean |
add(String prefix,
String key,
String string)
Adds a string for the given property key. |
boolean |
equals(Object object)
Compares this international string with the specified object for equality. |
Set<Locale> |
getLocales()
Returns the set of locales defined in this international string. |
int |
hashCode()
Returns a hash code value for this international text. |
boolean |
isSubsetOf(Object candidate)
Returns true if all localized texts stored in this international string are
contained in the specified object. |
String |
toString(Locale locale)
Returns a string in the specified locale. |
| Methods inherited from class AbstractInternationalString |
|---|
charAt, compareTo, formatTo, length, subSequence, toString |
| Methods inherited from class Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultInternationalString()
add(...) methods.
public DefaultInternationalString(String string)
add(...)
methods. The string specified to this constructor is the one that will be
returned if no localized string is found for the Locale argument
in a call to toString(Locale).
string - The string in no specific locale, or null if none.public DefaultInternationalString(Map<Locale,String> strings)
strings - The strings in various locales, or null if none.| Method Detail |
|---|
public void add(Locale locale,
String string)
throws IllegalArgumentException
locale - The locale for the string value, or null.string - The localized string.
IllegalArgumentException - if a different string value was already set for
the given locale.
public boolean add(String prefix,
String key,
String string)
throws IllegalArgumentException
AbstractInternationalString during iteration through the
entries in a Map. It infers the Locale
from the property key, using the following steps:
key do not starts with the specified prefix, then
this method do nothing and returns false.prefix are parsed as an ISO language
and country code, and the add(Locale,String) method is invoked.
For example if the prefix is "remarks", then the "remarks_fr" property key
stands for remarks in French while the "remarks_fr_CA"
property key stands for remarks in French Canadian.
prefix - The prefix to skip at the beginning of the key.key - The property key.string - The localized string for the specified key.
true if the key has been recognized, or false otherwise.
IllegalArgumentException - if the locale after the prefix is an illegal code, or a
different string value was already set for the given locale.public Set<Locale> getLocales()
public String toString(Locale locale)
locale,
then this method searches for a locale without the variant
part. If no string are found, then this method searches for a locale without the country part. For example if the "fr_CA" locale was requested
but not found, then this method looks for the "fr" locale. The null locale
(which stand for unlocalized message) is tried last.
Handling of null argument value
A null argument value can be given to this method for
requesting a "unlocalized" string - typically some programmatic strings like
UML identifiers. While such
identifiers often look like English words, they are not considered as the
English localization. In order to produce a value close
to the common practice, this method handles null argument value as below:
null locale, then that string is returned.
toString in interface InternationalStringtoString in class AbstractInternationalStringlocale - The locale to look for, or null.
public boolean isSubsetOf(Object candidate)
true if all localized texts stored in this international string are
contained in the specified object. More specifically:
If candidate is an instance of InternationalString, then this method
returns true if, for all locale-string pairs contained in this, candidate.toString(locale) returns a string
equals to string.
If candidate is an instance of CharSequence, then this method
returns true if toString(Locale) returns a string equals to candidate.toString() for all locales.
If candidate is an instance of Map, then this methods returns
true if all locale-string pairs are contained into candidate.
Otherwise, this method returns false.
candidate - The object which may contains this international string.
true if the given object contains all localized strings found in this
international string.public boolean equals(Object object)
equals in class Objectobject - The object to compare with this international string.
true if the given object is equal to this string.public int hashCode()
hashCode in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||