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

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/master by this push:
     new 7cbed68c71 [SYNCOPE-1924] Fix methods in PropagationByResource (#1217)
7cbed68c71 is described below

commit 7cbed68c712aa7112626ac410f5b83e3068a1474
Author: Matteo Tatoni <[email protected]>
AuthorDate: Tue Oct 28 08:23:59 2025 +0100

    [SYNCOPE-1924] Fix methods in PropagationByResource (#1217)
---
 .../provisioning/api/PropagationByResource.java    | 147 ++++++---------------
 .../api/PropagationByResourceTest.java             |  29 +++-
 2 files changed, 66 insertions(+), 110 deletions(-)

diff --git 
a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/PropagationByResource.java
 
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/PropagationByResource.java
index f2141a068e..c5b88ac10e 100644
--- 
a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/PropagationByResource.java
+++ 
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/PropagationByResource.java
@@ -87,21 +87,11 @@ public class PropagationByResource<T extends Serializable> 
implements Serializab
      * @return whether the operation was successful or not
      */
     public final boolean add(final ResourceOperation type, final T key) {
-        Set<T> set;
-        switch (type) {
-            case CREATE:
-                set = toBeCreated;
-                break;
-
-            case UPDATE:
-                set = toBeUpdated;
-                break;
-
-            case DELETE:
-            default:
-                set = toBeDeleted;
-                break;
-        }
+        Set<T> set = switch (type) {
+            case CREATE -> toBeCreated;
+            case UPDATE -> toBeUpdated;
+            default -> toBeDeleted;
+        };
 
         return set.add(key);
     }
@@ -114,21 +104,11 @@ public class PropagationByResource<T extends 
Serializable> implements Serializab
      * @return whether the operation was successful or not
      */
     public boolean addAll(final ResourceOperation type, final Collection<T> 
keys) {
-        Set<T> set;
-        switch (type) {
-            case CREATE:
-                set = toBeCreated;
-                break;
-
-            case UPDATE:
-                set = toBeUpdated;
-                break;
-
-            case DELETE:
-            default:
-                set = toBeDeleted;
-                break;
-        }
+        Set<T> set = switch (type) {
+            case CREATE -> toBeCreated;
+            case UPDATE -> toBeUpdated;
+            default -> toBeDeleted;
+        };
 
         return set.addAll(keys);
     }
@@ -141,25 +121,12 @@ public class PropagationByResource<T extends 
Serializable> implements Serializab
      * @return whether the operation was successful or not
      */
     public final boolean remove(final ResourceOperation type, final T key) {
-        boolean result = false;
-
-        switch (type) {
-            case CREATE:
-                result = toBeCreated.remove(key);
-                break;
-
-            case UPDATE:
-                result = toBeUpdated.remove(key);
-                break;
-
-            case DELETE:
-                result = toBeDeleted.remove(key);
-                break;
-
-            default:
-        }
-
-        return result;
+        return switch (type) {
+            case CREATE -> toBeCreated.remove(key);
+            case UPDATE -> toBeUpdated.remove(key);
+            case DELETE -> toBeDeleted.remove(key);
+            default -> false;
+        };
     }
 
     /**
@@ -170,21 +137,11 @@ public class PropagationByResource<T extends 
Serializable> implements Serializab
      * @return whether the operation was successful or not
      */
     public boolean removeAll(final ResourceOperation type, final Set<T> keys) {
-        Set<T> set;
-        switch (type) {
-            case CREATE:
-                set = toBeCreated;
-                break;
-
-            case UPDATE:
-                set = toBeUpdated;
-                break;
-
-            case DELETE:
-            default:
-                set = toBeDeleted;
-                break;
-        }
+        Set<T> set = switch (type) {
+            case CREATE -> toBeCreated;
+            case UPDATE -> toBeUpdated;
+            default -> toBeDeleted;
+        };
 
         return set.removeAll(keys);
     }
@@ -198,8 +155,8 @@ public class PropagationByResource<T extends Serializable> 
implements Serializab
      */
     public boolean removeAll(final Collection<T> keys) {
         return toBeCreated.removeAll(keys)
-                || toBeUpdated.removeAll(keys)
-                || toBeDeleted.removeAll(keys);
+                | toBeUpdated.removeAll(keys)
+                | toBeDeleted.removeAll(keys);
     }
 
     /**
@@ -211,8 +168,8 @@ public class PropagationByResource<T extends Serializable> 
implements Serializab
      */
     public boolean removeIf(final Predicate<? super T> filter) {
         return toBeCreated.removeIf(filter)
-                || toBeUpdated.removeIf(filter)
-                || toBeDeleted.removeIf(filter);
+                | toBeUpdated.removeIf(filter)
+                | toBeDeleted.removeIf(filter);
     }
 
     /**
@@ -225,30 +182,17 @@ public class PropagationByResource<T extends 
Serializable> implements Serializab
      */
     public boolean retainAll(final Collection<T> keys) {
         return toBeCreated.retainAll(keys)
-                || toBeUpdated.retainAll(keys)
-                || toBeDeleted.retainAll(keys);
+                | toBeUpdated.retainAll(keys)
+                | toBeDeleted.retainAll(keys);
     }
 
     public boolean contains(final ResourceOperation type, final T key) {
-        boolean result = false;
-
-        switch (type) {
-            case CREATE:
-                result = toBeCreated.contains(key);
-                break;
-
-            case UPDATE:
-                result = toBeUpdated.contains(key);
-                break;
-
-            case DELETE:
-                result = toBeDeleted.contains(key);
-                break;
-
-            default:
-        }
-
-        return result;
+        return switch (type) {
+            case CREATE -> toBeCreated.contains(key);
+            case UPDATE -> toBeUpdated.contains(key);
+            case DELETE -> toBeDeleted.contains(key);
+            default -> false;
+        };
     }
 
     public boolean contains(final T key) {
@@ -264,25 +208,12 @@ public class PropagationByResource<T extends 
Serializable> implements Serializab
      * @return resource matching the given type
      */
     public final Set<T> get(final ResourceOperation type) {
-        Set<T> result = Set.of();
-
-        switch (type) {
-            case CREATE:
-                result = toBeCreated;
-                break;
-
-            case UPDATE:
-                result = toBeUpdated;
-                break;
-
-            case DELETE:
-                result = toBeDeleted;
-                break;
-
-            default:
-        }
-
-        return result;
+        return switch (type) {
+            case CREATE -> toBeCreated;
+            case UPDATE -> toBeUpdated;
+            case DELETE -> toBeDeleted;
+            default -> Set.of();
+        };
     }
 
     public Map<T, ResourceOperation> asMap() {
diff --git 
a/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/PropagationByResourceTest.java
 
b/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/PropagationByResourceTest.java
index 4723ab9558..fbe38200ed 100644
--- 
a/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/PropagationByResourceTest.java
+++ 
b/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/PropagationByResourceTest.java
@@ -116,13 +116,38 @@ public class PropagationByResourceTest extends 
AbstractTest {
     @Test
     public void removeAll() {
         Set<String> keys = new HashSet<>();
-        keys.add("testKey1");
-        keys.add("testKey2");
+        String key1 = "key1";
+        String key2 = "key2";
+        keys.add(key1);
+        keys.add(key2);
 
         assertFalse(propagationByResource.removeAll(ResourceOperation.CREATE, 
keys));
         assertFalse(propagationByResource.removeAll(ResourceOperation.UPDATE, 
keys));
         assertFalse(propagationByResource.removeAll(ResourceOperation.DELETE, 
keys));
         assertFalse(propagationByResource.removeAll(ResourceOperation.NONE, 
keys));
+
+        propagationByResource.add(ResourceOperation.CREATE, key1);
+        propagationByResource.add(ResourceOperation.UPDATE, key2);
+        assertTrue(propagationByResource.removeAll(keys));
+        assertFalse(propagationByResource.contains(key1));
+        assertFalse(propagationByResource.contains(key2));
+    }
+
+    @Test
+    public void retainAll() {
+        Set<String> keys = new HashSet<>();
+        String key1 = "key1";
+        String key2 = "key2";
+        String key3 = "key3";
+        keys.add(key1);
+
+        propagationByResource.add(ResourceOperation.CREATE, key1);
+        propagationByResource.add(ResourceOperation.UPDATE, key2);
+        propagationByResource.add(ResourceOperation.DELETE, key3);
+        assertTrue(propagationByResource.retainAll(keys));
+        assertTrue(propagationByResource.contains(key1));
+        assertFalse(propagationByResource.contains(key2));
+        assertFalse(propagationByResource.contains(key3));
     }
 
     @Test

Reply via email to