Class MLText

  • All Implemented Interfaces:
    Serializable, Cloneable, Map<Locale,​String>

    public class MLText
    extends HashMap<Locale,​String>
    Class to represent a multilingual (ML) text value.

    The language codes used should conform to the ISO639-2 language code standard, although there is no enforcement of the standard in this class.

    This is a simple extension of a HashMap with a few convenience methods.

    Author:
    Philippe Dubois, Derek Hulley
    See Also:
    ISO639-2, Serialized Form
    • Constructor Detail

      • MLText

        public MLText()
      • MLText

        public MLText​(String value)
        Construct an instance with a value corresponding to the current context locale.
        Parameters:
        value - the value for the current default locale
        See Also:
        I18NUtil.getLocale(), MLText(Locale, String), getDefaultValue()
      • MLText

        public MLText​(Locale locale,
                      String value)
        Construct an instance with a value for the given locale.
        Parameters:
        locale - the locale
        value - the value
        See Also:
        getDefaultValue()
    • Method Detail

      • getLocales

        public Set<Locale> getLocales()
        Returns:
        Returns all the language locales defined in the text
      • getValues

        public Collection<String> getValues()
        Returns:
        Returns all the values stored
      • addValue

        public void addValue​(Locale locale,
                             String value)
        Add a multilingual text value
        Parameters:
        locale - the language locale
        value - the multilingual text
      • getValue

        public String getValue​(Locale locale)
        Retrieve a multilingual text value
        Parameters:
        locale - the language locale
      • getDefaultValue

        public String getDefaultValue()
        Retrieves a default value from the set of available locales.
        See Also:
        I18NUtil.getLocale(), getClosestValue(Locale)
      • getClosestValue

        public String getClosestValue​(Locale locale)
        The given locale is used to search for a matching value according to:
        • An exact locale match
        • A match of locale ISO language codes
        • The value for the locale provided in the constructor
        • An arbitrary value
        • null
        Parameters:
        locale - the locale to use as the starting point of the value search
        Returns:
        Returns a default String value or null if one isn't available. null will only be returned if there are no values associated with this instance. With or without a match, the return value may be null, depending on the values associated with the locales.
      • removeValue

        public void removeValue​(Locale locale)
        Remove a multilingual text value
        Parameters:
        locale - the language locale