Package dev.orne.i18n

Class I18nFixedString

java.lang.Object
dev.orne.i18n.I18nFixedString
All Implemented Interfaces:
I18nString, Serializable

@API(status=STABLE, since="0.1") public final class I18nFixedString extends Object implements I18nString
Implementation of I18nString that doesn't contain translations.

Useful for constant values and I18N texts associated with current thread language (texts provided by users, translations retrieved from DB in lazy mode, etc.).

Since:
0.1
Version:
1.0, 2021-01
Author:
(w) Iker Hernaez
See Also:
  • Method Details

    • from

      public static I18nFixedString from(String text)
      Returns an instance for the specified text.

      Will return null if text is null.

      Parameters:
      text - The fixed text for all languages
      Returns:
      A instance with the specified text, or null if text is null
    • from

      public static I18nFixedString from(I18nString source)
      Creates a new instance with the translation for the current language of the specified source I18nString.

      Will return null if source is null.

      Parameters:
      source - The source of the I18N text
      Returns:
      A instance with the current language translation, or null if source is null
    • get

      @NotNull public @NotNull String get()
      Returns the text for the current language.
      Specified by:
      get in interface I18nString
      Returns:
      The text for the current language
    • get

      @NotNull public @NotNull String get(@NotNull @NotNull String language)
      Returns the text for the specified language, or the default text if no translation is available.
      Specified by:
      get in interface I18nString
      Parameters:
      language - The language of the requested text
      Returns:
      The text for the specified language
    • get

      @NotNull public @NotNull String get(@NotNull @NotNull Locale locale)
      Returns the text for language of the specified locale, or the default text if no translation is available.
      Specified by:
      get in interface I18nString
      Parameters:
      locale - The language of the requested text
      Returns:
      The text for the specified language
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • isEquivalent

      public boolean isEquivalent(I18nString obj)
      Returns true if the specified I18nString is equivalent to this instance.
      1. If other is null returns false.
      2. If other is of the same type calls equals().
      3. Otherwise checks that the translations for current language of both instances are equal.
      Specified by:
      isEquivalent in interface I18nString
      Parameters:
      obj - The instance to compare against
      Returns:
      If both instances are equivalent
    • asMap

      @NotNull public @NotNull I18nStringMap asMap()
      Returns this instance represented as an I18nStringMap instance.
      Specified by:
      asMap in interface I18nString
      Returns:
      This instance represented as an I18nStringMap instance
    • toString

      @NotNull public @NotNull String toString()
      Overrides:
      toString in class Object