sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1773749 - in /sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis: feature/ feature/builder/ internal/feature/
Date Mon, 12 Dec 2016 08:06:58 GMT
Author: desruisseaux
Date: Mon Dec 12 08:06:58 2016
New Revision: 1773749

URL: http://svn.apache.org/viewvc?rev=1773749&view=rev
Log:
Feature attribute should not be cloneable unless requested by the subclass.
Move 'parameters' package-private method in an internal package so it can be shared by GPX.

Added:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractAttribute.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/EnvelopeOperation.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/LinkOperation.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/MultiValuedAttribute.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SingletonAttribute.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/StringJoinOperation.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractAttribute.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractAttribute.java?rev=1773749&r1=1773748&r2=1773749&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractAttribute.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractAttribute.java
[UTF-8] Mon Dec 12 08:06:58 2016
@@ -62,9 +62,12 @@ import org.opengis.feature.MultiValuedPr
  *   <li><b>Serialization:</b> serialized objects of this class are not
guaranteed to be compatible with future
  *       versions. Serialization should be used only for short term storage or RMI between
applications running
  *       the same SIS version.</li>
+ *   <li><b>Cloning:</b> despite providing a public {@link #clone()} method,
this base class is <strong>not</strong>
+ *       cloneable by default. Subclasses shall implement the {@link Cloneable} interface
themselves if they choose
+ *       to support cloning.</li>
  * </ul>
  *
- * @param <V> The type of attribute values.
+ * @param  <V>  the type of attribute values.
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
@@ -75,7 +78,8 @@ import org.opengis.feature.MultiValuedPr
  * @see AbstractFeature
  * @see DefaultAttributeType
  */
-public abstract class AbstractAttribute<V> extends Field<V> implements Attribute<V>,
Cloneable, Serializable {
+@SuppressWarnings("CloneInNonCloneableClass")       // Decision left to subclasses - see
javadoc
+public abstract class AbstractAttribute<V> extends Field<V> implements Attribute<V>,
Serializable {
     /**
      * For cross-version compatibility.
      */
@@ -478,8 +482,10 @@ public abstract class AbstractAttribute<
     }
 
     /**
-     * Returns a copy of this attribute.
-     * The default implementation returns a <em>shallow</em> copy:
+     * Returns a copy of this attribute if cloning is supported.
+     * The decision to support cloning or not is left to subclasses. If the subclass does
not implement
+     * the {@link Cloneable} interface, then this method throws a {@link CloneNotSupportedException}.
+     * Otherwise the default implementation returns a <em>shallow</em> copy of
this {@code Attribute}:
      * the attribute {@linkplain #getValue() value} and {@linkplain #characteristics() characteristics}
      * are <strong>not</strong> cloned.
      * However subclasses may choose to do otherwise.

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/EnvelopeOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/EnvelopeOperation.java?rev=1773749&r1=1773748&r2=1773749&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/EnvelopeOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/EnvelopeOperation.java
[UTF-8] Mon Dec 12 08:06:58 2016
@@ -20,6 +20,7 @@ import java.util.Arrays;
 import java.util.Set;
 import java.util.Map;
 import java.util.LinkedHashMap;
+import java.util.Objects;
 import org.opengis.util.GenericName;
 import org.opengis.util.FactoryException;
 import org.opengis.geometry.Envelope;
@@ -29,6 +30,7 @@ import org.opengis.referencing.crs.Coord
 import org.opengis.referencing.operation.CoordinateOperation;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.internal.feature.AttributeConvention;
+import org.apache.sis.internal.feature.FeatureUtilities;
 import org.apache.sis.internal.feature.Geometries;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.geometry.Envelopes;
@@ -37,7 +39,6 @@ import org.apache.sis.referencing.CRS;
 import org.apache.sis.util.resources.Errors;
 
 // Branch-dependent imports
-import java.util.Objects;
 import org.opengis.feature.Attribute;
 import org.opengis.feature.AttributeType;
 import org.opengis.feature.Feature;
@@ -80,7 +81,7 @@ final class EnvelopeOperation extends Ab
     /**
      * The parameter descriptor for the "Envelope" operation, which does not take any parameter.
      */
-    private static final ParameterDescriptorGroup EMPTY_PARAMS = LinkOperation.parameters("Envelope",
1);
+    private static final ParameterDescriptorGroup EMPTY_PARAMS = FeatureUtilities.parameters("Envelope");
 
     /**
      * The names of all properties containing a geometry object.
@@ -117,9 +118,9 @@ final class EnvelopeOperation extends Ab
     /**
      * Creates a new operation computing the envelope of features of the given type.
      *
-     * @param identification     the name and other information to be given to this operation.
-     * @param crs                the coordinate reference system of envelopes to computes,
or {@code null}.
-     * @param geometryAttributes the operation or attribute type from which to get geometry
values.
+     * @param identification      the name and other information to be given to this operation.
+     * @param crs                 the coordinate reference system of envelopes to computes,
or {@code null}.
+     * @param geometryAttributes  the operation or attribute type from which to get geometry
values.
      */
     EnvelopeOperation(final Map<String,?> identification, CoordinateReferenceSystem
crs,
             final PropertyType[] geometryAttributes) throws FactoryException

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/LinkOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/LinkOperation.java?rev=1773749&r1=1773748&r2=1773749&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/LinkOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/LinkOperation.java
[UTF-8] Mon Dec 12 08:06:58 2016
@@ -18,15 +18,11 @@ package org.apache.sis.feature;
 
 import java.util.Set;
 import java.util.Map;
-import java.util.HashMap;
 import java.util.Collections;
 import java.io.IOException;
-import org.opengis.metadata.Identifier;
 import org.opengis.parameter.ParameterValueGroup;
-import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
-import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
-import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.internal.feature.FeatureUtilities;
 import org.apache.sis.util.ArgumentChecks;
 
 // Branch-dependent imports
@@ -42,7 +38,7 @@ import org.opengis.feature.PropertyType;
  *
  * @author  Johann Sorel (Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.8
  * @module
  */
 final class LinkOperation extends AbstractOperation {
@@ -52,28 +48,9 @@ final class LinkOperation extends Abstra
     private static final long serialVersionUID = 765096861589501215L;
 
     /**
-     * Creates a parameter descriptor in the Apache SIS namespace. This convenience method
shall
-     * not be in public API, because users should define operations in their own namespace.
-     *
-     * <div class="note"><b>Note:</b>
-     * this method is shared by other operations in this package, but is declared here in
order to delay
-     * {@link org.apache.sis.parameter} classes loading until we need to instantiate an operation
like this
-     * {@code LinkOperation}. Since {@code LinkOperation} is very light and often used, the
cost for other
-     * operations of loading this class is considered negligible.</div>
-     */
-    static ParameterDescriptorGroup parameters(final String name, final int minimumOccurs,
-            final ParameterDescriptor<?>... parameters)
-    {
-        final Map<String,Object> properties = new HashMap<>(4);
-        properties.put(ParameterDescriptorGroup.NAME_KEY, name);
-        properties.put(Identifier.AUTHORITY_KEY, Citations.SIS);
-        return new DefaultParameterDescriptorGroup(properties, minimumOccurs, 1);
-    }
-
-    /**
      * The parameter descriptor for the "Link" operation, which does not take any parameter.
      */
-    private static final ParameterDescriptorGroup EMPTY_PARAMS = parameters("Link", 1);
+    private static final ParameterDescriptorGroup EMPTY_PARAMS = FeatureUtilities.parameters("Link");
 
     /**
      * The type of the result.

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/MultiValuedAttribute.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/MultiValuedAttribute.java?rev=1773749&r1=1773748&r2=1773749&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/MultiValuedAttribute.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/MultiValuedAttribute.java
[UTF-8] Mon Dec 12 08:06:58 2016
@@ -41,19 +41,21 @@ import org.opengis.feature.MultiValuedPr
  *   <li><b>Serialization:</b> serialized objects of this class are not
guaranteed to be compatible with future
  *       versions. Serialization should be used only for short term storage or RMI between
applications running
  *       the same SIS version.</li>
+ *   <li><b>Cloning:</b> this class support <em>shallow</em>
cloning only:
+ *       the attribute is cloned, but not the {@linkplain #getValues() value} elements.</li>
  * </ul>
  *
- * @param <V> The type of the attribute values.
+ * @param  <V>  the type of the attribute values.
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
- * @version 0.6
+ * @version 0.8
  * @module
  *
  * @see DefaultAttributeType
  */
-final class MultiValuedAttribute<V> extends AbstractAttribute<V> {
+final class MultiValuedAttribute<V> extends AbstractAttribute<V> implements Cloneable
{
     /**
      * For cross-version compatibility.
      */

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SingletonAttribute.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SingletonAttribute.java?rev=1773749&r1=1773748&r2=1773749&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SingletonAttribute.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SingletonAttribute.java
[UTF-8] Mon Dec 12 08:06:58 2016
@@ -31,19 +31,22 @@ import org.opengis.feature.AttributeType
  * <ul>
  *   <li><b>Multi-threading:</b> {@code SingletonAttribute} instances are
<strong>not</strong> thread-safe.
  *       Synchronization, if needed, shall be done externally by the caller.</li>
+ *   <li><b>Cloning:</b> this class support <em>shallow</em>
cloning only:
+ *       the attribute is cloned, but not its {@linkplain #getValue() value}.</li>
  * </ul>
  *
- * @param <V> The type of the attribute value.
+ * @param  <V>  the type of the attribute value.
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
- * @version 0.5
+ * @version 0.8
  * @module
  *
  * @see DefaultAttributeType
  */
-final class SingletonAttribute<V> extends AbstractAttribute<V> {
+@SuppressWarnings("CloneableClassWithoutClone")     // Nothing to add compared to subclass.
+final class SingletonAttribute<V> extends AbstractAttribute<V> implements Cloneable
{
     /**
      * For cross-version compatibility.
      */
@@ -58,7 +61,7 @@ final class SingletonAttribute<V> extend
      * Creates a new attribute of the given type initialized to the
      * {@linkplain DefaultAttributeType#getDefaultValue() default value}.
      *
-     * @param type Information about the attribute (base Java class, domain of values, <i>etc.</i>).
+     * @param type  information about the attribute (base Java class, domain of values, <i>etc.</i>).
      */
     public SingletonAttribute(final AttributeType<V> type) {
         super(type);
@@ -70,8 +73,8 @@ final class SingletonAttribute<V> extend
      * Creates a new attribute of the given type initialized to the given value.
      * Note that a {@code null} value may not be the same as the default value.
      *
-     * @param type  Information about the attribute (base Java class, domain of values, <i>etc.</i>).
-     * @param value The initial value (may be {@code null}).
+     * @param type   information about the attribute (base Java class, domain of values,
<i>etc.</i>).
+     * @param value  the initial value (may be {@code null}).
      */
     SingletonAttribute(final AttributeType<V> type, final Object value) {
         super(type);
@@ -82,7 +85,7 @@ final class SingletonAttribute<V> extend
     /**
      * Returns the attribute value.
      *
-     * @return The attribute value (may be {@code null}).
+     * @return the attribute value (may be {@code null}).
      */
     @Override
     public V getValue() {
@@ -92,7 +95,7 @@ final class SingletonAttribute<V> extend
     /**
      * Sets the attribute value.
      *
-     * @param value The new value.
+     * @param value the new value.
      */
     @Override
     public void setValue(final V value) {
@@ -102,7 +105,7 @@ final class SingletonAttribute<V> extend
     /**
      * Returns a hash code value for this attribute.
      *
-     * @return A hash code value.
+     * @return a hash code value.
      */
     @Override
     public int hashCode() {

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/StringJoinOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/StringJoinOperation.java?rev=1773749&r1=1773748&r2=1773749&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/StringJoinOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/StringJoinOperation.java
[UTF-8] Mon Dec 12 08:06:58 2016
@@ -19,11 +19,13 @@ package org.apache.sis.feature;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.Set;
+import java.util.Objects;
 import java.io.IOException;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.util.GenericName;
 import org.apache.sis.internal.util.CollectionsExt;
+import org.apache.sis.internal.feature.FeatureUtilities;
 import org.apache.sis.internal.feature.Resources;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ObjectConverter;
@@ -34,7 +36,6 @@ import org.apache.sis.util.CharSequences
 import org.apache.sis.util.Classes;
 
 // Branch-dependent imports
-import java.util.Objects;
 import org.opengis.feature.AttributeType;
 import org.opengis.feature.Feature;
 import org.opengis.feature.IdentifiedType;
@@ -74,7 +75,7 @@ final class StringJoinOperation extends
     /**
      * The parameter descriptor for the "String join" operation, which does not take any
parameter.
      */
-    private static final ParameterDescriptorGroup EMPTY_PARAMS = LinkOperation.parameters("StringJoin",
1);
+    private static final ParameterDescriptorGroup EMPTY_PARAMS = FeatureUtilities.parameters("StringJoin");
 
     /**
      * The name of the properties (attributes of operations producing attributes)

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java?rev=1773749&r1=1773748&r2=1773749&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
[UTF-8] Mon Dec 12 08:06:58 2016
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Locale;
 import java.util.Set;
+import java.util.Objects;
 import org.opengis.util.GenericName;
 import org.opengis.util.NameFactory;
 import org.opengis.util.FactoryException;
@@ -38,7 +39,6 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.util.ArraysExt;
 
 // Branch-dependent imports
-import java.util.Objects;
 import org.opengis.feature.AttributeType;
 import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;

Added: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java?rev=1773749&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java
(added)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java
[UTF-8] Mon Dec 12 08:06:58 2016
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.feature;
+
+import java.util.Map;
+import java.util.HashMap;
+import org.opengis.metadata.Identifier;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.ParameterDescriptorGroup;
+import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.util.Static;
+
+
+/**
+ * Non-public utility methods for Apache SIS internal usage.
+ *
+ * @author  Johann Sorel (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+public final class FeatureUtilities extends Static {
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private FeatureUtilities() {
+    }
+
+    /**
+     * Creates a parameter descriptor in the Apache SIS namespace. This convenience method
shall
+     * not be in public API, because users should define operations in their own namespace.
+     *
+     * @param  name           the parameter group name, typically the same as operation name.
+     * @param  parameters     the parameters, or an empty array if none.
+     * @return description of the parameters group.
+     */
+    public static ParameterDescriptorGroup parameters(final String name, final ParameterDescriptor<?>...
parameters) {
+        final Map<String,Object> properties = new HashMap<>(4);
+        properties.put(ParameterDescriptorGroup.NAME_KEY, name);
+        properties.put(Identifier.AUTHORITY_KEY, Citations.SIS);
+        return new DefaultParameterDescriptorGroup(properties, 1, 1);
+    }
+}

Propchange: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8



Mime
View raw message