Class MLText

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.util.Locale,​java.lang.String>

    public class MLText
    extends java.util.HashMap<java.util.Locale,​java.lang.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
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      MLText()  
      MLText​(java.lang.String value)
      Construct an instance with a value corresponding to the current context locale.
      MLText​(java.util.Locale locale, java.lang.String value)
      Construct an instance with a value for the given locale.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addValue​(java.util.Locale locale, java.lang.String value)
      Add a multilingual text value
      java.lang.String getClosestValue​(java.util.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
      java.lang.String getDefaultValue()
      Retrieves a default value from the set of available locales.
      java.util.Set<java.util.Locale> getLocales()  
      java.lang.String getValue​(java.util.Locale locale)
      Retrieve a multilingual text value
      java.util.Collection<java.lang.String> getValues()  
      void removeValue​(java.util.Locale locale)
      Remove a multilingual text value
      • Methods inherited from class java.util.HashMap

        clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        equals, hashCode
    • Constructor Detail

      • MLText

        public MLText()
      • MLText

        public MLText​(java.lang.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​(java.util.Locale locale,
                      java.lang.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 java.util.Set<java.util.Locale> getLocales()
        Returns:
        Returns all the language locales defined in the text
      • getValues

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

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

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

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

        public java.lang.String getClosestValue​(java.util.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​(java.util.Locale locale)
        Remove a multilingual text value
        Parameters:
        locale - the language locale