Class LocalizedString
- All Implemented Interfaces:
Serializable,Iterable<LocalizedString.LocalizedItem>,JacksonMapConvertible
This object allows to expose a text string in different languages. Each tense is represented by an LocalizedString.LocalizedItem
which contains the textual content and the relevant laguage; it is possible to add new items
via the add(Lang, String) method.
Once added, items can be retrieved punctually, by indicating the language (see get(String) and get(Lang)
methods), or by cycling through all available items with the methods iterator() and stream().
By default, all the inserted items are returned, but it is possible to filter them, with the filter
method, in order to have visibility only of the text belonging to the user's language, rather than to a specific language.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class represents a single element added to theLocalizedString, and maintains the reference to the text and the language from whom the text has been translated -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a new value translated into the specified language.Extract the current instance values into aMapvoidFilter oll the following invocation to the getter methods by returning only the values whose language matches the passed language's name.Get the value related to the specified language.Get the value related to the specified language.booleanisEmpty()Returnstrueif this instance contains no items.iterator()intsize()Return the number of items contained into this instancestream()Returns a sequential Stream of items belongs to this instance as its source.voidtransferValues(@NotNull BeanPropertyDefinition field, @NotNull Map<String, Object> values, boolean nullValues) Move values from the passed Map into the current instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
FILTER_ALL
- See Also:
-
FILTER_USER
- See Also:
-
-
Constructor Details
-
LocalizedString
public LocalizedString()Create a new LocalizedString instance with empty entries. Useadd(Lang, String)method to manually add the values for the many supported languages
-
-
Method Details
-
get
Get the value related to the specified language.- Parameters:
language- the language related to the value that is going to be extracted- Returns:
- the value related to the specified language.
nullvalue will be returned if the language has not been configured for the current Identity, or it has been filtered accordingly to thefilter(String)policy - Throws:
overit.geocall.asserts.AssertsException- if the passed lang is null
-
get
Get the value related to the specified language.- Parameters:
name- the language's name related to the value that is going to be extracted- Returns:
- the value related to the specified language.
nullvalue will be returned if the language has not been configured for the current Identity, or it has been filtered accordingly to thefilter(String)policy
-
add
Add a new value translated into the specified language.- Parameters:
language- the language related to the value that is going to be addedvalue- the translated value that is going to be added- Returns:
trueif this set did not already contain the specified element- Throws:
overit.geocall.asserts.AssertsException- if the passed lang is null
-
filter
Filter oll the following invocation to the getter methods by returning only the values whose language matches the passed language's name. These are two reserved values that can be passed as name:FILTER_ALL: returns all the items addedFILTER_USER: returns only the value whose language match with the one that has been set to the current user
- Parameters:
name- the specific language name,FILTER_ALLto get all values orFILTER_USERto get the value related to the user's language
-
size
public int size()Return the number of items contained into this instance- Returns:
- the number of items
-
isEmpty
public boolean isEmpty()Returnstrueif this instance contains no items.- Returns:
trueif this instance contains no items,falseotherwise
-
iterator
- Specified by:
iteratorin interfaceIterable<LocalizedString.LocalizedItem>
-
stream
Returns a sequential Stream of items belongs to this instance as its source. The items will be filtered accordingly to thefilter(String)policy- Returns:
- a sequential Stream of items belongs to this instance as its source
-
extractValues
Description copied from interface:JacksonMapConvertibleExtract the current instance values into aMap- Specified by:
extractValuesin interfaceJacksonMapConvertible- Parameters:
field- field reference from which the values should be extracted- Returns:
- a
Mapcontaining all the instance values
-
transferValues
public void transferValues(@NotNull @NotNull BeanPropertyDefinition field, @NotNull @NotNull Map<String, Object> values, boolean nullValues) Description copied from interface:JacksonMapConvertibleMove values from the passed Map into the current instance.Implementations should remove the moved values from the passed map to avoid any re-usage of that value
- Specified by:
transferValuesin interfaceJacksonMapConvertible- Parameters:
field- field reference to which the values should be addedvalues-Mapcontaining all the values that should be added to the current instancenullValues- specify if the null values should be filtered or not
-