sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject svn commit: r1807353 - in /sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis: internal/storage/ storage/
Date Tue, 05 Sep 2017 14:19:26 GMT
Author: jsorel
Date: Tue Sep  5 14:19:26 2017
New Revision: 1807353

URL: http://svn.apache.org/viewvc?rev=1807353&view=rev
Log:
FeatureSet : add writing operations add, removeIf and replaceIf

Added:
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ReadOnlyDataStoreException.java
Modified:
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.properties
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources_fr.properties
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.java?rev=1807353&r1=1807352&r2=1807353&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.java
[UTF-8] Tue Sep  5 14:19:26 2017
@@ -164,6 +164,11 @@ public final class Resources extends Ind
         public static final short ShallBeDeclaredBefore_2 = 22;
 
         /**
+         * Writing operations not supported.
+         */
+        public static final short StoreIsReadOnly = 28;
+
+        /**
          * Can not move backward in the “{0}” stream.
          */
         public static final short StreamIsForwardOnly_1 = 13;

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.properties?rev=1807353&r1=1807352&r2=1807353&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources.properties
[ISO-8859-1] Tue Sep  5 14:19:26 2017
@@ -46,3 +46,4 @@ StreamIsReadOnce_1                = The
 StreamIsWriteOnce_1               = Can not modify previously written data in \u201c{0}\u201d.
 UndefinedParameter_2              = Can not open {0} data store without \u201c{1}\u201d parameter.
 UnknownFormatFor_1                = Format of \u201c{0}\u201d is not recognized.
+StoreIsReadOnly                   = Writing operations not supported.

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources_fr.properties?rev=1807353&r1=1807352&r2=1807353&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/Resources_fr.properties
[ISO-8859-1] Tue Sep  5 14:19:26 2017
@@ -51,3 +51,4 @@ StreamIsReadOnce_1                = Les
 StreamIsWriteOnce_1               = Ne peut pas revenir sur les donn\u00e9es d\u00e9j\u00e0
\u00e9crites dans \u00ab\u202f{0}\u202f\u00bb.
 UndefinedParameter_2              = Ne peut pas ouvrir une source de donn\u00e9es {0} sans
le param\u00e8tre \u00ab\u202f{1}\u202f\u00bb.
 UnknownFormatFor_1                = Le format de \u00ab\u202f{0}\u202f\u00bb n\u2019est pas
reconnu.
+StoreIsReadOnly                   = Les op\u00e9rations d'\u00e9criture ne sont pas support\u00e9es.

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=1807353&r1=1807352&r2=1807353&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] Tue Sep  5 14:19:26 2017
@@ -17,7 +17,11 @@
 package org.apache.sis.storage;
 
 // Branch-dependent imports
+import java.util.Iterator;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
 import java.util.stream.Stream;
+import org.apache.sis.internal.storage.Resources;
 import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;
 
@@ -101,4 +105,54 @@ public interface FeatureSet extends Data
      * @throws DataStoreException if an error occurred while creating the stream.
      */
     Stream<Feature> features(boolean parallel) throws DataStoreException;
+
+    /**
+     * Insert new features in the {@link FeatureSet}.
+     * Any feature already present in the {@link FeatureSet} will remain unmodified.
+     *
+     * <p>The method expect an {@link Iterator} rather then a Stream to ease the user
+     * mapping work with various API. Implementing a custom {@link Iterator} require
+     * considerably less efforts then a {@link Stream}. On the other side if the user
+     * has a {@link Stream}, obtaining an {@link Iterator} can be done by a single
+     * call to {@link Stream#iterator() }.</p>
+     *
+     * @param features features to append in the {@link FeatureSet}
+     * @throws DataStoreException if an error occurred while storing new features.
+     */
+    default void add(Iterator<? extends Feature> features) throws DataStoreException
{
+        throw new ReadOnlyDataStoreException(null,Resources.Keys.StoreIsReadOnly);
+    }
+
+    /**
+     * Remove all {@link Feature} from the {@link FeatureSet} which match
+     * the given predicate.
+     *
+     * @param predicate matching predicate
+     * @throws DataStoreException if an error occurred while removing features.
+     */
+    default void removeIf(Predicate<? extends Feature> predicate) throws DataStoreException
{
+        throw new ReadOnlyDataStoreException(null,Resources.Keys.StoreIsReadOnly);
+    }
+
+    /**
+     * Update all {@link Feature} from the {@link FeatureSet} which match
+     * the given predicate.
+     *
+     * <p>For each {@link Feature} matching the {@link Predicate} the {@link UnaryOperator}
+     * will be called. Two behaviors are possible.</p>
+     * <ul>
+     *  <li>If it returns the {@link Feature}, then the updated feature is store with
+     *  all the modifications.</li>
+     *  <li> If it returns a null, then the feature will be removed from the
+     *  {@link FeatureSet}.</li>
+     * </ul>
+     *
+     * @param predicate matching predicate
+     * @param updater operation called for each matching {@link Feature}
+     * @throws DataStoreException
+     */
+    default void replaceIf(Predicate<? extends Feature> predicate, UnaryOperator<Feature>
updater) throws DataStoreException {
+        throw new ReadOnlyDataStoreException(null,Resources.Keys.StoreIsReadOnly);
+    }
+
 }

Added: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ReadOnlyDataStoreException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ReadOnlyDataStoreException.java?rev=1807353&view=auto
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ReadOnlyDataStoreException.java
(added)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/ReadOnlyDataStoreException.java
Tue Sep  5 14:19:26 2017
@@ -0,0 +1,77 @@
+/*
+ * 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.storage;
+
+import java.util.Locale;
+
+/**
+ * Thrown when a writing operation on a {@code DataStore} is not supported.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+public class ReadOnlyDataStoreException extends DataStoreException {
+
+    private static final long serialVersionUID = 5710116172772560023L;
+
+    /**
+     * Creates an exception with no cause and no details message.
+     */
+    public ReadOnlyDataStoreException() {
+    }
+
+    /**
+     * Creates an exception with the specified details message.
+     *
+     * @param message  the detail message.
+     */
+    public ReadOnlyDataStoreException(final String message) {
+        super(message);
+    }
+
+    /**
+     * Creates an exception with the specified cause and no details message.
+     *
+     * @param cause  the cause for this exception.
+     */
+    public ReadOnlyDataStoreException(final Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Creates an exception with the specified details message and cause.
+     *
+     * @param message  the detail message.
+     * @param cause    the cause for this exception.
+     */
+    public ReadOnlyDataStoreException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Creates a new exception which will format a localized message in the given locale.
+     *
+     * @param locale      the locale for the message to be returned by {@link #getLocalizedMessage()}.
+     * @param key         one of {@link org.apache.sis.internal.storage.Resources.Keys} constants.
+     * @param parameters  parameters to use for formatting the messages.
+     */
+    ReadOnlyDataStoreException(final Locale locale, final short key, final Object... parameters)
{
+        super(locale, key, parameters);
+    }
+}



Mime
View raw message