Class I18nString

  • All Implemented Interfaces:
    android.os.Parcelable, MapperInterface

    public final class I18nString
    extends java.lang.Object
    implements android.os.Parcelable, MapperInterface
    A string with a different value depending of the language. It's recommended to support a default value defaultValue() (optional) for non supported languages.

    ISO 639-2 is used to identify the languages.

    See Also:
    Locale.getISO3Language()
    • Field Detail

      • ANY_LANGUAGE

        public static final java.lang.String ANY_LANGUAGE
        Special code, non ISO 693-2, to denote value to use by default.
        See Also:
        Constant Field Values
      • CREATOR

        public static final android.os.Parcelable.Creator<I18nString> CREATOR
    • Constructor Detail

      • I18nString

        public I18nString​(@NonNull
                          java.util.Map<java.lang.String,​java.lang.String> values)
        Parameters:
        values - non null map, with non null keys and values. Keys should be language's ISO 693-2 codes
    • Method Detail

      • get

        @NonNull
        public java.lang.String get​(@NonNull
                                    java.lang.String language)
        Obtains the string in the provided language. If there is no value for that language, return value for ANY_LANGUAGE
        Parameters:
        language - ISO 639-2 language name representation, or ANY_LANGUAGE. If is null, will check for ANY_LANGUAGE
        Returns:
        String. Empty if there is no value for this language, or if provided language is null or empty.
      • get

        @NonNull
        public java.lang.String get​(@NonNull
                                    java.util.Locale locale)
        Obtains the string in the provided Locale's language Wraps get(String), using Locale.getISO3Language() to take language code.
        Parameters:
        locale - its Locale.getISO3Language() stands for the language.
        Returns:
        String. Empty if there is no value for this language.
        Throws:
        java.lang.IllegalArgumentException - if locale is null
      • defaultValue

        @NonNull
        public java.lang.String defaultValue()
      • has

        public boolean has​(@NonNull
                           java.lang.String language)
        Check if the language is supported by this I18nString
        Parameters:
        language - ISO 639-2 language name representation. Not null.
        Returns:
        true if there is some value for this string, false otherwise.
      • toMap

        public java.util.Map<java.lang.String,​java.lang.Object> toMap()
        Description copied from interface: MapperInterface
        Method to transform object into Map
        Specified by:
        toMap in interface MapperInterface
        Returns:
        Map with the information of the object mapped
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • describeContents

        public int describeContents()
        Specified by:
        describeContents in interface android.os.Parcelable
      • writeToParcel

        public void writeToParcel​(android.os.Parcel dest,
                                  int flags)
        Specified by:
        writeToParcel in interface android.os.Parcelable