Class MLText
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<Locale,String>
-
- org.alfresco.service.cmr.repository.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
HashMapwith 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
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddValue(Locale locale, String value)Add a multilingual text valueStringgetClosestValue(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 nullStringgetDefaultValue()Retrieves a default value from the set of available locales.Set<Locale>getLocales()StringgetValue(Locale locale)Retrieve a multilingual text valueCollection<String>getValues()voidremoveValue(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
-
-
-
-
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 localevalue- 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 localevalue- 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
-
-