Package dev.orne.i18n
Class I18nStringMap
java.lang.Object
dev.orne.i18n.I18nStringMap
- All Implemented Interfaces:
I18nString,Serializable
Implementation of
I18nString populated with translations.
Useful for translations edition and visualization.
- Since:
- 0.1
- Version:
- 1.0, 2021-01
- Author:
- (w) Iker Hernaez
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with empty default text and no translations.I18nStringMap(@NotNull I18nString copy) Copy constructor.I18nStringMap(@NotNull String defaultText) Creates a new instance with specified default text and no translations. -
Method Summary
Modifier and TypeMethodDescription@NotNull I18nStringMapasMap()Returns this instance represented as anI18nStringMapinstance.boolean@NotNull Stringget()Returns the text for the current language.@NotNull StringReturns the text for the specified language, or the default text if no translation is available.@NotNull StringReturns the text for language of the specified locale, or the default text if no translation is available.@NotNull StringReturns the default text.getI18n()Returns the text translations.inthashCode()booleanisEquivalent(I18nString obj) Returnstrueif the specifiedI18nStringis equivalent to this instance.@NotNull I18nStringMapRemoves the translation for the specified language.@NotNull I18nStringMapRemoves the translation for the specified language.@NotNull I18nStringMapSets the translation for the specified locale.@NotNull I18nStringMapSets the translation for the specified locale.@NotNull I18nStringMapsetDefaultText(@NotNull String defaultText) Sets the default text.@NotNull I18nStringMapSets the text translations.@NotNull StringtoString()Returns the default text.
-
Constructor Details
-
I18nStringMap
public I18nStringMap()Creates a new instance with empty default text and no translations. -
I18nStringMap
Creates a new instance with specified default text and no translations.- Parameters:
defaultText- The default text
-
I18nStringMap
Copy constructor.If
copyis ofI18nStringMaptype a full copy is performed. Ifcopyis ofI18nResourcesStringtype the formatted default text is set as default text and the result ofget()as translation for current language. Otherwise the result ofget()is used as default text.- Parameters:
copy- The instance to copy
-
-
Method Details
-
getDefaultText
Returns the default text.- Returns:
- The default text
-
setDefaultText
Sets the default text.- Parameters:
defaultText- The default text- Returns:
- This instance for method chaining
-
getI18n
Returns the text translations.- Returns:
- The text translations
-
setI18n
@NotNull public @NotNull I18nStringMap setI18n(@NotNull @NotNull Map<@NotNull String, @NotNull String> translations) Sets the text translations. This methods modifies the internalMap. Further modifications on argument will have no effect in internal translations.- Parameters:
translations- The text translations- Returns:
- This instance for method chaining
-
get
Returns the text for the current language.- Specified by:
getin interfaceI18nString- Returns:
- The text for the current language
-
get
Returns the text for the specified language, or the default text if no translation is available.- Specified by:
getin interfaceI18nString- Parameters:
language- The language of the requested text- Returns:
- The text for the specified language
-
get
Returns the text for language of the specified locale, or the default text if no translation is available.- Specified by:
getin interfaceI18nString- Parameters:
locale- The language of the requested text- Returns:
- The text for the specified language
-
set
@NotNull public @NotNull I18nStringMap set(@NotNull @NotNull String language, @NotNull @NotNull String text) Sets the translation for the specified locale.- Parameters:
language- The language of the translationtext- The translated text- Returns:
- This instance for method chaining
-
set
@NotNull public @NotNull I18nStringMap set(@NotNull @NotNull Locale locale, @NotNull @NotNull String text) Sets the translation for the specified locale.- Parameters:
locale- The language of the translationtext- The translated text- Returns:
- This instance for method chaining
-
remove
Removes the translation for the specified language.- Parameters:
language- The language of the translation- Returns:
- This instance for method chaining
-
remove
Removes the translation for the specified language.- Parameters:
locale- The language of the translation- Returns:
- This instance for method chaining
-
hashCode
public int hashCode() -
equals
-
isEquivalent
Returnstrueif the specifiedI18nStringis equivalent to this instance.- If
otherisnullreturnsfalse. - If
otheris of the same type callsequals(). - Otherwise checks that the translations for current language of both instances are equal.
- Specified by:
isEquivalentin interfaceI18nString- Parameters:
obj- The instance to compare against- Returns:
- If both instances are equivalent
- If
-
asMap
Returns this instance represented as anI18nStringMapinstance.- Specified by:
asMapin interfaceI18nString- Returns:
- This instance represented as an
I18nStringMapinstance
-
toString
Returns the default text.
-