You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2023/09/24 20:15:34 UTC

[sis] 03/03: Remove the boolean return value in WritableFeatureSet.removeIf(Predicate)

This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 6f65c2bacd120b81235735611fb0480383e9670e
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sat Sep 23 14:00:05 2023 +0200

    Remove the boolean return value in WritableFeatureSet.removeIf(Predicate)
    
    https://issues.apache.org/jira/browse/SIS-560
---
 .../org/apache/sis/storage/gpx/WritableStore.java  |  7 ++++---
 .../sis/storage/xml/stream/RewriteOnUpdate.java    | 22 +++++-----------------
 .../org/apache/sis/storage/gpx/UpdaterTest.java    |  4 +---
 .../org/apache/sis/storage/WritableFeatureSet.java | 14 ++------------
 4 files changed, 12 insertions(+), 35 deletions(-)

diff --git a/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/gpx/WritableStore.java b/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/gpx/WritableStore.java
index a04fc2742e..2fd3599554 100644
--- a/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/gpx/WritableStore.java
+++ b/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/gpx/WritableStore.java
@@ -40,7 +40,7 @@ import org.opengis.feature.FeatureType;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.3
+ * @version 1.4
  * @since   1.3
  */
 public final class WritableStore extends Store implements WritableFeatureSet {
@@ -95,9 +95,10 @@ public final class WritableStore extends Store implements WritableFeatureSet {
      * @throws DataStoreException if the feature stream cannot be obtained or updated.
      */
     @Override
-    public synchronized boolean removeIf(final Predicate<? super Feature> filter) throws DataStoreException {
+    public synchronized void removeIf(final Predicate<? super Feature> filter) throws DataStoreException {
         try (Updater updater = updater()) {
-            return updater.removeIf(filter);
+            updater.removeIf(filter);
+            updater.flush();
         }
     }
 
diff --git a/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/xml/stream/RewriteOnUpdate.java b/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/xml/stream/RewriteOnUpdate.java
index cf1e77ac84..60ba5e50a4 100644
--- a/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/xml/stream/RewriteOnUpdate.java
+++ b/endorsed/src/org.apache.sis.storage.xml/main/org/apache/sis/storage/xml/stream/RewriteOnUpdate.java
@@ -161,29 +161,17 @@ public abstract class RewriteOnUpdate implements AutoCloseable {
      * Removes all feature instances from the {@code FeatureSet} which matches the given predicate.
      *
      * @param  filter  a predicate which returns {@code true} for feature instances to be removed.
-     * @return {@code true} if any elements were removed.
      * @throws DataStoreException if the feature stream cannot be obtained or updated.
      */
-    public boolean removeIf(final Predicate<? super Feature> filter) throws DataStoreException {
+    public void removeIf(final Predicate<? super Feature> filter) throws DataStoreException {
         ArgumentChecks.ensureNonNull("filter", filter);
-        if (isEmpty()) {
-            return false;
+        if (!isEmpty()) {
+            filtered = filtered().filter((feature) -> {
+                return !filter.test(feature);
+            });
         }
-        filtered = filtered().filter((feature) -> {
-            boolean r = filter.test(feature);
-            if (r) modified = true;
-            return !r;
-        });
-        modified = false;
-        flush();            // Need immediate execution for getting the boolean value.
-        return modified;
     }
 
-    /**
-     * A flag telling whether {@link #removeIf(Predicate)} removed at least one feature.
-     */
-    private boolean modified;
-
     /**
      * Updates all feature instances from the {@code FeatureSet} which match the given predicate.
      * If the given operator returns {@code null}, then the filtered feature is removed.
diff --git a/endorsed/src/org.apache.sis.storage.xml/test/org/apache/sis/storage/gpx/UpdaterTest.java b/endorsed/src/org.apache.sis.storage.xml/test/org/apache/sis/storage/gpx/UpdaterTest.java
index 7d7f9c4ff1..d15c85c75a 100644
--- a/endorsed/src/org.apache.sis.storage.xml/test/org/apache/sis/storage/gpx/UpdaterTest.java
+++ b/endorsed/src/org.apache.sis.storage.xml/test/org/apache/sis/storage/gpx/UpdaterTest.java
@@ -165,14 +165,12 @@ public final class UpdaterTest extends TestCase {
             Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
         }
         assertTrue(containsLat20());
-        final boolean result;
         try (final WritableStore store = create()) {
-            result = store.removeIf((feature) -> {
+            store.removeIf((feature) -> {
                 Object point = feature.getPropertyValue("sis:geometry");
                 return ((Point) point).getY() == 20;
             });
         }
-        assertTrue(result);
         assertFalse(containsLat20());
     }
 
diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/WritableFeatureSet.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/WritableFeatureSet.java
index c6641cc256..14820d87da 100644
--- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/WritableFeatureSet.java
+++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/WritableFeatureSet.java
@@ -32,7 +32,7 @@ import org.opengis.feature.FeatureType;
  * or {@linkplain #replaceIf(Predicate, UnaryOperator) replace} feature instances.
  *
  * @author  Johann Sorel (Geomatys)
- * @version 1.0
+ * @version 1.4
  * @since   1.0
  */
 public interface WritableFeatureSet extends FeatureSet {
@@ -80,21 +80,11 @@ public interface WritableFeatureSet extends FeatureSet {
     /**
      * Removes all feature instances from this {@code FeatureSet} which matches the given predicate.
      *
-     * <div class="warning"><b>Possible API change:</b>
-     * The {@code boolean} return type may be removed in a future version.
-     * It currently exists for compatibility with the {@link java.util.Collection#removeIf(Predicate)} method
-     * if an implementation chooses to implements {@code WritableFeatureSet} and {@link java.util.Collection}
-     * in same time. But this is not recommended, and the current method signature is a blocker for deferred
-     * method execution. Telling if there is any feature to remove requires immediate execution of the filter,
-     * while an implementation may want to wait in case the filtering can be combined with other operations
-     * such as {@code add(…)} or {@code replaceIf(…)}.
-     * See <a href="https://issues.apache.org/jira/browse/SIS-560">SIS-560 on issue tracker</a>.</div>
-     *
      * @param  filter  a predicate which returns {@code true} for feature instances to be removed.
      * @return {@code true} if any elements were removed.
      * @throws DataStoreException if an error occurred while removing features.
      */
-    boolean removeIf(Predicate<? super Feature> filter) throws DataStoreException;
+    void removeIf(Predicate<? super Feature> filter) throws DataStoreException;
 
     /**
      * Updates all feature instances from this {@code FeatureSet} which match the given predicate.