Class GrowableInternationalString
- All Implemented Interfaces:
Serializable,CharSequence,Comparable<InternationalString>,InternationalString
This class is mutable and not thread-safe.
- Since:
- 2.1
- Author:
- Martin Desruisseaux (IRD)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an initially empty international string.GrowableInternationalString(String string) Constructs an international string initialized with the specified string.GrowableInternationalString(InternationalString internationalString) Constructs an international string from the specified InternationalString. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a string for the given property key.voidAdds a string for the given locale.booleanCompares this international string with the specified object for equality.Returns the set of locales defined in this international string.inthashCode()Returns a hash code value for this international text.booleanisSubsetOf(Object candidate) Returnstrueif all localized texts stored in this international string are contained in the specified object.Returns a string in the specified locale.Methods inherited from class AbstractInternationalString
charAt, compareTo, length, subSequence, toStringMethods inherited from interface CharSequence
chars, codePoints, isEmpty
-
Constructor Details
-
GrowableInternationalString
public GrowableInternationalString()Constructs an initially empty international string. Localized strings can been added using one ofadd(...)methods. -
GrowableInternationalString
Constructs an international string initialized with the specified string. Additional localized strings can been added using one ofadd(...)methods. The string specified to this constructor is the one that will be returned if no localized string is found for theLocaleargument in a call totoString(Locale).- Parameters:
string- The string in no specific locale.
-
GrowableInternationalString
Constructs an international string from the specified InternationalString. It avoids to add an entry for each locales in cases whereInternationalString.toString(Locale)returns always the same string, by considering the result returned byInternationalString.toString()as the default value.- Parameters:
internationalString- the internationalString from which construct a new instance.
-
-
Method Details
-
add
Adds a string for the given locale.- Parameters:
locale- The locale for thestringvalue, ornull.string- The localized string.- Throws:
IllegalArgumentException- if a different string value was already set for the given locale.
-
add
Adds a string for the given property key. This is a convenience method for constructing anAbstractInternationalStringduring iteration through the entries in aMap. It infers theLocalefrom the propertykey, using the following steps:- If the
keydo not starts with the specifiedprefix, then this method do nothing and returnsfalse. - Otherwise, the characters after the
prefixare parsed as an ISO language and country code, and theadd(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.- Parameters:
prefix- The prefix to skip at the begining of thekey.key- The property key.string- The localized string for the specifiedkey.- Returns:
trueif the key has been recognized, orfalseotherwise.- Throws:
IllegalArgumentException- if the locale after the prefix is an illegal code, or a different string value was already set for the given locale.
- If the
-
getLocales
Returns the set of locales defined in this international string.The returned set may contain a
nullobject, signifying there's a "default" value (as created wither through thesingle-stringconstructor, or with anull"locale" parameter toadd(Locale, String)- Returns:
- The set of locales.
-
toString
Returns a string in the specified locale. If there is no string for the specifiedlocale, then this method search for a locale without the variant part. If no string are found, then this method search 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. Thenulllocale (which stand for unlocalized message) is tried last.- Specified by:
toStringin interfaceInternationalString- Specified by:
toStringin classAbstractInternationalString- Parameters:
locale- The locale to look for, ornull.- Returns:
- The string in the specified locale, or in a default locale.
-
isSubsetOf
Returnstrueif all localized texts stored in this international string are contained in the specified object. More specifically:-
If
candidateis an instance ofInternationalString, then this method returnstrueif, for all locale-string pairs contained inthis,candidate.toString(locale)returns a string equals tostring. -
If
candidateis an instance ofCharSequence, then this method returnstrueiftoString(Locale)returns a string equals tocandidate.toString()for all locales. -
If
candidateis an instance ofMap, then this methods returnstrueif all locale-string pairs are contained intocandidate. -
Otherwise, this method returns
false.
- Parameters:
candidate- The object which may contains this international string.- Returns:
trueif the given object contains all localized strings found in this international string.- Since:
- 2.3
-
-
equals
Compares this international string with the specified object for equality. -
hashCode
public int hashCode()Returns a hash code value for this international text.
-