Class LocalizedString

  • All Implemented Interfaces:
    Serializable

    public class LocalizedString
    extends Object
    implements Serializable
    Localized string container where a string is represented by its international value and a collection of translations to other languages.
    See Also:
    Serialized Form
    • Constructor Detail

      • LocalizedString

        public LocalizedString​(String internationalValue)
        Constructs a new localized string.
        Parameters:
        internationalValue - International value
      • LocalizedString

        protected LocalizedString()
        For Serializable
    • Method Detail

      • addTranslation

        public void addTranslation​(String lang,
                                   String translation)
        Adds a new translation to the string. Overrides the previous language translations if existed.
        Parameters:
        lang - Language code
        translation - Translation for this language
      • equals

        public boolean equals​(LocalizedString other)
        Check for equality.

        Note : Compares by the international value only.

        Parameters:
        other - other object
        Returns:
        true when equal; false else
      • getAvailableTranslationLanguages

        public Set<String> getAvailableTranslationLanguages()
        Available language codes this instance is translated to. For instance "de", "en" and so on.

        Note: Might be empty, then you still have the international name

        Returns:
        all available language codes
      • getInternational

        public String getInternational()
        Returns international string.
        Returns:
        international value
      • getTranslation

        public String getTranslation​(String lang)
        Returns translation for the specified language. Falls back to international string if translation does not exist.
        Parameters:
        lang - Language code (null for international string)
        Returns:
        Translation for the specified language.
      • hashCode

        public int hashCode()
        Serves as a hash function for a particular type.
        Overrides:
        hashCode in class Object
        Returns:
        Hash for current object
      • equals

        public boolean equals​(Object obj)
        Check for equality.
        Overrides:
        equals in class Object
        Parameters:
        obj - other object
        Returns:
        true when equal; false else
      • toString

        public String toString()
        Returns international string, if available.
        Overrides:
        toString in class Object
        Returns:
        International string, if available