Class OtherLocales

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<PT_Locale>
org.apache.sis.internal.jaxb.lan.OtherLocales
All Implemented Interfaces:
Iterable<PT_Locale>, Collection<PT_Locale>, Set<PT_Locale>

public final class OtherLocales extends AbstractSet<PT_Locale>
Helper methods for handling the ISO 19115 defaultLocale and otherLocale legacy properties. The ISO standard defines them as two separated properties while GeoAPI handles them in a single collection for integration with JDK standard API like Locale.lookup(List, Collection).

The first element of the languages collection is taken as the defaultLocale, and all remaining ones are taken as otherLocale elements. Instances of this OtherLocales class are for those remaining elements and are created by the filter(Map) method.

Since:
0.5
Version:
1.0
  • Field Details

    • locales

      private final Set<PT_Locale> locales
      The default locale followed by all other locales.
  • Constructor Details

  • Method Details

    • filter

      public static Set<PT_Locale> filter(Map<Locale,Charset> locales)
      Returns a collection for all elements except the first one from the given collection.

      Null values and XML marshalling

      The locales argument may be null at XML marshalling time. In such case, this method returns null instead of an empty set in order to instruct JAXB to not marshal the otherLocale element (an empty set would cause JAXB to marshal an empty element). Since the locales argument given to this method should never be null except at XML marshalling time, this rule should not be a violation of public API.
      Parameters:
      locales - the collection containing the default locale followed by the other ones, or null.
      Returns:
      a collection containing all languages elements except the first one, or null.
    • size

      public int size()
      Returns the number of elements in this collection.
      Specified by:
      size in interface Collection<PT_Locale>
      Specified by:
      size in interface Set<PT_Locale>
      Specified by:
      size in class AbstractCollection<PT_Locale>
      Returns:
      number of other locales.
    • iterator

      public Iterator<PT_Locale> iterator()
      Returns an iterator over all elements in this collection except the first one.
      Specified by:
      iterator in interface Collection<PT_Locale>
      Specified by:
      iterator in interface Iterable<PT_Locale>
      Specified by:
      iterator in interface Set<PT_Locale>
      Specified by:
      iterator in class AbstractCollection<PT_Locale>
      Returns:
      iterator over all other locales.
    • add

      public boolean add(PT_Locale locale)
      Adds a new element to the collection of "other locales". If we had no "default locale" prior this method call, then this method will choose one before to add the given locale. This is needed since the other locales begin only after the first element, so a first element needs to exist.

      The above rule could be a risk of confusion for the users, since it could cause the apparition of a default locale which has never been specified. However, this risk exists only when invoking the deprecated methods, or when unmarshalling a XML document having a otherLocale property without defaultLocale property, which is probably invalid.

      Specified by:
      add in interface Collection<PT_Locale>
      Specified by:
      add in interface Set<PT_Locale>
      Overrides:
      add in class AbstractCollection<PT_Locale>
      Parameters:
      locale - the element to add.
      Returns:
      true if the "other locales" collection has been modified as a result of this method call.
    • setFirst

      public static Map<Locale,Charset> setFirst(Map<Locale,Charset> addTo, PT_Locale newValue)
      Returns a map containing the given PT_Locale followed by other locales in the given addTo map.
      Parameters:
      addTo - the map where to set the first locale, or null.
      newValue - the value to add in the map, or null.
      Returns:
      a map containing this locale followed by other locales in the given map.