Class LocalizedString

java.lang.Object
overit.geocall.model.lang.LocalizedString
All Implemented Interfaces:
Serializable, Iterable<LocalizedString.LocalizedItem>, JacksonMapConvertible

public class LocalizedString extends Object implements Iterable<LocalizedString.LocalizedItem>, Serializable, 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:
  • Field Details

  • Constructor Details

    • LocalizedString

      public LocalizedString()
      Create a new LocalizedString instance with empty entries. Use add(Lang, String) method to manually add the values for the many supported languages
  • Method Details

    • get

      public String get(Lang language)
      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. null value will be returned if the language has not been configured for the current Identity, or it has been filtered accordingly to the filter(String) policy
      Throws:
      overit.geocall.asserts.AssertsException - if the passed lang is null
    • get

      public String get(String name)
      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. null value will be returned if the language has not been configured for the current Identity, or it has been filtered accordingly to the filter(String) policy
    • add

      public boolean add(Lang language, String value)
      Add a new value translated into the specified language.
      Parameters:
      language - the language related to the value that is going to be added
      value - the translated value that is going to be added
      Returns:
      true if this set did not already contain the specified element
      Throws:
      overit.geocall.asserts.AssertsException - if the passed lang is null
    • filter

      public void filter(String name)
      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 added
      • FILTER_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_ALL to get all values or FILTER_USER to 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()
      Returns true if this instance contains no items.
      Returns:
      true if this instance contains no items, false otherwise
    • iterator

      Specified by:
      iterator in interface Iterable<LocalizedString.LocalizedItem>
    • stream

      Returns a sequential Stream of items belongs to this instance as its source. The items will be filtered accordingly to the filter(String) policy
      Returns:
      a sequential Stream of items belongs to this instance as its source
    • extractValues

      public Map<String,Object> extractValues(@NotNull @NotNull BeanPropertyDefinition field)
      Description copied from interface: JacksonMapConvertible
      Extract the current instance values into a Map
      Specified by:
      extractValues in interface JacksonMapConvertible
      Parameters:
      field - field reference from which the values should be extracted
      Returns:
      a Map containing all the instance values
    • transferValues

      public void transferValues(@NotNull @NotNull BeanPropertyDefinition field, @NotNull @NotNull Map<String,Object> values, boolean nullValues)
      Description copied from interface: JacksonMapConvertible
      Move 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:
      transferValues in interface JacksonMapConvertible
      Parameters:
      field - field reference to which the values should be added
      values - Map containing all the values that should be added to the current instance
      nullValues - specify if the null values should be filtered or not