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
ConstructorDescriptionCreates 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 I18nStringMap
asMap()
Returns this instance represented as anI18nStringMap
instance.boolean
@NotNull String
get()
Returns the text for the current language.@NotNull String
Returns the text for the specified language, or the default text if no translation is available.@NotNull String
Returns the text for language of the specified locale, or the default text if no translation is available.@NotNull String
Returns the default text.getI18n()
Returns the text translations.int
hashCode()
boolean
isEquivalent
(I18nString obj) Returnstrue
if the specifiedI18nString
is equivalent to this instance.@NotNull I18nStringMap
Removes the translation for the specified language.@NotNull I18nStringMap
Removes the translation for the specified language.@NotNull I18nStringMap
Sets the translation for the specified locale.@NotNull I18nStringMap
Sets the translation for the specified locale.@NotNull I18nStringMap
setDefaultText
(@NotNull String defaultText) Sets the default text.@NotNull I18nStringMap
Sets the text translations.@NotNull String
toString()
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
copy
is ofI18nStringMap
type a full copy is performed. Ifcopy
is ofI18nResourcesString
type 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:
get
in 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:
get
in 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:
get
in 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
Returnstrue
if the specifiedI18nString
is equivalent to this instance.- If
other
isnull
returnsfalse
. - If
other
is of the same type callsequals()
. - Otherwise checks that the translations for current language of both instances are equal.
- Specified by:
isEquivalent
in interfaceI18nString
- Parameters:
obj
- The instance to compare against- Returns:
- If both instances are equivalent
- If
-
asMap
Returns this instance represented as anI18nStringMap
instance.- Specified by:
asMap
in interfaceI18nString
- Returns:
- This instance represented as an
I18nStringMap
instance
-
toString
Returns the default text.
-