Author: desruisseaux
Date: Sat May  5 11:54:07 2018
New Revision: 1830965

URL: http://svn.apache.org/viewvc?rev=1830965&view=rev
Log:
Rename ArrayFeatureSet as MemoryFeatureSet, add javadoc and move some 
implementation to super-class.

Added:
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryFeatureSet.java
      - copied, changed from r1830964, 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ArrayFeatureSet.java
Removed:
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ArrayFeatureSet.java
Modified:
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/JoinFeatureSet.java
    
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
    
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/JoinFeatureSetTest.java
    
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/SimpleQueryTest.java

Modified: 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java?rev=1830965&r1=1830964&r2=1830965&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractFeatureSet.java
 [UTF-8] Sat May  5 11:54:07 2018
@@ -17,15 +17,20 @@
 package org.apache.sis.internal.storage;
 
 import org.apache.sis.storage.DataStore;
+import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.FeatureSet;
+import org.apache.sis.storage.Query;
+import org.apache.sis.storage.UnsupportedQueryException;
+import org.apache.sis.internal.storage.query.SimpleQuery;
 import org.apache.sis.util.logging.WarningListeners;
 
 
 /**
  * Base implementation of feature sets contained in data stores.
  *
+ * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.8
  * @module
  */
@@ -33,9 +38,29 @@ public abstract class AbstractFeatureSet
     /**
      * Creates a new resource.
      *
-     * @param listeners  the set of registered warning listeners for the data 
store.
+     * @param listeners  the set of registered warning listeners for the data 
store, or {@code null} if none.
      */
     protected AbstractFeatureSet(final WarningListeners<DataStore> listeners) {
         super(listeners);
     }
+
+    /**
+     * Requests a subset of features and/or feature properties from this 
resource.
+     * The default implementation try to execute the queries by filtering the
+     * {@linkplain #features(boolean) stream of features}, which may be 
inefficient.
+     * Subclasses are encouraged to override.
+     *
+     * @param  query  definition of feature and feature properties filtering 
applied at reading time.
+     * @return resulting subset of features (never {@code null}).
+     * @throws UnsupportedQueryException if this {@code FeatureSet} can not 
execute the given query.
+     * @throws DataStoreException if another error occurred while processing 
the query.
+     */
+    @Override
+    public FeatureSet subset(final Query query) throws DataStoreException {
+        if (query instanceof SimpleQuery) {
+            return SimpleQuery.executeOnCPU(this, (SimpleQuery) query);
+        } else {
+            return FeatureSet.super.subset(query);
+        }
+    }
 }

Modified: 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java?rev=1830965&r1=1830964&r2=1830965&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractResource.java
 [UTF-8] Sat May  5 11:54:07 2018
@@ -43,14 +43,14 @@ import org.apache.sis.storage.event.Chan
  */
 public abstract class AbstractResource implements Resource, Localized {
     /**
-     * The set of registered warning listeners for the data store.
+     * The set of registered warning listeners for the data store, or {@code 
null} if none.
      */
     protected final WarningListeners<DataStore> listeners;
 
     /**
      * Creates a new resource.
      *
-     * @param listeners  the set of registered warning listeners for the data 
store.
+     * @param listeners  the set of registered warning listeners for the data 
store, or {@code null} if none.
      */
     protected AbstractResource(final WarningListeners<DataStore> listeners) {
         this.listeners = listeners;

Modified: 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/JoinFeatureSet.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/JoinFeatureSet.java?rev=1830965&r1=1830964&r2=1830965&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/JoinFeatureSet.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/JoinFeatureSet.java
 [UTF-8] Sat May  5 11:54:07 2018
@@ -34,8 +34,6 @@ import org.apache.sis.referencing.NamedI
 import org.apache.sis.storage.DataStore;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.FeatureSet;
-import org.apache.sis.storage.Query;
-import org.apache.sis.storage.UnsupportedQueryException;
 import org.apache.sis.util.collection.BackingStoreException;
 import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.util.logging.WarningListeners;
@@ -187,14 +185,6 @@ public class JoinFeatureSet extends Abst
     }
 
     @Override
-    public FeatureSet subset(Query query) throws UnsupportedQueryException, 
DataStoreException {
-        if (query instanceof SimpleQuery) {
-            return SimpleQuery.executeOnCPU(this, (SimpleQuery) query);
-        }
-        return FeatureSet.super.subset(query);
-    }
-
-    @Override
     public Stream<Feature> features(boolean parallel) throws 
DataStoreException {
         final JoinIterator ite;
         switch (joinType) {

Copied: 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryFeatureSet.java
 (from r1830964, 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ArrayFeatureSet.java)
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryFeatureSet.java?p2=sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryFeatureSet.java&p1=sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ArrayFeatureSet.java&r1=1830964&r2=1830965&rev=1830965&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ArrayFeatureSet.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryFeatureSet.java
 [UTF-8] Sat May  5 11:54:07 2018
@@ -17,94 +17,105 @@
 package org.apache.sis.internal.storage;
 
 import java.util.Collection;
-import java.util.Collections;
 import java.util.stream.Stream;
-import org.apache.sis.internal.storage.query.SimpleQuery;
 import org.apache.sis.metadata.iso.DefaultMetadata;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.metadata.iso.identification.DefaultDataIdentification;
 import org.apache.sis.referencing.NamedIdentifier;
 import org.apache.sis.storage.DataStore;
-import org.apache.sis.storage.DataStoreException;
-import org.apache.sis.storage.FeatureSet;
-import org.apache.sis.storage.Query;
-import org.apache.sis.storage.UnsupportedQueryException;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.logging.WarningListeners;
 import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;
 import org.opengis.metadata.Metadata;
 
+
 /**
- * FeatureSet implementation stored in memory.
- *
- * <p>
- * Note-1 : This implementation is read-only for now but will become writable.
- * </p>
- * <p>
- * Note-2 : this class is experimental.
- * </p>
+ * Set of features stored in memory.
+ * Metadata and features are specified at construction time.
  *
- * @author Johann Sorel (Geomatys)
+ * @author  Johann Sorel (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
  */
-public final class ArrayFeatureSet extends AbstractFeatureSet implements 
FeatureSet {
-
+public final class MemoryFeatureSet extends AbstractFeatureSet {
+    /**
+     * The metadata to be returned by {@link #getMetadata()}.
+     */
     private final Metadata metadata;
+
+    /**
+     * The type specified at construction time and returned by {@link 
#getType()}.
+     */
     private final FeatureType type;
+
+    /**
+     * The features specified at construction time, potentially as a 
modifiable collection.
+     * For all features in this collection, {@link Feature#getType()} shall be 
{@link #type}.
+     */
     private final Collection<Feature> features;
 
     /**
-     * Creates a new feature set in memory.
+     * Creates a new set of features stored in memory. It is caller 
responsibility to ensure that
+     * <code>{@linkplain Feature#getType()} == type</code> for all elements in 
the given collection
+     * (this is not verified).
      *
-     * @param listeners the set of registered warning listeners for the data 
store.
-     * @param type stored features type.
-     * @param features collection of stored features, this collection will not 
be copied.
-     * @param metadata can be null
+     * @param listeners  the set of registered warning listeners for the data 
store, or {@code null} if none.
+     * @param metadata   information about this resource, or {@code null} for 
inferring default metadata.
+     * @param type       the type of all features in the given collection.
+     * @param features   collection of stored features. This collection will 
not be copied.
      */
-    public ArrayFeatureSet(final WarningListeners<DataStore> listeners, 
FeatureType type, Collection<Feature> features, Metadata metadata) {
+    public MemoryFeatureSet(final WarningListeners<DataStore> listeners, 
Metadata metadata,
+                            final FeatureType type, final Collection<Feature> 
features)
+    {
         super(listeners);
-        ArgumentChecks.ensureNonNull("type", type);
-        ArgumentChecks.ensureNonNull("features", type);
-        this.type = type;
+        ArgumentChecks.ensureNonNull("type",     type);
+        ArgumentChecks.ensureNonNull("features", features);
+        this.type     = type;
         this.features = features;
-
         if (metadata == null) {
             final DefaultDataIdentification identification = new 
DefaultDataIdentification();
-            final NamedIdentifier identifier = new 
NamedIdentifier(type.getName());
             final DefaultCitation citation = new 
DefaultCitation(type.getName().toString());
-            citation.setIdentifiers(Collections.singleton(identifier));
+            citation.getIdentifiers().add(new NamedIdentifier(type.getName()));
             identification.setCitation(citation);
 
-            final DefaultMetadata md = new DefaultMetadata();
-            md.setIdentificationInfo(Collections.singleton(identification));
+            final DefaultMetadata md = new DefaultMetadata(null, null, 
identification);
             md.freeze();
             metadata = md;
         }
-
         this.metadata = metadata;
     }
 
+    /**
+     * Returns the metadata given or inferred at construction time.
+     *
+     * @return information about this resource.
+     */
     @Override
-    public FeatureType getType() throws DataStoreException {
-        return type;
-    }
-
-    @Override
-    public Metadata getMetadata() throws DataStoreException {
+    public Metadata getMetadata() {
         return metadata;
     }
 
+    /**
+     * Returns the type common to all feature instances in this set.
+     *
+     * @return a description of properties that are common to all features in 
this dataset.
+     */
     @Override
-    public Stream<Feature> features(boolean bln) throws DataStoreException {
-        return bln ? features.parallelStream() : features.stream();
+    public FeatureType getType() {
+        return type;
     }
 
+    /**
+     * Returns a stream of all features contained in this dataset.
+     *
+     * @param  parallel  {@code true} for a parallel stream (if supported), or 
{@code false} for a sequential stream.
+     * @return all features contained in this dataset.
+     */
     @Override
-    public FeatureSet subset(Query query) throws UnsupportedQueryException, 
DataStoreException {
-        if (query instanceof SimpleQuery) {
-            return SimpleQuery.executeOnCPU(this, (SimpleQuery) query);
-        }
-        return FeatureSet.super.subset(query);
+    public Stream<Feature> features(final boolean parallel) {
+        return parallel ? features.parallelStream() : features.stream();
     }
-
 }

Modified: 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java?rev=1830965&r1=1830964&r2=1830965&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
 [UTF-8] Sat May  5 11:54:07 2018
@@ -17,6 +17,7 @@
 package org.apache.sis.storage;
 
 import java.util.stream.Stream;
+import org.apache.sis.util.ArgumentChecks;
 
 // Branch-dependent imports
 import org.opengis.feature.Feature;
@@ -71,7 +72,7 @@ public interface FeatureSet extends Data
     FeatureType getType() throws DataStoreException;
 
     /**
-     * Requests a subset of features and feature properties from this resource.
+     * Requests a subset of features and/or feature properties from this 
resource.
      * The filtering can be applied in two domains:
      *
      * <ul>
@@ -101,6 +102,7 @@ public interface FeatureSet extends Data
      * @throws DataStoreException if another error occurred while processing 
the query.
      */
     default FeatureSet subset(Query query) throws UnsupportedQueryException, 
DataStoreException {
+        ArgumentChecks.ensureNonNull("query", query);
         throw new UnsupportedQueryException();
     }
 

Modified: 
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/JoinFeatureSetTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/JoinFeatureSetTest.java?rev=1830965&r1=1830964&r2=1830965&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/JoinFeatureSetTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/JoinFeatureSetTest.java
 [UTF-8] Sat May  5 11:54:07 2018
@@ -113,7 +113,7 @@ public class JoinFeatureSetTest extends
         fid_1_4 = getId(sf);
         features1.add(sf);
 
-        featureSet1 = new ArrayFeatureSet(null, sft1, features1, null);
+        featureSet1 = new MemoryFeatureSet(null, null, sft1, features1);
 
 
         
//----------------------------------------------------------------------
@@ -169,7 +169,7 @@ public class JoinFeatureSetTest extends
         fid_2_5 = getId(sf);
         features2.add(sf);
 
-        featureSet2 = new ArrayFeatureSet(null, sft2, features2, null);
+        featureSet2 = new MemoryFeatureSet(null, null, sft2, features2);
 
     }
 

Modified: 
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/SimpleQueryTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/SimpleQueryTest.java?rev=1830965&r1=1830964&r2=1830965&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/SimpleQueryTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/SimpleQueryTest.java
 [UTF-8] Sat May  5 11:54:07 2018
@@ -23,7 +23,7 @@ import org.apache.sis.filter.DefaultLite
 import org.apache.sis.filter.DefaultPropertyIsEqualTo;
 import org.apache.sis.filter.DefaultPropertyName;
 import org.apache.sis.filter.DefaultSortBy;
-import org.apache.sis.internal.storage.ArrayFeatureSet;
+import org.apache.sis.internal.storage.MemoryFeatureSet;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.FeatureSet;
 import org.apache.sis.test.TestCase;
@@ -73,7 +73,7 @@ public class SimpleQueryTest extends Tes
         f5.setPropertyValue("value2", 1);
 
         FEATURES = new Feature[]{f1,f2,f3,f4,f5};
-        FEATURESET = new ArrayFeatureSet(null, TYPE, Arrays.asList(FEATURES), 
null);
+        FEATURESET = new MemoryFeatureSet(null, null, TYPE, 
Arrays.asList(FEATURES));
     }
 
     /**


Reply via email to