sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1595944 [2/2] - in /sis/branches/JDK8: core/sis-feature/src/main/java/org/apache/sis/feature/ core/sis-feature/src/test/java/org/apache/sis/feature/ core/sis-feature/src/test/java/org/apache/sis/test/suite/ storage/sis-shapefile/src/main/j...
Date Mon, 19 May 2014 16:01:13 GMT
Copied: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
(from r1595794, 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/SparseFeature.java?p2=sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java&p1=sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeature.java&r1=1595794&r2=1595944&rev=1595944&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/SparseFeature.java
[UTF-8] Mon May 19 16:01:13 2014
@@ -19,36 +19,14 @@ package org.apache.sis.feature;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.ConcurrentModificationException;
-import java.io.Serializable;
-import org.opengis.util.GenericName;
-import org.opengis.metadata.quality.DataQuality;
-import org.opengis.metadata.maintenance.ScopeCode;
 import org.apache.sis.util.ArgumentChecks;
-import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.CorruptedObjectException;
 
 
 /**
- * An instance of a {@linkplain DefaultFeatureType feature type} containing values for a
real-world phenomena.
- * Each feature instance can provide values for the following properties:
- *
- * <ul>
- *   <li>{@linkplain DefaultAttribute   Attributes}</li>
- *   <li>{@linkplain DefaultAssociation Associations to other features}</li>
- *   <li>{@linkplain DefaultOperation   Operations}</li>
- * </ul>
- *
- * {@section Simple features}
- * A feature is said “simple” if it complies to the following conditions:
- * <ul>
- *   <li>the feature allows only attributes and operations (no associations),</li>
- *   <li>the cardinality of all attributes is constrained to [1 … 1].</li>
- * </ul>
- *
- * {@section Usage in multi-thread environment}
- * {@code DefaultFeature} are <strong>not</strong> thread-safe.
- * Synchronization, if needed, shall be done externally by the caller.
+ * A feature in which only a small fraction of properties are expected to be provided. This
implementation uses
+ * a {@link Map} for its internal storage of properties. This consumes less memory than a
plain array when we
+ * know that the array may be long and likely to be full of {@code null} values.
  *
  * @author  Travis L. Pinney
  * @author  Johann Sorel (Geomatys)
@@ -57,13 +35,14 @@ import org.apache.sis.util.CorruptedObje
  * @version 0.5
  * @module
  *
+ * @see DenseFeature
  * @see DefaultFeatureType
  */
-public class DefaultFeature implements Serializable {
+final class SparseFeature extends AbstractFeature {
     /**
      * For cross-version compatibility.
      */
-    private static final long serialVersionUID = 6594295132544357870L;
+    private static final long serialVersionUID = -4486200659005766093L;
 
     /**
      * A {@link #valuesKind} flag meaning that the {@link #properties} map contains raw values.
@@ -81,11 +60,6 @@ public class DefaultFeature implements S
     private static final byte CORRUPTED = 2;
 
     /**
-     * Information about the feature (name, characteristics, <i>etc.</i>).
-     */
-    private final DefaultFeatureType type;
-
-    /**
      * The properties (attributes, operations, feature associations) of this feature.
      *
      * Conceptually, values in this map are {@link Property} instances. However at first
we will store
@@ -112,75 +86,35 @@ public class DefaultFeature implements S
      *
      * @param type Information about the feature (name, characteristics, <i>etc.</i>).
      */
-    public DefaultFeature(final DefaultFeatureType type) {
-        ArgumentChecks.ensureNonNull("type", type);
-        this.type = type;
-        properties = new HashMap<>(Math.min(16, Containers.hashMapCapacity(type.getInstanceSize())));
-    }
-
-    /**
-     * Returns information about the feature (name, characteristics, <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.FeatureType}. This change is pending GeoAPI revision.</div>
-     *
-     * @return Information about the feature.
-     */
-    public DefaultFeatureType getType() {
-        return type;
-    }
-
-    /**
-     * Returns the type for the property of the given name.
-     *
-     * @param  name The property name.
-     * @return The type for the property of the given name (never {@code null}).
-     * @throws IllegalArgumentException If the given argument is not a property name of this
feature.
-     */
-    private PropertyType getPropertyType(final String name) throws IllegalArgumentException
{
-        final PropertyType pt = type.getProperty(name);
-        if (pt != null) {
-            return pt;
-        }
-        throw new IllegalArgumentException(Errors.format(Errors.Keys.PropertyNotFound_2,
type.getName(), name));
+    public SparseFeature(final DefaultFeatureType type) {
+        super(type);
+        properties = new HashMap<>();
     }
 
     /**
      * Returns the property (attribute, operation or association) of the given name.
      *
-     * <div class="warning"><b>Warning:</b> In a future SIS version, the
return type may be changed
-     * to {@code org.opengis.feature.Property}. This change is pending GeoAPI revision.</div>
-     *
      * @param  name The property name.
      * @return The property of the given name.
      * @throws IllegalArgumentException If the given argument is not a property name of this
feature.
      */
+    @Override
     public Object getProperty(final String name) throws IllegalArgumentException {
         ArgumentChecks.ensureNonNull("name", name);
         /*
          * Wraps values in Property objects for all entries in the properties map,
-         * if not already done. This operation is execute at most once per feature.
+         * if not already done. This operation is executed at most once per feature.
          */
         if (valuesKind != PROPERTIES) {
             if (!properties.isEmpty()) { // The map is typically empty when this method is
first invoked.
                 if (valuesKind != VALUES) {
-                    throw new CorruptedObjectException(String.valueOf(type.getName()));
+                    throw new CorruptedObjectException(String.valueOf(getName()));
                 }
                 valuesKind = CORRUPTED;
                 for (final Map.Entry<String, Object> entry : properties.entrySet())
{
-                    final String key      = entry.getKey();
-                    final Object value    = entry.getValue();
-                    final PropertyType pt = getPropertyType(key);
-                    final Property property;
-                    if (pt instanceof DefaultAttributeType<?>) {
-                        property = new DefaultAttribute<>((DefaultAttributeType<?>)
pt, value);
-                    } else if (pt instanceof DefaultAssociationRole) {
-                        property = new DefaultAssociation((DefaultAssociationRole) pt, (DefaultFeature)
value);
-                    } else {
-                        // Should never happen, unless the user gave us some mutable FeatureType.
-                        throw new IllegalStateException(Errors.format(Errors.Keys.UnknownType_1,
pt));
-                    }
-                    if (entry.setValue(property) != value) {
+                    final String key   = entry.getKey();
+                    final Object value = entry.getValue();
+                    if (entry.setValue(createProperty(key, value)) != value) {
                         throw new ConcurrentModificationException(key);
                     }
                 }
@@ -198,14 +132,7 @@ public class DefaultFeature implements S
         assert valuesKind == PROPERTIES : valuesKind;
         Property property = (Property) properties.get(name);
         if (property == null) {
-            final PropertyType pt = getPropertyType(name);
-            if (pt instanceof DefaultAttributeType<?>) {
-                property = new DefaultAttribute<>((DefaultAttributeType<?>) pt);
-            } else if (pt instanceof DefaultAssociationRole) {
-                property = new DefaultAssociation((DefaultAssociationRole) pt);
-            } else {
-                throw new IllegalArgumentException(unsupportedPropertyType(pt.getName()));
-            }
+            property = createProperty(name);
             replace(name, null, property);
         }
         return property;
@@ -213,101 +140,63 @@ public class DefaultFeature implements S
 
     /**
      * Returns the value for the property of the given name.
-     * This convenience method is equivalent to the following steps:
-     *
-     * <ul>
-     *   <li>Get the property of the given name.</li>
-     *   <li>Delegates to {@link DefaultAttribute#getValue()} or {@link DefaultAssociation#getValue()},
-     *       depending on the property type.
-     * </ul>
      *
      * @param  name The property name.
      * @return The value for the given property, or {@code null} if none.
      * @throws IllegalArgumentException If the given argument is not an attribute or association
name of this feature.
-     *
-     * @see DefaultAttribute#getValue()
      */
+    @Override
     public Object getPropertyValue(final String name) throws IllegalArgumentException {
         ArgumentChecks.ensureNonNull("name", name);
         final Object element = properties.get(name);
-        final GenericName unsupported;
         if (element != null) {
             if (valuesKind == VALUES) {
-                return element;
+                return element; // Most common case.
             } else if (element instanceof DefaultAttribute<?>) {
                 return ((DefaultAttribute<?>) element).getValue();
             } else if (element instanceof DefaultAssociation) {
                 return ((DefaultAssociation) element).getValue();
             } else if (valuesKind == PROPERTIES) {
-                unsupported = ((Property) element).getName();
+                throw new IllegalArgumentException(unsupportedPropertyType(((Property) element).getName()));
             } else {
-                throw new CorruptedObjectException(String.valueOf(type.getName()));
+                throw new CorruptedObjectException(String.valueOf(getName()));
             }
         } else if (properties.containsKey(name)) {
             return null; // Null has been explicitely set.
         } else {
-            final PropertyType pt = getPropertyType(name);
-            if (pt instanceof DefaultAttributeType<?>) {
-                return ((DefaultAttributeType<?>) pt).getDefaultValue();
-            } else if (pt instanceof DefaultAssociationRole) {
-                return null; // No default value for associations.
-            } else {
-                unsupported = pt.getName();
-            }
+            return getDefaultValue(name);
         }
-        // Happen if the property for the given name is an Operation or an unknown PropertyType.
-        throw new IllegalArgumentException(unsupportedPropertyType(unsupported));
     }
 
     /**
      * Sets the value for the property of the given name.
      *
-     * {@section Validation}
-     * The amount of validation performed by this method is implementation dependent.
-     * Usually, only the most basic constraints are verified. This is so for performance
reasons
-     * and also because some rules may be temporarily broken while constructing a feature.
-     * A more exhaustive verification can be performed by invoking the {@link #validate()}
method.
-     *
      * @param  name  The attribute name.
      * @param  value The new value for the given attribute (may be {@code null}).
      * @throws ClassCastException If the value is not assignable to the expected value class.
      * @throws IllegalArgumentException If the given value can not be assigned for an other
reason.
-     *
-     * @see DefaultAttribute#setValue(Object)
      */
+    @Override
     public void setPropertyValue(final String name, final Object value) throws IllegalArgumentException
{
         ArgumentChecks.ensureNonNull("name", name);
         if (valuesKind == VALUES) {
             final Object previous = properties.put(name, value);
             /*
-             * Slight optimisation: if we replaced a previous value of the same class, then
we can skip the
-             * checks for name and type validity since those checks has been done previously.
But if we add
+             * Slight optimisation:  if we replaced a previous value of the same class, then
we can skip the
+             * checks for name and type validity since those checks have been done previously.
But if we add
              * a new value or a value of a different type, then we need to check the name
and type validity.
              */
             if (previous == null || (value != null && previous.getClass() != value.getClass()))
{
-                final PropertyType pt = type.getProperty(name);
-                final Object illegalType = verifyType(pt, value);
-                if (illegalType != null) {
+                final RuntimeException e = verifyValueType(name, value);
+                if (e != null) {
                     replace(name, value, previous); // Restore the previous value.
-                    if (pt == null) {
-                        throw new IllegalArgumentException(Errors.format(
-                                Errors.Keys.PropertyNotFound_2, type.getName(), name));
-                    } else {
-                        throw new ClassCastException(Errors.format(
-                                Errors.Keys.IllegalPropertyClass_2, name, illegalType));
-                    }
+                    throw e;
                 }
             }
         } else if (valuesKind == PROPERTIES) {
-            final Property property = getPropertyInstance(name);
-            if (property instanceof DefaultAttribute<?>) {
-                setAttributeValue((DefaultAttribute<?>) property, value);
-            } else if (property instanceof DefaultAssociation) {
-                ArgumentChecks.ensureCanCast("value", DefaultFeature.class, value);
-                setAssociationValue((DefaultAssociation) property, (DefaultFeature) value);
-            } else {
-                throw new IllegalArgumentException(unsupportedPropertyType(property.getName()));
-            }
+            setPropertyValue(getPropertyInstance(name), value);
+        } else {
+            throw new CorruptedObjectException(String.valueOf(getName()));
         }
     }
 
@@ -325,129 +214,13 @@ public class DefaultFeature implements S
     }
 
     /**
-     * Returns {@code null} if the given type is an attribute type or association role,
-     * and if the given value is valid for that type or role. Otherwise returns the name
-     * of the property type for building an exception message.
-     */
-    private static Object verifyType(final PropertyType type, final Object value) {
-        if (type instanceof DefaultAttributeType<?>) {
-            if (value == null) {
-                return null;
-            }
-            if (((DefaultAttributeType<?>) type).getValueClass().isInstance(value))
{
-                return null;
-            }
-        } else if (type instanceof DefaultAssociationRole) {
-            if (value == null) {
-                return null;
-            }
-            if (value instanceof DefaultFeature) {
-                final DefaultFeatureType valueType = ((DefaultFeature) value).getType();
-                if (((DefaultAssociationRole) type).getValueType().maybeAssignableFrom(valueType))
{
-                    return null;
-                }
-                return String.valueOf(valueType.getName());
-            }
-        } else {
-            throw new IllegalArgumentException(unsupportedPropertyType(type.getName()));
-        }
-        return value.getClass();
-    }
-
-    /**
-     * Sets the attribute value after verification of its type. This method is invoked only
for checking
-     * that we are not violating the Java parameterized type contract. For a more exhaustive
validation,
-     * use {@link Validator} instead.
-     */
-    @SuppressWarnings("unchecked")
-    private static <T> void setAttributeValue(final DefaultAttribute<T> attribute,
final Object value) {
-        if (value != null) {
-            final DefaultAttributeType<T> pt = attribute.getType();
-            final Class<?> base = pt.getValueClass();
-            if (!base.isInstance(value)) {
-                throw new ClassCastException(Errors.format(Errors.Keys.IllegalPropertyClass_2,
-                        pt.getName(), value.getClass()));
-            }
-        }
-        ((DefaultAttribute) attribute).setValue(value);
-    }
-
-    /**
-     * Sets the association value after verification of its type.
-     * For a more exhaustive validation, use {@link Validator} instead.
-     */
-    private static <T> void setAssociationValue(final DefaultAssociation association,
final DefaultFeature value) {
-        if (value != null) {
-            final DefaultAssociationRole pt = association.getRole();
-            final DefaultFeatureType base = pt.getValueType();
-            final DefaultFeatureType actual = value.getType();
-            if (!base.maybeAssignableFrom(actual)) {
-                throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalPropertyClass_2,
-                        pt.getName(), actual.getName()));
-            }
-        }
-        association.setValue(value);
-    }
-
-    /**
-     * Returns the exception message for a property type which neither an attribute or an
association.
-     */
-    private static String unsupportedPropertyType(final GenericName name) {
-        return Errors.format(Errors.Keys.CanNotInstantiate_1, name);
-    }
-
-    /**
-     * Verifies if all current properties met the constraints defined by the feature type.
-     * This method returns {@linkplain org.apache.sis.metadata.iso.quality.DefaultDataQuality#getReports()
-     * reports} for all constraint violations found, if any.
-     *
-     * <div class="note"><b>Example:</b> given a feature with an attribute
named “population”.
-     * If this attribute is mandatory ([1 … 1] cardinality) but no value has been assigned
to it,
-     * then this {@code validate()} method will return the following data quality report:
-     *
-     * {@preformat text
-     *   Data quality
-     *     ├─Scope
-     *     │   └─Level…………………………………………………
Feature
-     *     └─Report
-     *         ├─Measure identification
-     *         │   └─Code…………………………………………
population
-     *         ├─Evaluation method type…… Direct internal
-     *         └─Result
-     *             ├─Explanation……………………… Missing value for
“population” property.
-     *             └─Pass………………………………………… false
-     * }
-     * </div>
-     *
-     * This feature is valid if this method does not report any
-     * {@linkplain org.apache.sis.metadata.iso.quality.DefaultConformanceResult conformance
result} having a
-     * {@linkplain org.apache.sis.metadata.iso.quality.DefaultConformanceResult#pass() pass}
value of {@code false}.
-     *
-     * @return Reports on all constraint violations found.
-     *
-     * @see DefaultAttribute#validate()
-     * @see DefaultAssociation#validate()
-     */
-    /*
-     * API NOTE: this method is final for now because if we allowed users to override it,
users would
-     * expect their method to be invoked by DefaultAssociation.validate(). But this is not
yet the case.
-     */
-    public final DataQuality validate() {
-        final Validator v = new Validator(ScopeCode.FEATURE);
-        for (final Map.Entry<String, Object> entry : properties.entrySet()) {
-            v.validateAny(getPropertyType(entry.getKey()), entry.getValue());
-        }
-        return v.quality;
-    }
-
-    /**
      * Returns a hash code value for this feature.
      *
      * @return A hash code value.
      */
     @Override
     public int hashCode() {
-        return type.hashCode() + 37 * properties.hashCode();
+        return super.hashCode() + 37 * properties.hashCode();
     }
 
     /**
@@ -460,23 +233,9 @@ public class DefaultFeature implements S
         if (obj == this) {
             return true;
         }
-        if (obj != null && obj.getClass() == getClass()) {
-            final DefaultFeature that = (DefaultFeature) obj;
-            return type.equals(that.type) &&
-                   properties.equals(that.properties);
+        if (super.equals(obj)) {
+            return properties.equals(((SparseFeature) obj).properties);
         }
         return false;
     }
-
-    /**
-     * Formats this feature in a tabular format.
-     *
-     * @return A string representation of this feature in a tabular format.
-     *
-     * @see FeatureFormat
-     */
-    @Override
-    public String toString() {
-        return FeatureFormat.sharedFormat(this);
-    }
 }

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Validator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Validator.java?rev=1595944&r1=1595943&r2=1595944&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Validator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Validator.java
[UTF-8] Mon May 19 16:01:13 2014
@@ -81,7 +81,7 @@ final class Validator {
             validate((DefaultAttributeType<?>) type, value);
         }
         if (type instanceof DefaultAssociationRole) {
-            validate((DefaultAssociationRole) type, (DefaultFeature) value);
+            validate((DefaultAssociationRole) type, (AbstractFeature) value);
         }
     }
 
@@ -106,7 +106,7 @@ final class Validator {
     /**
      * Verifies if the given value is valid for the given association role.
      */
-    void validate(final DefaultAssociationRole role, final DefaultFeature value) {
+    void validate(final DefaultAssociationRole role, final AbstractFeature value) {
         if (value != null) {
             final DefaultFeatureType type = value.getType();
             if (!role.getValueType().isAssignableFrom(type)) {

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java?rev=1595944&r1=1595943&r2=1595944&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java
[UTF-8] Mon May 19 16:01:13 2014
@@ -33,7 +33,7 @@
  *       {@link java.lang.Class} in the Java language. By extension, {@code AttributeType}
and {@code Operation} are
  *       equivalent to {@link java.lang.reflect.Field} and {@link java.lang.reflect.Method}
respectively.</div></li>
  *
- *   <li><p><b>{@linkplain org.apache.sis.feature.DefaultFeature Feature
instances}</b> (often called only Features)<br>
+ *   <li><p><b>{@linkplain org.apache.sis.feature.AbstractFeature Feature
instances}</b> (often called only Features)<br>
  *       Hold the <em>content</em> (or values) that describe one specific real-world
object.</p>
  *
  *       <div class="note"><b>Example:</b> the “Eiffel tower” is a
<em>feature instance</em> belonging
@@ -72,7 +72,7 @@
  * {@code      ├─} {@linkplain org.apache.sis.feature.DefaultAssociationRole  Feature
association role}<br>
  * {@code      └─} {@linkplain org.apache.sis.feature.DefaultOperation        Operation}<br>
  * </td><td class="sep" style="width: 50%; white-space: nowrap">
- *             {@linkplain org.apache.sis.feature.DefaultFeature     Feature}<br>
+ *             {@linkplain org.apache.sis.feature.AbstractFeature    Feature}<br>
  *                                                                   Property<br>
  * {@code  ├─} {@linkplain org.apache.sis.feature.DefaultAttribute   Attribute}<br>
  * {@code  └─} {@linkplain org.apache.sis.feature.DefaultAssociation Feature association}<br>

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java?rev=1595944&r1=1595943&r2=1595944&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
[UTF-8] Mon May 19 16:01:13 2014
@@ -34,7 +34,7 @@ import static org.apache.sis.test.Assert
  */
 @DependsOn({
     DefaultAssociationRoleTest.class,
-    DefaultFeatureTest.class
+    DenseFeatureTest.class
 })
 public final strictfp class DefaultAssociationTest extends TestCase {
     /**
@@ -44,7 +44,7 @@ public final strictfp class DefaultAssoc
      * and Le Mans, France in 836.” — source: Wikipedia</blockquote>
      */
     static DefaultAssociation twinTown() {
-        final DefaultFeature twinTown = new DefaultFeature(DefaultFeatureTypeTest.city());
+        final AbstractFeature twinTown = DefaultFeatureTypeTest.city().newInstance();
         twinTown.setPropertyValue("city", "Le Mans");
         twinTown.setPropertyValue("population", 143240); // In 2011.
         final DefaultAssociation association = new DefaultAssociation(DefaultAssociationRoleTest.twinTown());
@@ -59,8 +59,8 @@ public final strictfp class DefaultAssoc
     public void testWrongValue() {
         final DefaultAssociation association  = twinTown();
         final PropertyType       population   = association.getRole().getValueType().getProperty("population");
-        final DefaultFeature     otherFeature = new DefaultFeature(new DefaultFeatureType(
-                singletonMap(DefaultFeatureType.NAME_KEY, "Population"), false, null, population));
+        final AbstractFeature     otherFeature = new DefaultFeatureType(
+                singletonMap(DefaultFeatureType.NAME_KEY, "Population"), false, null, population).newInstance();
         try {
             association.setValue(otherFeature);
         } catch (IllegalArgumentException e) {

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java?rev=1595944&r1=1595943&r2=1595944&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] Mon May 19 16:01:13 2014
@@ -193,7 +193,7 @@ public final strictfp class DefaultFeatu
         assertFalse ("isAbstract",       simple.isAbstract());
         assertTrue  ("isSimple",         simple.isSimple());
         assertTrue  ("isAssignableFrom", simple.isAssignableFrom(simple));
-        assertEquals("instanceSize", 2,  simple.getInstanceSize());
+        assertEquals("instanceSize", 2,  simple.indices().size());
         assertPropertiesEquals(simple, false, "city", "population");
     }
 
@@ -240,7 +240,7 @@ public final strictfp class DefaultFeatu
         assertTrue  ("isAssignableFrom",                                complex.isAssignableFrom(complex));
         assertFalse ("isAbstract",                                      complex.isAbstract());
         assertEquals("isSimple",        maximumOccurs == minimumOccurs, complex.isSimple());
-        assertEquals("instanceSize",    maximumOccurs == 0 ? 2 : 3,     complex.getInstanceSize());
+        assertEquals("instanceSize",    maximumOccurs == 0 ? 2 : 3,     complex.indices().size());
         assertEquals("minimumOccurs",   minimumOccurs,                  festival.getMinimumOccurs());
         assertEquals("maximumOccurs",   maximumOccurs,                  festival.getMaximumOccurs());
         assertEquals("properties.size", 3,                              properties.size());
@@ -289,7 +289,7 @@ public final strictfp class DefaultFeatu
         assertEquals("superTypes",      city, getSingleton(capital.getSuperTypes()));
         assertFalse ("isAbstract",      capital.isAbstract());
         assertTrue  ("isSimple",        capital.isSimple());
-        assertEquals("instanceSize", 3, capital.getInstanceSize());
+        assertEquals("instanceSize", 3, capital.indices().size());
 
         assertPropertiesEquals(city,    false, "city", "population");
         assertPropertiesEquals(capital, false, "parliament");
@@ -323,7 +323,7 @@ public final strictfp class DefaultFeatu
         assertArrayEquals("superTypes", new Object[] {metropolis, capital}, metroCapital.getSuperTypes().toArray());
         assertFalse      ("isAbstract",      metroCapital.isAbstract());
         assertTrue       ("isSimple",        metroCapital.isSimple());
-        assertEquals     ("instanceSize", 6, metroCapital.getInstanceSize());
+        assertEquals     ("instanceSize", 6, metroCapital.indices().size());
 
         assertPropertiesEquals(metroCapital, false, "country");
         assertPropertiesEquals(metroCapital, true, "city", "population", "region", "isGlobal",
"parliament", "country");
@@ -364,7 +364,7 @@ public final strictfp class DefaultFeatu
         assertArrayEquals("superTypes", new Object[] {metropolis}, worldMetropolis.getSuperTypes().toArray());
         assertFalse      ("isAbstract",      worldMetropolis.isAbstract());
         assertTrue       ("isSimple",        worldMetropolis.isSimple());
-        assertEquals     ("instanceSize", 4, worldMetropolis.getInstanceSize());
+        assertEquals     ("instanceSize", 4, worldMetropolis.indices().size());
 
         assertPropertiesEquals(worldMetropolis, false, "region");
         assertPropertiesEquals(worldMetropolis, true, "city", "population", "region", "isGlobal");

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java?rev=1595944&r1=1595943&r2=1595944&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
[UTF-8] Mon May 19 16:01:13 2014
@@ -32,7 +32,7 @@ import static org.apache.sis.test.Assert
  * @version 0.5
  * @module
  */
-@DependsOn(DefaultFeatureTest.class)
+@DependsOn(DenseFeatureTest.class)
 public final strictfp class FeatureFormatTest extends TestCase {
     /**
      * Tests the formatting of a {@link DefaultFeatureType}.
@@ -54,11 +54,11 @@ public final strictfp class FeatureForma
     }
 
     /**
-     * Tests the formatting of a {@link DefaultFeature}.
+     * Tests the formatting of an {@link AbstractFeature}.
      */
     @Test
     public void testFeature() {
-        final DefaultFeature feature = DefaultFeatureTest.twinTown();
+        final AbstractFeature feature = FeatureTestCase.twinTown();
         final FeatureFormat format = new FeatureFormat(Locale.US, null);
         final String text = format.format(feature);
         assertMultilinesEquals("Twin town\n" +

Copied: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
(from r1595781, sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java?p2=sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java&p1=sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTest.java&r1=1595781&r2=1595944&rev=1595944&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
[UTF-8] Mon May 19 16:01:13 2014
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.feature;
 
-import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -25,34 +24,29 @@ import static java.util.Collections.sing
 
 
 /**
- * Tests {@link DefaultFeature}.
+ * Base class of {@link DenseFeatureTest} and {@link SparseFeatureTest}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
  * @version 0.5
  * @module
  */
-@DependsOn({
-    DefaultFeatureTypeTest.class,
-    DefaultAttributeTest.class,
-    PropertySingletonTest.class
-})
-public final strictfp class DefaultFeatureTest extends TestCase {
+strictfp class FeatureTestCase extends TestCase {
     /**
      * Creates a feature for twin towns.
      */
-    static DefaultFeature twinTown() {
+    static AbstractFeature twinTown() {
         final DefaultAssociationRole twinTown = DefaultAssociationRoleTest.twinTown();
         final DefaultFeatureType     city     = twinTown.getValueType();
         final DefaultFeatureType     type     = new DefaultFeatureType(
                 singletonMap(DefaultFeatureType.NAME_KEY, "Twin town"), false,
                 new DefaultFeatureType[] {city}, twinTown);
 
-        final DefaultFeature leMans = new DefaultFeature(type);
+        final AbstractFeature leMans = new DenseFeature(type);
         leMans.setPropertyValue("city", "Le Mans");
         leMans.setPropertyValue("population", 143240); // In 2011.
 
-        final DefaultFeature paderborn = new DefaultFeature(type);
+        final AbstractFeature paderborn = new DenseFeature(type);
         paderborn.setPropertyValue("city", "Paderborn");
         paderborn.setPropertyValue("population", 143174); // December 31th, 2011
         paderborn.setPropertyValue("twin town", leMans);
@@ -64,7 +58,7 @@ public final strictfp class DefaultFeatu
      */
     @Test
     public void testSimple() {
-        final DefaultFeature cityPopulation = new DefaultFeature(DefaultFeatureTypeTest.city());
+        final AbstractFeature cityPopulation = new DenseFeature(DefaultFeatureTypeTest.city());
 
         assertEquals("Utopia", cityPopulation.getPropertyValue("city"));
         cityPopulation.setPropertyValue("city", "Atlantide");

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java?rev=1595944&r1=1595943&r2=1595944&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
[UTF-8] Mon May 19 16:01:13 2014
@@ -34,7 +34,7 @@ import org.junit.BeforeClass;
     org.apache.sis.feature.DefaultFeatureTypeTest.class,
     org.apache.sis.feature.DefaultAttributeTest.class,
     org.apache.sis.feature.PropertySingletonTest.class,
-    org.apache.sis.feature.DefaultFeatureTest.class,
+    org.apache.sis.feature.DenseFeatureTest.class,
     org.apache.sis.feature.DefaultAssociationRoleTest.class,
     org.apache.sis.feature.DefaultAssociationTest.class,
     org.apache.sis.feature.DefaultOperationTest.class,

Modified: sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java?rev=1595944&r1=1595943&r2=1595944&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
[UTF-8] Mon May 19 16:01:13 2014
@@ -29,7 +29,7 @@ import com.esri.core.geometry.Polygon;
 import com.esri.core.geometry.Polyline;
 import com.esri.core.geometry.Geometry;
 
-import org.apache.sis.feature.DefaultFeature;
+import org.apache.sis.feature.AbstractFeature;
 import org.apache.sis.feature.DefaultFeatureType;
 import org.apache.sis.feature.DefaultAttributeType;
 import org.apache.sis.storage.DataStoreException;
@@ -74,7 +74,7 @@ public class ShapeFile {
     // reserve 4 bytes
 
     public ArrayList<FieldDescriptor> FDArray = new ArrayList<FieldDescriptor>();
-    public Map<Integer, DefaultFeature> FeatureMap = new HashMap<Integer, DefaultFeature>();
+    public Map<Integer, AbstractFeature> FeatureMap = new HashMap<Integer, AbstractFeature>();
 
 
 
@@ -156,7 +156,7 @@ public class ShapeFile {
             data = new byte[4];
             rf.order(ByteOrder.LITTLE_ENDIAN);
             int ShapeType = rf.getInt();
-            final DefaultFeature f = new DefaultFeature(featureType);
+            final AbstractFeature f = featureType.newInstance();
 
             if (ShapeType == ShapeTypeEnum.Point.getValue()) {
                 double x = rf.getDouble();



Mime
View raw message