Author: desruisseaux Date: Wed Oct 7 19:37:07 2015 New Revision: 1707365 URL: http://svn.apache.org/viewvc?rev=1707365&view=rev Log: Remove a OtherLocales method which was duplicated in CollectionsExt. Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java?rev=1707365&r1=1707364&r2=1707365&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/OtherLocales.java [UTF-8] Wed Oct 7 19:37:07 2015 @@ -147,28 +147,6 @@ public final class OtherLocales extends } /** - * Returns the first element of the given collection, or {@code null} if none. - * This method does not emit warning if more than one element is found. - * Consequently, this method should be used only when multi-occurrence is not ambiguous. - * - *

Note: while defined in {@code OtherLocales} because the primary use for this method is to - * get the default locale, this method is also opportunistically used for other legacy properties.

- * - * @param The type of elements in the collection. - * @param values The collection from which to get the first element, or {@code null}. - * @return The first element found in the given collection, or {@code null}. - */ - public static T getFirst(final Collection values) { - if (values != null) { - final Iterator it = values.iterator(); - if (it.hasNext()) { - return it.next(); - } - } - return null; - } - - /** * Sets the first element in the given collection to the given value. * Special cases: * @@ -185,6 +163,8 @@ public final class OtherLocales extends * @param values The collection where to add the new value, or {@code null}. * @param newValue The new value to set, or {@code null} for instead removing the first element. * @return The collection (may or may not be the given {@code values} collection). + * + * @see org.apache.sis.internal.util.CollectionsExt#first(Iterable) */ public static Collection setFirst(Collection values, final T newValue) { if (values == null) { Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java?rev=1707365&r1=1707364&r2=1707365&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java [UTF-8] Wed Oct 7 19:37:07 2015 @@ -64,6 +64,7 @@ import org.apache.sis.metadata.iso.ident import org.apache.sis.metadata.iso.identification.DefaultDataIdentification; import org.apache.sis.internal.metadata.LegacyPropertyAdapter; import org.apache.sis.internal.metadata.OtherLocales; +import org.apache.sis.internal.util.CollectionsExt; import org.apache.sis.internal.jaxb.code.PT_Locale; import org.apache.sis.internal.jaxb.Context; import org.apache.sis.xml.Namespaces; @@ -455,7 +456,7 @@ public class DefaultMetadata extends ISO @Deprecated @XmlElement(name = "language") public Locale getLanguage() { - return OtherLocales.getFirst(getLanguages()); + return CollectionsExt.first(getLanguages()); // No warning if the collection contains more than one locale, because // this is allowed by the "getLanguage() + getLocales()" contract. } @@ -504,7 +505,7 @@ public class DefaultMetadata extends ISO @Deprecated public void setLocales(final Collection newValues) { checkWritePermission(); - setLanguages(OtherLocales.merge(OtherLocales.getFirst(languages), newValues)); // See "Note about deprecated methods implementation" + setLanguages(OtherLocales.merge(CollectionsExt.first(languages), newValues)); // See "Note about deprecated methods implementation" } /** @@ -1129,7 +1130,7 @@ public class DefaultMetadata extends ISO final URI uri = new URI(newValue); checkWritePermission(); Collection info = identificationInfo; // See "Note about deprecated methods implementation" - AbstractIdentification firstId = AbstractIdentification.castOrCopy(OtherLocales.getFirst(info)); + AbstractIdentification firstId = AbstractIdentification.castOrCopy(CollectionsExt.first(info)); if (firstId == null) { firstId = new DefaultDataIdentification(); } @@ -1138,7 +1139,7 @@ public class DefaultMetadata extends ISO citation = new DefaultCitation(); } Collection onlineResources = citation.getOnlineResources(); - DefaultOnlineResource firstOnline = DefaultOnlineResource.castOrCopy(OtherLocales.getFirst(onlineResources)); + DefaultOnlineResource firstOnline = DefaultOnlineResource.castOrCopy(CollectionsExt.first(onlineResources)); if (firstOnline == null) { firstOnline = new DefaultOnlineResource(); } @@ -1435,7 +1436,7 @@ public class DefaultMetadata extends ISO * This method sets the locale to be used for XML marshalling to the metadata language. */ private void beforeMarshal(final Marshaller marshaller) { - Context.push(OtherLocales.getFirst(languages)); + Context.push(CollectionsExt.first(languages)); } /** Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java?rev=1707365&r1=1707364&r2=1707365&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java [UTF-8] Wed Oct 7 19:37:07 2015 @@ -63,7 +63,10 @@ public final class CollectionsExt extend /** * Returns the first element of the given iterable, or {@code null} if none. - * This method is null-safe. Note that the first element may be null. + * This method does not emit warning if more than one element is found. + * Consequently, this method should be used only when multi-occurrence is not ambiguous. + * + *

This method is null-safe. Note however that the first element may be null.

* * @param The type of elements contained in the iterable. * @param collection The iterable from which to get the first element, or {@code null}.