sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1593584 - in /sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature: DefaultAssociation.java DefaultAssociationRole.java DefaultAttribute.java DefaultAttributeType.java DefaultFeature.java DefaultFeatureType.java
Date Fri, 09 May 2014 17:33:54 GMT
Author: desruisseaux
Date: Fri May  9 17:33:53 2014
New Revision: 1593584

URL: http://svn.apache.org/r1593584
Log:
Added DefaultAssociation as a complement of DefaultAssociationRole, so we have the complete
set of expected java classes.
The intend is to help to take those properties in account while working on DefaultFeature
internal.

Added:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java

Added: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java?rev=1593584&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
(added)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociation.java
[UTF-8] Fri May  9 17:33:53 2014
@@ -0,0 +1,174 @@
+/*
+ * 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.feature;
+
+import java.io.Serializable;
+import org.apache.sis.util.Debug;
+import org.apache.sis.util.ArgumentChecks;
+
+// Related to JDK7
+import java.util.Objects;
+
+
+/**
+ * Indicates the role played by the association between two features.
+ *
+ * {@section Usage in multi-thread environment}
+ * {@code DefaultAssociation} are <strong>not</strong> thread-safe.
+ * Synchronization, if needed, shall be done externally by the caller.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+public class DefaultAssociation extends Property implements Cloneable, Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -1175014792131253528L;
+
+    /**
+     * Information about the association.
+     */
+    private final DefaultAssociationRole role;
+
+    /**
+     * The associated feature.
+     */
+    private DefaultFeature value;
+
+    /**
+     * Creates a new association of the given type.
+     *
+     * @param role Information about the association.
+     */
+    public DefaultAssociation(final DefaultAssociationRole role) {
+        ArgumentChecks.ensureNonNull("role", role);
+        this.role = role;
+    }
+
+    /**
+     * Creates a new association of the given type initialized to the given value.
+     *
+     * @param role  Information about the association.
+     * @param value The initial value.
+     */
+    public DefaultAssociation(final DefaultAssociationRole role, final DefaultFeature value)
{
+        ArgumentChecks.ensureNonNull("role", role);
+        this.role  = role;
+        this.value = value;
+    }
+
+    /**
+     * Returns information about the association.
+     *
+     * <div class="warning"><b>Warning:</b> In a future SIS version, the
return type may be changed
+     * to {@code org.opengis.feature.AssociationRole}. This change is pending GeoAPI revision.</div>
+     *
+     * @return Information about the association.
+     */
+    public DefaultAssociationRole getRole() {
+        return role;
+    }
+
+    /**
+     * Returns the associated feature.
+     *
+     * <div class="warning"><b>Warning:</b> In a future SIS version, the
return type may be changed
+     * to {@code org.opengis.feature.Feature}. This change is pending GeoAPI revision.</div>
+     *
+     * @return The associated feature (may be {@code null}).
+     *
+     * @see DefaultFeature#getPropertyValue(String)
+     */
+    public DefaultFeature getValue() {
+        return value;
+    }
+
+    /**
+     * Sets the associated feature.
+     *
+     * <div class="warning"><b>Warning:</b> In a future SIS version, the
argument type may be changed
+     * to {@code org.opengis.feature.Feature}. This change is pending GeoAPI revision.</div>
+     *
+     * @param  value The new value.
+     *
+     * @see DefaultFeature#setPropertyValue(String, Object)
+     */
+    public void setValue(final DefaultFeature value) {
+        this.value = value;
+    }
+
+    /**
+     * Returns a shallow copy of this association.
+     * The association {@linkplain #getValue() value} is <strong>not</strong>
cloned.
+     *
+     * @return A clone of this association.
+     */
+    @Override
+    public DefaultAssociation clone() {
+        final DefaultAssociation clone;
+        try {
+            clone = (DefaultAssociation) super.clone();
+        } catch (CloneNotSupportedException e) {
+            throw new AssertionError(e); // Should never happen since we are cloneable.
+        }
+        return clone;
+    }
+
+    /**
+     * Returns a hash code value for this association.
+     *
+     * @return A hash code value.
+     */
+    @Override
+    public int hashCode() {
+        return role.hashCode() + Objects.hashCode(value);
+    }
+
+    /**
+     * Compares this association with the given object for equality.
+     *
+     * @return {@code true} if both objects are equal.
+     */
+    @Override
+    public boolean equals(final Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (obj != null && obj.getClass() == getClass()) {
+            final DefaultAssociation that = (DefaultAssociation) obj;
+            return role.equals(that.role) &&
+                   Objects.equals(value, that.value);
+        }
+        return false;
+    }
+
+    /**
+     * Returns a string representation of this association.
+     * The returned string is for debugging purpose and may change in any future SIS version.
+     *
+     * @return A string representation of this association for debugging purpose.
+     */
+    @Debug
+    @Override
+    public String toString() {
+        return role.toString("Association", role.getValueType().getName().toString())
+                .append(" = ").append(value).toString();
+    }
+}

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

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

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java?rev=1593584&r1=1593583&r2=1593584&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAssociationRole.java
[UTF-8] Fri May  9 17:33:53 2014
@@ -17,6 +17,8 @@
 package org.apache.sis.feature;
 
 import java.util.Map;
+import org.opengis.util.GenericName;
+import org.opengis.util.InternationalString;
 import org.apache.sis.util.Debug;
 
 import static org.apache.sis.util.ArgumentChecks.*;
@@ -25,6 +27,11 @@ import static org.apache.sis.util.Argume
 /**
  * Indicates the role played by the association between two features.
  *
+ * {@section Immutability and thread safety}
+ * Instances of this class are immutable if all properties ({@link GenericName} and {@link
InternationalString}
+ * instances) and all arguments (e.g. {@code valueType}) given to the constructor are also
immutable.
+ * Such immutable instances can be shared by many objects and passed between threads without
synchronization.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
  * @version 0.5
@@ -57,22 +64,22 @@ public class DefaultAssociationRole exte
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#NAME_KEY}</td>
-     *     <td>{@link org.opengis.util.GenericName} or {@link String}</td>
+     *     <td>{@link GenericName} or {@link String}</td>
      *     <td>{@link #getName()}</td>
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#DEFINITION_KEY}</td>
-     *     <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
+     *     <td>{@link InternationalString} or {@link String}</td>
      *     <td>{@link #getDefinition()}</td>
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#DESIGNATION_KEY}</td>
-     *     <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
+     *     <td>{@link InternationalString} or {@link String}</td>
      *     <td>{@link #getDesignation()}</td>
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#DESCRIPTION_KEY}</td>
-     *     <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
+     *     <td>{@link InternationalString} or {@link String}</td>
      *     <td>{@link #getDescription()}</td>
      *   </tr>
      * </table>
@@ -103,7 +110,6 @@ public class DefaultAssociationRole exte
         return valueType;
     }
 
-
     /**
      * Returns the minimum number of occurrences of the association within its containing
entity.
      * The returned value is greater than or equal to zero.
@@ -156,10 +162,10 @@ public class DefaultAssociationRole exte
     }
 
     /**
-     * Returns a string representation of this attribute type.
+     * Returns a string representation of this association role.
      * The returned string is for debugging purpose and may change in any future SIS version.
      *
-     * @return A string representation of this attribute type for debugging purpose.
+     * @return A string representation of this association role for debugging purpose.
      */
     @Debug
     @Override

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java?rev=1593584&r1=1593583&r2=1593584&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttribute.java
[UTF-8] Fri May  9 17:33:53 2014
@@ -92,7 +92,7 @@ public class DefaultAttribute<T> extends
      * Returns information about the attribute (base Java class, domain of values, <i>etc.</i>).
      *
      * <div class="warning"><b>Warning:</b> In a future SIS version, the
return type may be changed
-     * to {@code org.opengis.feature.AttrbuteType}. This change is pending GeoAPI revision.</div>
+     * to {@code org.opengis.feature.AttributeType}. This change is pending GeoAPI revision.</div>
      *
      * @return Information about the attribute.
      */

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java?rev=1593584&r1=1593583&r2=1593584&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultAttributeType.java
[UTF-8] Fri May  9 17:33:53 2014
@@ -107,22 +107,22 @@ public class DefaultAttributeType<T> ext
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#NAME_KEY}</td>
-     *     <td>{@link org.opengis.util.GenericName} or {@link String}</td>
+     *     <td>{@link GenericName} or {@link String}</td>
      *     <td>{@link #getName()}</td>
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#DEFINITION_KEY}</td>
-     *     <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
+     *     <td>{@link InternationalString} or {@link String}</td>
      *     <td>{@link #getDefinition()}</td>
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#DESIGNATION_KEY}</td>
-     *     <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
+     *     <td>{@link InternationalString} or {@link String}</td>
      *     <td>{@link #getDesignation()}</td>
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#DESCRIPTION_KEY}</td>
-     *     <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
+     *     <td>{@link InternationalString} or {@link String}</td>
      *     <td>{@link #getDescription()}</td>
      *   </tr>
      * </table>

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java?rev=1593584&r1=1593583&r2=1593584&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java
[UTF-8] Fri May  9 17:33:53 2014
@@ -36,6 +36,9 @@ import org.apache.sis.util.collection.Co
  *   <li>{@linkplain DefaultOperation   Operations}</li>
  * </ul>
  *
+ * If a feature allows only attributes and operations (no associations), and if the cardinality
of all attributes
+ * is constrained to [1 … 1], then the feature is said “simple”.
+ *
  * {@section Usage in multi-thread environment}
  * {@code DefaultFeature} are <strong>not</strong> thread-safe.
  * Synchronization, if needed, shall be done externally by the caller.

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java?rev=1593584&r1=1593583&r2=1593584&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] Fri May  9 17:33:53 2014
@@ -133,22 +133,22 @@ public class DefaultFeatureType extends 
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#NAME_KEY}</td>
-     *     <td>{@link org.opengis.util.GenericName} or {@link String}</td>
+     *     <td>{@link GenericName} or {@link String}</td>
      *     <td>{@link #getName()}</td>
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#DEFINITION_KEY}</td>
-     *     <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
+     *     <td>{@link InternationalString} or {@link String}</td>
      *     <td>{@link #getDefinition()}</td>
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#DESIGNATION_KEY}</td>
-     *     <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
+     *     <td>{@link InternationalString} or {@link String}</td>
      *     <td>{@link #getDesignation()}</td>
      *   </tr>
      *   <tr>
      *     <td>{@value org.apache.sis.feature.AbstractIdentifiedType#DESCRIPTION_KEY}</td>
-     *     <td>{@link org.opengis.util.InternationalString} or {@link String}</td>
+     *     <td>{@link InternationalString} or {@link String}</td>
      *     <td>{@link #getDescription()}</td>
      *   </tr>
      * </table>
@@ -204,16 +204,24 @@ public class DefaultFeatureType extends 
             if (byName.put(s, property) != null) {
                 throw new IllegalArgumentException(Errors.format(Errors.Keys.DuplicatedIdentifier_1,
s));
             }
-            if (!(property instanceof DefaultOperation)) {
-                if (property instanceof DefaultAttributeType<?>) {
-                    switch (((DefaultAttributeType<?>) property).getMaximumOccurs())
{
-                        case 0:  continue;
-                        case 1:  isSimple &= (((DefaultAttributeType<?>) property).getMinimumOccurs()
== 1); break;
-                        default: isSimple = false; break;
-                    }
-                } else {
+            /*
+             * Stores indices that the property elements would have in a flat array,
+             * and opportunistically check if the FeatureType is "simple".
+             */
+            final int maximumOccurs;
+            if (property instanceof DefaultAttributeType<?>) { // TODO: check for AttributeType
instead (after GeoAPI upgrade).
+                maximumOccurs = ((DefaultAttributeType<?>) property).getMaximumOccurs();
+                if (isSimple && ((DefaultAttributeType<?>) property).getMinimumOccurs()
!= maximumOccurs) {
                     isSimple = false;
                 }
+            } else if (property instanceof FieldType) { // TODO: check for AssociationRole
instead (after GeoAPI upgrade).
+                maximumOccurs = ((FieldType) property).getMaximumOccurs();
+                isSimple = false;
+            } else {
+                continue; // For feature operations, maximumOccurs is implicitly 0.
+            }
+            if (maximumOccurs != 0) {
+                isSimple &= (maximumOccurs == 1);
                 indices.put(s, index++);
             }
         }



Mime
View raw message