/** * Provides information about an alternatively used localized character string for a linguistic extension. * * @return alternatively used localized character string for a linguistic extension. * * @deprecated As of GeoAPI 3.1, replaced by {@link #getLanguages()}. */ @Override @Deprecated @XmlElement(name = "locale") @XmlJavaTypeAdapter(PT_Locale.class) @Dependencies("getLanguages") public Collection<Locale> getLocales() { return OtherLocales.filter(getLanguages()); }
/** * Sets the default locale for this record (used in ISO 19115-3 format). */ private void setDefaultLocale(final Locale newValue) { setLanguages(OtherLocales.setFirst(languages, newValue)); // See "Note about deprecated methods implementation" }
/** * Returns a collection for all elements except the first one from the given collection. * * <p><b>Null values and XML marshalling:</b> * The {@code languages} argument may be {@code null} at XML marshalling time. In such case, this method returns * {@code null} instead than an empty set in order to instruct JAXB to not marshal the {@code otherLocale} element * (an empty set would cause JAXB to marshal an empty element). Since the {@code languages} argument given to this * method should never be null except at XML marshalling time, this rule should not be a violation of public API.</p> * * <p>The converse of this {@code filter} method is {@link #merge(Locale, Collection)}.</p> * * @param languages the collection containing the default locale followed by the other ones. * @return a collection containing all {@code languages} elements except the first one. */ public static Collection<Locale> filter(final Collection<Locale> languages) { return (languages != null) ? new OtherLocales(languages) : null; }
/** * Sets the other locales for this record (used in ISO 19115-3 format). */ private void setOtherLocales(final Collection<? extends Locale> newValues) { setLanguages(OtherLocales.merge(CollectionsExt.first(languages), newValues)); }
/** * Sets information about an alternatively used localized character string for a linguistic extension. * * @param newValues the new locales. * * @deprecated As of GeoAPI 3.1, replaced by {@link #setLanguages(Collection)}. */ @Deprecated public void setLocales(final Collection<? extends Locale> newValues) { checkWritePermission(); setLanguages(OtherLocales.merge(CollectionsExt.first(languages), newValues)); // See "Note about deprecated methods implementation" }
/** * Sets the default locale for this record (used in ISO 19115-3 format). */ @SuppressWarnings("unused") private void setDefaultLocale(final Locale newValue) { setLanguages(OtherLocales.setFirst(languages, newValue)); }
/** * Gets the other locales for this record (used in ISO 19115-3 format). */ @XmlElement(name = "otherLocale") private Collection<Locale> getOtherLocales() { return FilterByVersion.CURRENT_METADATA.accept() ? OtherLocales.filter(getLanguages()) : null; }
/** * Tests {@link OtherLocales#merge(Locale, Collection)}. */ @Test public void testMerge() { Collection<Locale> merged = OtherLocales.merge(null, null); assertTrue(merged.isEmpty()); merged = OtherLocales.merge(ENGLISH, null); assertArrayEquals(new Locale[] {ENGLISH}, merged.toArray()); merged = OtherLocales.merge(ENGLISH, Arrays.asList(FRENCH, JAPANESE)); assertArrayEquals(new Locale[] {ENGLISH, FRENCH, JAPANESE}, merged.toArray()); /* * The tricky case: a default locale will be generated. That locale is system-dependent. */ merged = OtherLocales.merge(null, Arrays.asList(FRENCH, JAPANESE)); final Iterator<Locale> it = merged.iterator(); assertNotNull(it.next()); // System-dependent value. assertEquals(FRENCH, it.next()); assertEquals(JAPANESE, it.next()); assertFalse(it.hasNext()); }
/** * Returns a collection for all elements except the first one from the given collection. * * <p><b>Null values and XML marshalling:</b> * The {@code languages} argument may be {@code null} at XML marshalling time. In such case, this method returns * {@code null} instead than an empty set in order to instruct JAXB to not marshal the {@code otherLocale} element * (an empty set would cause JAXB to marshal an empty element). Since the {@code languages} argument given to this * method should never be null except at XML marshalling time, this rule should not be a violation of public API.</p> * * <p>The converse of this {@code filter} method is {@link #merge(Locale, Collection)}.</p> * * @param languages the collection containing the default locale followed by the other ones. * @return a collection containing all {@code languages} elements except the first one. */ public static Collection<Locale> filter(final Collection<Locale> languages) { return (languages != null) ? new OtherLocales(languages) : null; }
/** * Sets the language used for documenting metadata. * This method modifies the collection returned by {@link #getLanguages()} as below: * * <ul> * <li>If the languages collection is empty, then this method sets the collection to the given {@code newValue}.</li> * <li>Otherwise the first element in the languages collection is replaced by the given {@code newValue}.</li> * </ul> * * @param newValue the new language. * * @deprecated As of GeoAPI 3.1, replaced by {@link #setLanguages(Collection)}. */ @Deprecated public void setLanguage(final Locale newValue) { checkWritePermission(); setLanguages(OtherLocales.setFirst(languages, newValue)); // See "Note about deprecated methods implementation" }
/** * Gets the other locales for this record (used in ISO 19115-3 format). */ @XmlElement(name = "otherLocale") private Collection<Locale> getOtherLocales() { return FilterByVersion.CURRENT_METADATA.accept() ? OtherLocales.filter(getLanguages()) : null; }
/** * Tests the {@link OtherLocales#setFirst(Collection, Object)} method. */ @Test public void testSetFirst() { Collection<Locale> locales = OtherLocales.setFirst(null, null); assertTrue(locales.isEmpty()); locales = OtherLocales.setFirst(null, GERMAN); assertArrayEquals(new Locale[] {GERMAN}, locales.toArray()); locales = Arrays.asList(ENGLISH, JAPANESE, FRENCH); assertSame("Shall set value in-place.", locales, OtherLocales.setFirst(locales, GERMAN)); assertArrayEquals(new Locale[] {GERMAN, JAPANESE, FRENCH}, locales.toArray()); locales = new LinkedHashSet<>(Arrays.asList(ENGLISH, JAPANESE, FRENCH)); locales = OtherLocales.setFirst(locales, ITALIAN); assertArrayEquals(new Locale[] {ITALIAN, JAPANESE, FRENCH}, locales.toArray()); locales = OtherLocales.setFirst(locales, null); assertArrayEquals(new Locale[] {JAPANESE, FRENCH}, locales.toArray()); } }
/** * Provides information about an alternatively used localized character string for a linguistic extension. * * @return alternatively used localized character string for a linguistic extension. * * @deprecated As of SIS 0.5, replaced by {@link #getLanguages()}. */ @Override @Deprecated @Dependencies("getLanguages") @XmlElement(name = "locale", namespace = LegacyNamespaces.GMD) public Collection<Locale> getLocales() { return FilterByVersion.LEGACY_METADATA.accept() ? OtherLocales.filter(getLanguages()) : null; }
public void testFilter() { final Collection<Locale> languages = new LinkedHashSet<>(); final Collection<Locale> otherLocales = OtherLocales.filter(languages); assertEquals("size", 0, otherLocales.size());