public class DefaultInternationalString extends AbstractInternationalString implements Serializable
DefaultInternationalString
are thread-safe. While those instances are not strictly immutable,
SIS typically references them as if they were immutable because of their add-only behavior.Types.toInternationalString(Map, String)
,
Serialized FormDefined in the sis-utility
module
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Locale locale,
String string)
Adds a string for the given locale.
|
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.
|
charAt, compareTo, formatTo, length, subSequence, toString
chars, codePoints
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.Types.toInternationalString(Map, String)
public void add(Locale locale, String string) throws IllegalArgumentException
locale
- The locale for the string
value.string
- The localized string.IllegalArgumentException
- if 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 root locale is tried last.
Locale.ROOT
argument valueLocale.ROOT
can be given to this method for requesting a "unlocalized" string,
typically some programmatic values like enumerations or identifiers.
While identifiers often look like English words, Locale.ROOT
is not considered
synonymous to Locale.ENGLISH
because the values may differ in the way numbers and
dates are formatted (e.g. using the ISO 8601 standard for dates instead than English conventions).
In order to produce a value close to the common practice, this method handles Locale.ROOT
as below:
Locale.ROOT
, then that string is returned.Locale.US
as an approximation of "unlocalized" strings.null
argument valuenull
locale is handled as a synonymous of
Locale.ROOT
. However subclasses are free to use a different fallback. Client
code are encouraged to specify only non-null values for more determinist behavior.toString
in interface InternationalString
toString
in class AbstractInternationalString
locale
- The desired locale for the string to be returned.Locale.getDefault()
,
Locale.ROOT
public boolean isSubsetOf(Object candidate)
true
if all localized texts stored in this international string are
contained in the specified object. More specifically:
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
.candidate
is an instance of CharSequence
, then this method
returns true
if toString(Locale)
returns a string equals to candidate.toString()
for all locales.candidate
is an instance of Map
, then this methods returns
true
if all locale-string pairs are contained into candidate
.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)
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.