sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1779506 [9/9] - in /sis/branches/JDK8/core: sis-feature/src/main/java/org/apache/sis/feature/ sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-metadata/src/main/java/org/apache/sis/metadata/ sis-metadata/src/main/java/org/apache/sis/m...
Date Thu, 19 Jan 2017 18:46:46 GMT
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java?rev=1779506&r1=1779505&r2=1779506&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
[UTF-8] Thu Jan 19 18:46:44 2017
@@ -58,6 +58,7 @@ import org.apache.sis.xml.Namespaces;
  * @version 0.3
  * @module
  */
+@SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
 @XmlType(name = "MD_Georectified_Type", propOrder = {
     "checkPointAvailable",
     "checkPointDescription",
@@ -135,7 +136,7 @@ public class DefaultGeorectified extends
      * This is a <cite>shallow</cite> copy constructor, since the other metadata
contained in the
      * given object are not recursively copied.
      *
-     * @param object The metadata to copy values from, or {@code null} if none.
+     * @param  object  the metadata to copy values from, or {@code null} if none.
      *
      * @see #castOrCopy(Georectified)
      */
@@ -171,8 +172,8 @@ public class DefaultGeorectified extends
      *       metadata contained in the given object are not recursively copied.</li>
      * </ul>
      *
-     * @param  object The object to get as a SIS implementation, or {@code null} if none.
-     * @return A SIS implementation containing the values of the given object (may be the
+     * @param  object  the object to get as a SIS implementation, or {@code null} if none.
+     * @return a SIS implementation containing the values of the given object (may be the
      *         given object itself), or {@code null} if the argument was null.
      */
     public static DefaultGeorectified castOrCopy(final Georectified object) {
@@ -186,7 +187,7 @@ public class DefaultGeorectified extends
      * Returns an indication of whether or not geographic position points are available to
test the
      * accuracy of the georeferenced grid data.
      *
-     * @return Whether or not geographic position points are available to test accuracy.
+     * @return whether or not geographic position points are available to test accuracy.
      */
     @Override
     @XmlElement(name = "checkPointAvailability", required = true)
@@ -223,7 +224,7 @@ public class DefaultGeorectified extends
      * georeferenced grid data. This value is non-null only if {@link #isCheckPointAvailable()}
      * returns {@code true}.
      *
-     * @return Description of geographic position points used to test accuracy, or {@code
null}.
+     * @return description of geographic position points used to test accuracy, or {@code
null}.
      */
     @Override
     @XmlElement(name = "checkPointDescription")
@@ -239,7 +240,7 @@ public class DefaultGeorectified extends
      * If and only if the given {@code newValue} is non-null, then this method automatically
sets
      * the {@linkplain #setCheckPointAvailable check point availability} property to {@code
true}.
      *
-     * @param newValue The new check point description.
+     * @param  newValue  the new check point description.
      */
     public void setCheckPointDescription(final InternationalString newValue) {
         checkWritePermission();
@@ -253,7 +254,7 @@ public class DefaultGeorectified extends
      * Returns the Earth location in the coordinate system defined by the Spatial Reference
System
      * and the grid coordinate of the cells at opposite ends of grid coverage along two diagonals.
      *
-     * @return The corner points.
+     * @return the corner points.
      */
     @Override
     @XmlElement(name = "cornerPoints", required = true)
@@ -270,7 +271,7 @@ public class DefaultGeorectified extends
      *
      * <p>The first corner point shall correspond to the origin of the grid.</p>
      *
-     * @param newValues The new corner points.
+     * @param  newValues  the new corner points.
      */
     public void setCornerPoints(final List<? extends Point> newValues) {
         cornerPoints = writeList(newValues, cornerPoints, Point.class);
@@ -281,7 +282,7 @@ public class DefaultGeorectified extends
      * and the grid coordinate of the cell halfway between opposite ends of the grid in the
      * spatial dimensions.
      *
-     * @return The center point, or {@code null}.
+     * @return the center point, or {@code null}.
      */
     @Override
     @XmlElement(name = "centerPoint")
@@ -292,7 +293,7 @@ public class DefaultGeorectified extends
     /**
      * Sets the center point.
      *
-     * @param newValue The new center point.
+     * @param  newValue  the new center point.
      */
     public void setCenterPoint(final Point newValue) {
         checkWritePermission();
@@ -302,7 +303,7 @@ public class DefaultGeorectified extends
     /**
      * Returns the point in a pixel corresponding to the Earth location of the pixel.
      *
-     * @return Earth location of the pixel, or {@code null}.
+     * @return earth location of the pixel, or {@code null}.
      */
     @Override
     @XmlElement(name = "pointInPixel", required = true)
@@ -313,7 +314,7 @@ public class DefaultGeorectified extends
     /**
      * Sets the point in a pixel corresponding to the Earth location of the pixel.
      *
-     * @param newValue The new point in a pixel.
+     * @param  newValue  the new point in a pixel.
      */
     public void setPointInPixel(final PixelOrientation newValue) {
         checkWritePermission();
@@ -323,7 +324,7 @@ public class DefaultGeorectified extends
     /**
      * Returns a general description of the transformation.
      *
-     * @return General description of the transformation, or {@code null}.
+     * @return general description of the transformation, or {@code null}.
      */
     @Override
     @XmlElement(name = "transformationDimensionDescription")
@@ -334,7 +335,7 @@ public class DefaultGeorectified extends
     /**
      * Sets a general description of the transformation.
      *
-     * @param newValue The new general description.
+     * @param  newValue  the new general description.
      */
     public void setTransformationDimensionDescription(final InternationalString newValue)
{
         checkWritePermission();
@@ -344,7 +345,7 @@ public class DefaultGeorectified extends
     /**
      * Returns information about which grid dimensions are the spatial dimensions.
      *
-     * @return Information about which grid dimensions are the spatial dimensions, or {@code
null}.
+     * @return information about which grid dimensions are the spatial dimensions, or {@code
null}.
      */
     @Override
     @XmlElement(name = "transformationDimensionMapping")
@@ -356,7 +357,7 @@ public class DefaultGeorectified extends
      * Sets information about which grid dimensions are the spatial dimensions.
      * The given list should contain at most 2 elements.
      *
-     * @param newValues The new transformation mapping.
+     * @param  newValues  the new transformation mapping.
      */
     public void setTransformationDimensionMapping(final Collection<? extends InternationalString>
newValues) {
         transformationDimensionMapping = writeCollection(newValues, transformationDimensionMapping,
InternationalString.class);
@@ -365,7 +366,7 @@ public class DefaultGeorectified extends
     /**
      * Returns the geographic references used to validate georectification of the data.
      *
-     * @return Geographic references used to validate georectification.
+     * @return geographic references used to validate georectification.
      */
     @Override
     @XmlElement(name = "checkPoint", namespace = Namespaces.GMI)
@@ -376,7 +377,7 @@ public class DefaultGeorectified extends
     /**
      * Sets the geographic references used to validate georectification of the data.
      *
-     * @param newValues The new check points values.
+     * @param  newValues  the new check points values.
      */
     public void setCheckPoints(final Collection<? extends GCP> newValues) {
         checkPoints = writeCollection(newValues, checkPoints, GCP.class);

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeoreferenceable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeoreferenceable.java?rev=1779506&r1=1779505&r2=1779506&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeoreferenceable.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeoreferenceable.java
[UTF-8] Thu Jan 19 18:46:44 2017
@@ -50,6 +50,7 @@ import org.apache.sis.xml.Namespaces;
  * @version 0.3
  * @module
  */
+@SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
 @XmlType(name = "MD_Georeferenceable_Type", propOrder = {
     "controlPointAvailable",
     "orientationParameterAvailable",
@@ -110,7 +111,7 @@ public class DefaultGeoreferenceable ext
      * This is a <cite>shallow</cite> copy constructor, since the other metadata
contained in the
      * given object are not recursively copied.
      *
-     * @param object The metadata to copy values from, or {@code null} if none.
+     * @param  object  the metadata to copy values from, or {@code null} if none.
      *
      * @see #castOrCopy(Georeferenceable)
      */
@@ -144,8 +145,8 @@ public class DefaultGeoreferenceable ext
      *       metadata contained in the given object are not recursively copied.</li>
      * </ul>
      *
-     * @param  object The object to get as a SIS implementation, or {@code null} if none.
-     * @return A SIS implementation containing the values of the given object (may be the
+     * @param  object  the object to get as a SIS implementation, or {@code null} if none.
+     * @return a SIS implementation containing the values of the given object (may be the
      *         given object itself), or {@code null} if the argument was null.
      */
     public static DefaultGeoreferenceable castOrCopy(final Georeferenceable object) {
@@ -158,7 +159,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Returns an indication of whether or not control point(s) exists.
      *
-     * @return Whether or not control point(s) exists.
+     * @return whether or not control point(s) exists.
      */
     @Override
     @XmlElement(name = "controlPointAvailability", required = true)
@@ -183,7 +184,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Returns an indication of whether or not orientation parameters are available.
      *
-     * @return Whether or not orientation parameters are available.
+     * @return whether or not orientation parameters are available.
      */
     @Override
     @XmlElement(name = "orientationParameterAvailability", required = true)
@@ -208,7 +209,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Returns a description of parameters used to describe sensor orientation.
      *
-     * @return Description of parameters used to describe sensor orientation, or {@code null}.
+     * @return description of parameters used to describe sensor orientation, or {@code null}.
      */
     @Override
     @XmlElement(name = "orientationParameterDescription")
@@ -219,7 +220,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Sets a description of parameters used to describe sensor orientation.
      *
-     * @param newValue The new orientation parameter description.
+     * @param  newValue  the new orientation parameter description.
      */
     public void setOrientationParameterDescription(final InternationalString newValue) {
         checkWritePermission();
@@ -229,7 +230,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Returns the terms which support grid data georeferencing.
      *
-     * @return Terms which support grid data georeferencing, or {@code null}.
+     * @return terms which support grid data georeferencing, or {@code null}.
      */
     @Override
 /// @XmlElement(name = "georeferencedParameters", required = true)
@@ -240,7 +241,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Sets the terms which support grid data georeferencing.
      *
-     * @param newValue The new georeferenced parameters.
+     * @param  newValue  the new georeferenced parameters.
      */
     public void setGeoreferencedParameters(final Record newValue) {
         checkWritePermission();
@@ -250,7 +251,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Returns a reference providing description of the parameters.
      *
-     * @return Reference providing description of the parameters.
+     * @return reference providing description of the parameters.
      */
     @Override
     @XmlElement(name = "parameterCitation")
@@ -261,7 +262,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Sets a reference providing description of the parameters.
      *
-     * @param newValues The new parameter citations.
+     * @param  newValues  the new parameter citations.
      */
     public void setParameterCitations(final Collection<? extends Citation> newValues)
{
         parameterCitations = writeCollection(newValues, parameterCitations, Citation.class);
@@ -270,7 +271,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Returns the information that can be used to geolocate the data.
      *
-     * @return A geolocalisation of the data.
+     * @return a geolocalisation of the data.
      */
     @Override
     @XmlElement(name = "geolocationInformation", namespace = Namespaces.GMI, required = true)
@@ -281,7 +282,7 @@ public class DefaultGeoreferenceable ext
     /**
      * Sets the information that can be used to geolocate the data.
      *
-     * @param newValues The new geolocation information values.
+     * @param  newValues  the new geolocation information values.
      */
     public void setGeolocationInformation(final Collection<? extends GeolocationInformation>
newValues) {
         geolocationInformation = writeCollection(newValues, geolocationInformation, GeolocationInformation.class);

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java?rev=1779506&r1=1779505&r2=1779506&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java
[UTF-8] Thu Jan 19 18:46:44 2017
@@ -50,6 +50,7 @@ import static org.apache.sis.internal.me
  * @version 0.5
  * @module
  */
+@SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
 @XmlType(name = "MD_GridSpatialRepresentation_Type", propOrder = {
     "numberOfDimensions",
     "axisDimensionProperties",
@@ -122,7 +123,7 @@ public class DefaultGridSpatialRepresent
      * metadata instances can also be obtained by unmarshalling an invalid XML document.
      * </div>
      *
-     * @param object The metadata to copy values from, or {@code null} if none.
+     * @param  object  the metadata to copy values from, or {@code null} if none.
      *
      * @see #castOrCopy(GridSpatialRepresentation)
      */
@@ -157,8 +158,8 @@ public class DefaultGridSpatialRepresent
      *       metadata contained in the given object are not recursively copied.</li>
      * </ul>
      *
-     * @param  object The object to get as a SIS implementation, or {@code null} if none.
-     * @return A SIS implementation containing the values of the given object (may be the
+     * @param  object  the object to get as a SIS implementation, or {@code null} if none.
+     * @return a SIS implementation containing the values of the given object (may be the
      *         given object itself), or {@code null} if the argument was null.
      */
     public static DefaultGridSpatialRepresentation castOrCopy(final GridSpatialRepresentation
object) {
@@ -178,7 +179,7 @@ public class DefaultGridSpatialRepresent
     /**
      * Returns the number of independent spatial-temporal axes.
      *
-     * @return Number of independent spatial-temporal axes, or {@code null}.
+     * @return number of independent spatial-temporal axes, or {@code null}.
      */
     @Override
     @ValueRange(minimum = 0)
@@ -190,7 +191,7 @@ public class DefaultGridSpatialRepresent
     /**
      * Sets the number of independent spatial-temporal axes.
      *
-     * @param newValue The new number of dimension, or {@code null}.
+     * @param  newValue  the new number of dimension, or {@code null}.
      * @throws IllegalArgumentException if the given value is negative.
      */
     public void setNumberOfDimensions(final Integer newValue) {
@@ -203,7 +204,7 @@ public class DefaultGridSpatialRepresent
     /**
      * Returns information about spatial-temporal axis properties.
      *
-     * @return Information about spatial-temporal axis properties.
+     * @return information about spatial-temporal axis properties.
      */
     @Override
     @XmlElement(name = "axisDimensionProperties", required = true)
@@ -214,7 +215,7 @@ public class DefaultGridSpatialRepresent
     /**
      * Sets the information about spatial-temporal axis properties.
      *
-     * @param newValues The new axis dimension properties.
+     * @param  newValues  the new axis dimension properties.
      */
     public void setAxisDimensionProperties(final List<? extends Dimension> newValues)
{
         checkWritePermission();
@@ -225,7 +226,7 @@ public class DefaultGridSpatialRepresent
     /**
      * Returns the identification of grid data as point or cell.
      *
-     * @return Identification of grid data as point or cell, or {@code null}.
+     * @return identification of grid data as point or cell, or {@code null}.
      */
     @Override
     @XmlElement(name = "cellGeometry", required = true)
@@ -236,7 +237,7 @@ public class DefaultGridSpatialRepresent
     /**
      * Sets identification of grid data as point or cell.
      *
-     * @param newValue The new cell geometry.
+     * @param  newValue  the new cell geometry.
      */
     public void setCellGeometry(final CellGeometry newValue) {
         checkWritePermission();
@@ -246,7 +247,7 @@ public class DefaultGridSpatialRepresent
     /**
      * Returns indication of whether or not parameters for transformation exists.
      *
-     * @return Whether or not parameters for transformation exists.
+     * @return whether or not parameters for transformation exists.
      */
     @Override
     @XmlElement(name = "transformationParameterAvailability", required = true)

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultVectorSpatialRepresentation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultVectorSpatialRepresentation.java?rev=1779506&r1=1779505&r2=1779506&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultVectorSpatialRepresentation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultVectorSpatialRepresentation.java
[UTF-8] Thu Jan 19 18:46:44 2017
@@ -44,6 +44,7 @@ import org.opengis.metadata.spatial.Vect
  * @version 0.3
  * @module
  */
+@SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
 @XmlType(name = "MD_VectorSpatialRepresentation_Type", propOrder = {
     "topologyLevel",
     "geometricObjects"
@@ -78,7 +79,7 @@ public class DefaultVectorSpatialReprese
      * This is a <cite>shallow</cite> copy constructor, since the other metadata
contained in the
      * given object are not recursively copied.
      *
-     * @param object The metadata to copy values from, or {@code null} if none.
+     * @param  object  the metadata to copy values from, or {@code null} if none.
      *
      * @see #castOrCopy(VectorSpatialRepresentation)
      */
@@ -104,8 +105,8 @@ public class DefaultVectorSpatialReprese
      *       metadata contained in the given object are not recursively copied.</li>
      * </ul>
      *
-     * @param  object The object to get as a SIS implementation, or {@code null} if none.
-     * @return A SIS implementation containing the values of the given object (may be the
+     * @param  object  the object to get as a SIS implementation, or {@code null} if none.
+     * @return a SIS implementation containing the values of the given object (may be the
      *         given object itself), or {@code null} if the argument was null.
      */
     public static DefaultVectorSpatialRepresentation castOrCopy(final VectorSpatialRepresentation
object) {
@@ -118,7 +119,7 @@ public class DefaultVectorSpatialReprese
     /**
      * Returns the code which identifies the degree of complexity of the spatial relationships.
      *
-     * @return The degree of complexity of the spatial relationships, or {@code null}.
+     * @return the degree of complexity of the spatial relationships, or {@code null}.
      */
     @Override
     @XmlElement(name = "topologyLevel")
@@ -129,7 +130,7 @@ public class DefaultVectorSpatialReprese
     /**
      * Sets the code which identifies the degree of complexity of the spatial relationships.
      *
-     * @param newValue The new topology level.
+     * @param  newValue  the new topology level.
      */
     public void setTopologyLevel(final TopologyLevel newValue) {
         checkWritePermission();
@@ -139,7 +140,7 @@ public class DefaultVectorSpatialReprese
     /**
      * Returns information about the geometric objects used in the dataset.
      *
-     * @return Information about the geometric objects used in the dataset, or {@code null}.
+     * @return information about the geometric objects used in the dataset, or {@code null}.
      */
     @Override
     @XmlElement(name = "geometricObjects")
@@ -150,7 +151,7 @@ public class DefaultVectorSpatialReprese
     /**
      * Sets information about the geometric objects used in the dataset.
      *
-     * @param newValues The new geometric objects.
+     * @param  newValues  the new geometric objects.
      */
     public void setGeometricObjects(final Collection<? extends GeometricObjects> newValues)
{
         geometricObjects = writeCollection(newValues, geometricObjects, GeometricObjects.class);

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=1779506&r1=1779505&r2=1779506&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] Thu Jan 19 18:46:44 2017
@@ -22,6 +22,7 @@ import org.opengis.util.CodeList;
 import org.apache.sis.util.Static;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.collection.CodeListSet;
+import org.apache.sis.util.collection.CheckedContainer;
 import org.apache.sis.util.resources.Errors;
 import org.opengis.parameter.InvalidParameterCardinalityException;
 
@@ -393,6 +394,65 @@ public final class CollectionsExt extend
     }
 
     /**
+     * Returns a unmodifiable version of the given collection.
+     * If the given collection is a {@link Set} or a {@link List}, then this method tries
to
+     * return a collection of the same type. Other types are not guaranteed to be preserved.
+     *
+     * <p><em>The collection returned by this method may or may not be a view
of the given collection</em>.
+     * Consequently this method shall be used <strong>only</strong> if the given
collection will
+     * <strong>not</strong> be modified after this method call. In case of doubt,
use the
+     * standard {@link Collections#unmodifiableCollection(Collection)} method instead.</p>
+     *
+     * @param  <E>         the type of elements in the collection.
+     * @param  collection  the collection to make unmodifiable, or {@code null}.
+     * @return a unmodifiable version of the given collection, or {@code null} if the given
collection was null.
+     *
+     * @since 0.8
+     */
+    public static <E> Collection<E> unmodifiableOrCopy(Collection<E> collection)
{
+        if (collection != null) {
+            if (collection instanceof Set<?>) {
+                return unmodifiableOrCopy((Set<E>) collection);
+            }
+            final int length = collection.size();
+            switch (length) {
+                case 0: {
+                    collection = Collections.emptyList();
+                    break;
+                }
+                case 1: {
+                    collection = Collections.singletonList(collection.iterator().next());
+                    break;
+                }
+                default: {
+                    if (collection instanceof UnmodifiableArrayList<?>) {
+                        break;                                              // List is already
unmodifiable.
+                    }
+                    if (collection instanceof CheckedContainer<?>) {
+                        /*
+                         * We use UnmodifiableArrayList for avoiding one level of indirection.
The fact that it
+                         * implements CheckedContainer is not a goal here, and is actually
unsafe since we have
+                         * no guarantee (except Javadoc contract) that the <E> in CheckedContainer<E>
is really
+                         * the same than in Collection<E>.  We tolerate this hole for
now because we documented
+                         * the restriction in CheckedContainer javadoc, but future version
may replace this block
+                         * by JDK9 collections.
+                         */
+                        @SuppressWarnings("unchecked")       // Okay if collection is compliant
with CheckedContainer contract.
+                        final E[] array = (E[]) Array.newInstance(((CheckedContainer<E>)
collection).getElementType(), length);
+                        collection = UnmodifiableArrayList.wrap(collection.toArray(array));
+                    } else if (collection instanceof List<?>) {
+                        collection = Collections.unmodifiableList((List<E>) collection);
+                    } else {
+                        collection = Collections.unmodifiableCollection(collection);
+                    }
+                    break;
+                }
+            }
+        }
+        return collection;
+    }
+
+    /**
      * Copies the content of the given collection to a new, unsynchronized, modifiable, in-memory
      * collection. The implementation class of the returned collection may be different than
the
      * class of the collection given in argument. The following table gives the types mapping
@@ -498,7 +558,7 @@ public final class CollectionsExt extend
      * Returns a more compact representation of the given map. This method is similar to
      * {@link #unmodifiableOrCopy(Map)} except that it does not wrap the map in an unmodifiable
      * view. The intend is to avoid one level of indirection for performance and memory reasons.
-     * This is okay only if the map is kept in a private field and never escape outside this
class.
+     * This is okay only if the map is kept in a private field and never escape outside that
class.
      *
      * @param  <K>  the type of keys in the map.
      * @param  <V>  the type of values in the map.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedContainer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedContainer.java?rev=1779506&r1=1779505&r2=1779506&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedContainer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedContainer.java
[UTF-8] Thu Jan 19 18:46:44 2017
@@ -23,6 +23,14 @@ import java.util.Collection;
  * A container that ensures that all elements are assignable to a given base type.
  * Checked containers are usually {@link Collection}, but not always.
  *
+ * <p><b>Constraint:</b>
+ * if a class implements both {@code CheckedContainer} and {@code Collection},
+ * then the parameterized type shall be the same type. Example:</p>
+ *
+ * {@preformat java
+ *     class MyList<E> extends AbstractList<E> implements CheckedContainer<E>
{ ... }
+ * }
+ *
  * @param  <E>  the base type of elements in the container.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)



Mime
View raw message