Class MLText
- All Implemented Interfaces:
Serializable,Cloneable,Map<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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a multilingual text valuegetClosestValue(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 theconstructorAn arbitrary value nullstatic LocaleReturns default locale used by theMLTextimplementationRetrieves a default value from the set of available locales.Retrieve a multilingual text valuevoidremoveValue(Locale locale) Remove a multilingual text valueMethods 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, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
MLText
public MLText() -
MLText
Construct an instance with a value corresponding to the current context locale.- Parameters:
value- the value for the current default locale- See Also:
-
MLText
Construct an instance with a value for the given locale.- Parameters:
locale- the localevalue- the value- See Also:
-
-
Method Details
-
getDefaultLocale
Returns default locale used by theMLTextimplementation- Returns:
- default locale
- See Also:
-
I18NUtil.getLocale()
-
getLocales
- Returns:
- Returns all the language locales defined in the text
-
getValues
- Returns:
- Returns all the values stored
-
addValue
Add a multilingual text value- Parameters:
locale- the language localevalue- the multilingual text
-
getValue
Retrieve a multilingual text value- Parameters:
locale- the language locale
-
getDefaultValue
Retrieves a default value from the set of available locales.- See Also:
-
getClosestValue
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
Remove a multilingual text value- Parameters:
locale- the language locale
-