syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [12/16] syncope git commit: [SYNCOPE-938] Switching from commons-collections to Java 8 features
Date Tue, 22 Aug 2017 15:09:16 GMT
http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java b/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java
index c0b211f..f180ed0 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java
@@ -21,11 +21,8 @@ package org.apache.syncope.common.lib;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
-import org.apache.commons.collections4.Closure;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.commons.lang3.SerializationUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.Pair;
@@ -115,16 +112,18 @@ public final class AnyOperations {
         result.getAuxClasses().clear();
 
         if (!incremental) {
-            for (String auxClass : CollectionUtils.subtract(original.getAuxClasses(), updated.getAuxClasses())) {
-                result.getAuxClasses().add(
-                        new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(auxClass).build());
-            }
+            original.getAuxClasses().stream().filter(auxClass -> !updated.getAuxClasses().contains(auxClass)).
+                    forEach(auxClass -> {
+                        result.getAuxClasses().add(new StringPatchItem.Builder().
+                                operation(PatchOperation.DELETE).value(auxClass).build());
+                    });
         }
 
-        for (String auxClass : CollectionUtils.subtract(updated.getAuxClasses(), original.getAuxClasses())) {
-            result.getAuxClasses().add(
-                    new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(auxClass).build());
-        }
+        updated.getAuxClasses().stream().filter(auxClass -> !original.getAuxClasses().contains(auxClass)).
+                forEach(auxClass -> {
+                    result.getAuxClasses().add(new StringPatchItem.Builder().
+                            operation(PatchOperation.ADD_REPLACE).value(auxClass).build());
+                });
 
         // 3. plain attributes
         Map<String, AttrTO> updatedAttrs = EntityTOUtils.buildAttrMap(updated.getPlainAttrs());
@@ -133,20 +132,16 @@ public final class AnyOperations {
         result.getPlainAttrs().clear();
 
         if (!incremental) {
-            IterableUtils.forEach(CollectionUtils.subtract(originalAttrs.keySet(), updatedAttrs.keySet()),
-                    new Closure<String>() {
-
-                @Override
-                public void execute(final String schema) {
-                    result.getPlainAttrs().add(new AttrPatch.Builder().
-                            operation(PatchOperation.DELETE).
-                            attrTO(new AttrTO.Builder().schema(schema).build()).
-                            build());
-                }
-            });
+            originalAttrs.keySet().stream().filter(attr -> !updatedAttrs.containsKey(attr)).
+                    forEach(schema -> {
+                        result.getPlainAttrs().add(new AttrPatch.Builder().
+                                operation(PatchOperation.DELETE).
+                                attrTO(new AttrTO.Builder().schema(schema).build()).
+                                build());
+                    });
         }
 
-        for (AttrTO attrTO : updatedAttrs.values()) {
+        updatedAttrs.values().forEach(attrTO -> {
             if (attrTO.getValues().isEmpty()) {
                 if (!incremental) {
                     result.getPlainAttrs().add(new AttrPatch.Builder().
@@ -163,7 +158,7 @@ public final class AnyOperations {
                     result.getPlainAttrs().add(patch);
                 }
             }
-        }
+        });
 
         // 4. virtual attributes
         result.getVirAttrs().clear();
@@ -173,16 +168,18 @@ public final class AnyOperations {
         result.getResources().clear();
 
         if (!incremental) {
-            for (String resource : CollectionUtils.subtract(original.getResources(), updated.getResources())) {
-                result.getResources().add(
-                        new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(resource).build());
-            }
+            original.getResources().stream().filter(resource -> !updated.getResources().contains(resource)).
+                    forEach(resource -> {
+                        result.getResources().add(new StringPatchItem.Builder().
+                                operation(PatchOperation.DELETE).value(resource).build());
+                    });
         }
 
-        for (String resource : CollectionUtils.subtract(updated.getResources(), original.getResources())) {
-            result.getResources().add(
-                    new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build());
-        }
+        updated.getResources().stream().filter(resource -> !original.getResources().contains(resource)).
+                forEach(resource -> {
+                    result.getResources().add(new StringPatchItem.Builder().
+                            operation(PatchOperation.ADD_REPLACE).value(resource).build());
+                });
     }
 
     /**
@@ -209,38 +206,41 @@ public final class AnyOperations {
         Map<Pair<String, String>, RelationshipTO> originalRels =
                 EntityTOUtils.buildRelationshipMap(original.getRelationships());
 
-        for (Map.Entry<Pair<String, String>, RelationshipTO> entry : updatedRels.entrySet()) {
-            if (!originalRels.containsKey(entry.getKey())) {
-                result.getRelationships().add(new RelationshipPatch.Builder().
-                        operation(PatchOperation.ADD_REPLACE).
-                        relationshipTO(entry.getValue()).build());
-            }
-        }
+        updatedRels.entrySet().stream().
+                filter(entry -> (!originalRels.containsKey(entry.getKey()))).
+                forEachOrdered(entry -> {
+                    result.getRelationships().add(new RelationshipPatch.Builder().
+                            operation(PatchOperation.ADD_REPLACE).
+                            relationshipTO(entry.getValue()).build());
+                });
 
         if (!incremental) {
-            for (Pair<String, String> key : CollectionUtils.subtract(originalRels.keySet(), updatedRels.keySet())) {
-                result.getRelationships().add(new RelationshipPatch.Builder().
-                        operation(PatchOperation.DELETE).
-                        relationshipTO(originalRels.get(key)).build());
-            }
+            originalRels.keySet().stream().filter(relationship -> !updatedRels.containsKey(relationship)).
+                    forEach(key -> {
+                        result.getRelationships().add(new RelationshipPatch.Builder().
+                                operation(PatchOperation.DELETE).
+                                relationshipTO(originalRels.get(key)).build());
+                    });
         }
 
         // 3. memberships
         Map<String, MembershipTO> updatedMembs = EntityTOUtils.buildMembershipMap(updated.getMemberships());
         Map<String, MembershipTO> originalMembs = EntityTOUtils.buildMembershipMap(original.getMemberships());
 
-        for (Map.Entry<String, MembershipTO> entry : updatedMembs.entrySet()) {
-            if (!originalMembs.containsKey(entry.getKey())) {
-                result.getMemberships().add(new MembershipPatch.Builder().
-                        operation(PatchOperation.ADD_REPLACE).group(entry.getValue().getGroupKey()).build());
-            }
-        }
+        updatedMembs.entrySet().stream().
+                filter(entry -> (!originalMembs.containsKey(entry.getKey()))).
+                forEachOrdered(entry -> {
+                    result.getMemberships().add(new MembershipPatch.Builder().
+                            operation(PatchOperation.ADD_REPLACE).group(entry.getValue().getGroupKey()).
+                            build());
+                });
 
         if (!incremental) {
-            for (String key : CollectionUtils.subtract(originalMembs.keySet(), updatedMembs.keySet())) {
-                result.getMemberships().add(new MembershipPatch.Builder().
-                        operation(PatchOperation.DELETE).group(originalMembs.get(key).getGroupKey()).build());
-            }
+            originalMembs.keySet().stream().filter(membership -> !updatedMembs.containsKey(membership)).
+                    forEach(key -> {
+                        result.getMemberships().add(new MembershipPatch.Builder().
+                                operation(PatchOperation.DELETE).group(originalMembs.get(key).getGroupKey()).build());
+                    });
         }
 
         return result;
@@ -290,16 +290,18 @@ public final class AnyOperations {
 
         // 4. roles
         if (!incremental) {
-            for (String toRemove : CollectionUtils.subtract(original.getRoles(), updated.getRoles())) {
-                result.getRoles().add(
-                        new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(toRemove).build());
-            }
+            original.getRoles().stream().filter(role -> !updated.getRoles().contains(role)).
+                    forEach(toRemove -> {
+                        result.getRoles().add(new StringPatchItem.Builder().
+                                operation(PatchOperation.DELETE).value(toRemove).build());
+                    });
         }
 
-        for (String toAdd : CollectionUtils.subtract(updated.getRoles(), original.getRoles())) {
-            result.getRoles().add(
-                    new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(toAdd).build());
-        }
+        updated.getRoles().stream().filter(role -> !original.getRoles().contains(role)).
+                forEach(toAdd -> {
+                    result.getRoles().add(new StringPatchItem.Builder().
+                            operation(PatchOperation.ADD_REPLACE).value(toAdd).build());
+                });
 
         // 5. relationships
         Map<Pair<String, String>, RelationshipTO> updatedRels =
@@ -307,48 +309,52 @@ public final class AnyOperations {
         Map<Pair<String, String>, RelationshipTO> originalRels =
                 EntityTOUtils.buildRelationshipMap(original.getRelationships());
 
-        for (Map.Entry<Pair<String, String>, RelationshipTO> entry : updatedRels.entrySet()) {
-            if (!originalRels.containsKey(entry.getKey())) {
-                result.getRelationships().add(new RelationshipPatch.Builder().
-                        operation(PatchOperation.ADD_REPLACE).
-                        relationshipTO(entry.getValue()).build());
-            }
-        }
+        updatedRels.entrySet().stream().
+                filter(entry -> (!originalRels.containsKey(entry.getKey()))).
+                forEachOrdered(entry -> {
+                    result.getRelationships().add(new RelationshipPatch.Builder().
+                            operation(PatchOperation.ADD_REPLACE).
+                            relationshipTO(entry.getValue()).build());
+                });
 
         if (!incremental) {
-            for (Pair<String, String> key : CollectionUtils.subtract(originalRels.keySet(), updatedRels.keySet())) {
-                result.getRelationships().add(new RelationshipPatch.Builder().
-                        operation(PatchOperation.DELETE).
-                        relationshipTO(originalRels.get(key)).build());
-            }
+            originalRels.keySet().stream().filter(relationship -> !updatedRels.containsKey(relationship)).
+                    forEach(key -> {
+                        result.getRelationships().add(new RelationshipPatch.Builder().
+                                operation(PatchOperation.DELETE).
+                                relationshipTO(originalRels.get(key)).build());
+                    });
         }
 
         // 6. memberships
         Map<String, MembershipTO> updatedMembs = EntityTOUtils.buildMembershipMap(updated.getMemberships());
         Map<String, MembershipTO> originalMembs = EntityTOUtils.buildMembershipMap(original.getMemberships());
 
-        for (Map.Entry<String, MembershipTO> entry : updatedMembs.entrySet()) {
-            MembershipPatch membershipPatch = new MembershipPatch.Builder().
-                    operation(PatchOperation.ADD_REPLACE).group(entry.getValue().getGroupKey()).build();
-
-            MembershipTO omemb;
-            if (originalMembs.containsKey(entry.getKey())) {
-                // get the original membership
-                omemb = originalMembs.get(entry.getKey());
-            } else {
-                // create an empty one to generate the patch
-                omemb = new MembershipTO.Builder().group(entry.getKey()).build();
-            }
-
-            diff(entry.getValue(), omemb, membershipPatch, incremental);
-            result.getMemberships().add(membershipPatch);
-        }
+        updatedMembs.entrySet().stream().
+                map(entry -> {
+                    MembershipPatch membershipPatch = new MembershipPatch.Builder().
+                            operation(PatchOperation.ADD_REPLACE).group(entry.getValue().getGroupKey()).build();
+                    MembershipTO omemb;
+                    if (originalMembs.containsKey(entry.getKey())) {
+                        // get the original membership
+                        omemb = originalMembs.get(entry.getKey());
+                    } else {
+                        // create an empty one to generate the patch
+                        omemb = new MembershipTO.Builder().group(entry.getKey()).build();
+                    }
+                    diff(entry.getValue(), omemb, membershipPatch, incremental);
+                    return membershipPatch;
+                }).
+                forEachOrdered(membershipPatch -> {
+                    result.getMemberships().add(membershipPatch);
+                });
 
         if (!incremental) {
-            for (String key : CollectionUtils.subtract(originalMembs.keySet(), updatedMembs.keySet())) {
-                result.getMemberships().add(new MembershipPatch.Builder().
-                        operation(PatchOperation.DELETE).group(originalMembs.get(key).getGroupKey()).build());
-            }
+            originalMembs.keySet().stream().filter(membership -> !updatedMembs.containsKey(membership)).
+                    forEach(key -> {
+                        result.getMemberships().add(new MembershipPatch.Builder().
+                                operation(PatchOperation.DELETE).group(originalMembs.get(key).getGroupKey()).build());
+                    });
         }
 
         return result;
@@ -403,7 +409,7 @@ public final class AnyOperations {
 
     private static Collection<AttrTO> patch(final Map<String, AttrTO> attrs, final Set<AttrPatch> attrPatches) {
         Map<String, AttrTO> rwattrs = new HashMap<>(attrs);
-        for (AttrPatch patch : attrPatches) {
+        attrPatches.forEach(patch -> {
             if (patch.getAttrTO() == null) {
                 LOG.warn("Invalid {} specified: {}", AttrPatch.class.getName(), patch);
             } else {
@@ -412,7 +418,7 @@ public final class AnyOperations {
                     rwattrs.put(patch.getAttrTO().getSchema(), patch.getAttrTO());
                 }
             }
-        }
+        });
 
         return rwattrs.values();
     }
@@ -496,46 +502,44 @@ public final class AnyOperations {
         }
 
         // 1. relationships
-        for (RelationshipPatch relPatch : anyObjectPatch.getRelationships()) {
-            if (relPatch.getRelationshipTO() == null) {
-                LOG.warn("Invalid {} specified: {}", RelationshipPatch.class.getName(), relPatch);
-            } else {
-                result.getRelationships().remove(relPatch.getRelationshipTO());
-                if (relPatch.getOperation() == PatchOperation.ADD_REPLACE) {
-                    result.getRelationships().add(relPatch.getRelationshipTO());
-                }
-            }
-        }
+        anyObjectPatch.getRelationships().
+                forEach(relPatch -> {
+                    if (relPatch.getRelationshipTO() == null) {
+                        LOG.warn("Invalid {} specified: {}", RelationshipPatch.class.getName(), relPatch);
+                    } else {
+                        result.getRelationships().remove(relPatch.getRelationshipTO());
+                        if (relPatch.getOperation() == PatchOperation.ADD_REPLACE) {
+                            result.getRelationships().add(relPatch.getRelationshipTO());
+                        }
+                    }
+                });
 
         // 2. memberships
-        for (final MembershipPatch membPatch : anyObjectPatch.getMemberships()) {
-            if (membPatch.getGroup() == null) {
-                LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
-            } else {
-                MembershipTO memb = IterableUtils.find(result.getMemberships(), new Predicate<MembershipTO>() {
-
-                    @Override
-                    public boolean evaluate(final MembershipTO object) {
-                        return membPatch.getGroup().equals(object.getGroupKey());
+        anyObjectPatch.getMemberships().
+                forEach(membPatch -> {
+                    if (membPatch.getGroup() == null) {
+                        LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
+                    } else {
+                        Optional<MembershipTO> memb = result.getMemberships().stream().
+                                filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).findFirst();
+                        if (memb.isPresent()) {
+                            result.getMemberships().remove(memb.get());
+                        }
+
+                        if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
+                            MembershipTO newMembershipTO =
+                                    new MembershipTO.Builder().group(membPatch.getGroup()).build();
+
+                            // 3. plain attributes
+                            newMembershipTO.getPlainAttrs().addAll(membPatch.getPlainAttrs());
+
+                            // 4. virtual attributes
+                            newMembershipTO.getVirAttrs().addAll(membPatch.getVirAttrs());
+
+                            result.getMemberships().add(newMembershipTO);
+                        }
                     }
                 });
-                if (memb != null) {
-                    result.getMemberships().remove(memb);
-                }
-
-                if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
-                    MembershipTO newMembershipTO = new MembershipTO.Builder().group(membPatch.getGroup()).build();
-
-                    // 3. plain attributes
-                    newMembershipTO.getPlainAttrs().addAll(membPatch.getPlainAttrs());
-
-                    // 4. virtual attributes
-                    newMembershipTO.getVirAttrs().addAll(membPatch.getVirAttrs());
-
-                    result.getMemberships().add(newMembershipTO);
-                }
-            }
-        }
 
         return result;
     }
@@ -555,46 +559,44 @@ public final class AnyOperations {
         }
 
         // 3. relationships
-        for (RelationshipPatch relPatch : userPatch.getRelationships()) {
-            if (relPatch.getRelationshipTO() == null) {
-                LOG.warn("Invalid {} specified: {}", RelationshipPatch.class.getName(), relPatch);
-            } else {
-                result.getRelationships().remove(relPatch.getRelationshipTO());
-                if (relPatch.getOperation() == PatchOperation.ADD_REPLACE) {
-                    result.getRelationships().add(relPatch.getRelationshipTO());
-                }
-            }
-        }
+        userPatch.getRelationships().
+                forEach(relPatch -> {
+                    if (relPatch.getRelationshipTO() == null) {
+                        LOG.warn("Invalid {} specified: {}", RelationshipPatch.class.getName(), relPatch);
+                    } else {
+                        result.getRelationships().remove(relPatch.getRelationshipTO());
+                        if (relPatch.getOperation() == PatchOperation.ADD_REPLACE) {
+                            result.getRelationships().add(relPatch.getRelationshipTO());
+                        }
+                    }
+                });
 
         // 4. memberships
-        for (final MembershipPatch membPatch : userPatch.getMemberships()) {
-            if (membPatch.getGroup() == null) {
-                LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
-            } else {
-                MembershipTO memb = IterableUtils.find(result.getMemberships(), new Predicate<MembershipTO>() {
-
-                    @Override
-                    public boolean evaluate(final MembershipTO object) {
-                        return membPatch.getGroup().equals(object.getGroupKey());
+        userPatch.getMemberships().
+                forEach(membPatch -> {
+                    if (membPatch.getGroup() == null) {
+                        LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
+                    } else {
+                        Optional<MembershipTO> memb = result.getMemberships().stream().
+                                filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).findFirst();
+                        if (memb.isPresent()) {
+                            result.getMemberships().remove(memb.get());
+                        }
+
+                        if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
+                            MembershipTO newMembershipTO =
+                                    new MembershipTO.Builder().group(membPatch.getGroup()).build();
+
+                            // 3. plain attributes
+                            newMembershipTO.getPlainAttrs().addAll(membPatch.getPlainAttrs());
+
+                            // 4. virtual attributes
+                            newMembershipTO.getVirAttrs().addAll(membPatch.getVirAttrs());
+
+                            result.getMemberships().add(newMembershipTO);
+                        }
                     }
                 });
-                if (memb != null) {
-                    result.getMemberships().remove(memb);
-                }
-
-                if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
-                    MembershipTO newMembershipTO = new MembershipTO.Builder().group(membPatch.getGroup()).build();
-
-                    // 3. plain attributes
-                    newMembershipTO.getPlainAttrs().addAll(membPatch.getPlainAttrs());
-
-                    // 4. virtual attributes
-                    newMembershipTO.getVirAttrs().addAll(membPatch.getVirAttrs());
-
-                    result.getMemberships().add(newMembershipTO);
-                }
-            }
-        }
 
         // 5. roles
         for (StringPatchItem rolePatch : userPatch.getRoles()) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/EntityTOUtils.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/EntityTOUtils.java b/common/lib/src/main/java/org/apache/syncope/common/lib/EntityTOUtils.java
index dfc0a1e..38f5202 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/EntityTOUtils.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/EntityTOUtils.java
@@ -22,30 +22,16 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-import org.apache.commons.collections4.Transformer;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.EntityTO;
 import org.apache.syncope.common.lib.to.MembershipTO;
 import org.apache.syncope.common.lib.to.RelationshipTO;
 
 public final class EntityTOUtils {
 
-    public static <E extends EntityTO> Transformer<E, String> keyTransformer() {
-        return new Transformer<E, String>() {
-
-            @Override
-            public String transform(final E input) {
-                return input.getKey();
-            }
-        };
-    }
-
     public static Map<String, AttrTO> buildAttrMap(final Collection<AttrTO> attrs) {
         Map<String, AttrTO> result = new HashMap<>(attrs.size());
-        for (AttrTO attributeTO : attrs) {
-            result.put(attributeTO.getSchema(), attributeTO);
-        }
+        attrs.forEach(attrTO -> result.put(attrTO.getSchema(), attrTO));
 
         return Collections.unmodifiableMap(result);
     }
@@ -54,18 +40,15 @@ public final class EntityTOUtils {
             final Collection<RelationshipTO> relationships) {
 
         Map<Pair<String, String>, RelationshipTO> result = new HashMap<>(relationships.size());
-        for (RelationshipTO relationship : relationships) {
-            result.put(Pair.of(relationship.getType(), relationship.getRightKey()), relationship);
-        }
+        relationships.forEach(
+                relationship -> result.put(Pair.of(relationship.getType(), relationship.getRightKey()), relationship));
 
         return Collections.unmodifiableMap(result);
     }
 
     public static Map<String, MembershipTO> buildMembershipMap(final Collection<MembershipTO> memberships) {
         Map<String, MembershipTO> result = new HashMap<>(memberships.size());
-        for (MembershipTO membership : memberships) {
-            result.put(membership.getRightKey(), membership);
-        }
+        memberships.forEach(membership -> result.put(membership.getRightKey(), membership));
 
         return Collections.unmodifiableMap(result);
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeClientCompositeException.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeClientCompositeException.java b/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeClientCompositeException.java
index b338df8..3e7bc0c 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeClientCompositeException.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/SyncopeClientCompositeException.java
@@ -20,9 +20,8 @@ package org.apache.syncope.common.lib;
 
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Optional;
 import java.util.Set;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.common.lib.types.ClientExceptionType;
 
 public class SyncopeClientCompositeException extends SyncopeClientException {
@@ -68,17 +67,12 @@ public class SyncopeClientCompositeException extends SyncopeClientException {
                     + ClientExceptionType.class.getName() + " set");
         }
 
-        SyncopeClientException alreadyAdded = IterableUtils.find(exceptions, new Predicate<SyncopeClientException>() {
+        Optional<SyncopeClientException> alreadyAdded =
+                exceptions.stream().filter(ex -> ex.getType() == exception.getType()).findFirst();
 
-            @Override
-            public boolean evaluate(final SyncopeClientException ex) {
-                return ex.getType() == exception.getType();
-            }
-        });
-
-        return alreadyAdded == null
-                ? exceptions.add(exception)
-                : alreadyAdded.getElements().addAll(exception.getElements());
+        return alreadyAdded.isPresent()
+                ? alreadyAdded.get().getElements().addAll(exception.getElements())
+                : exceptions.add(exception);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/collections/CircularFifoQueue.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/collections/CircularFifoQueue.java b/common/lib/src/main/java/org/apache/syncope/common/lib/collections/CircularFifoQueue.java
new file mode 100644
index 0000000..1977a7e
--- /dev/null
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/collections/CircularFifoQueue.java
@@ -0,0 +1,427 @@
+/*
+ * 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.syncope.common.lib.collections;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.AbstractCollection;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Queue;
+
+/**
+ * CircularFifoQueue is a first-in first-out queue with a fixed size that
+ * replaces its oldest element if full.
+ *
+ * The removal order of a {@link CircularFifoQueue} is based on the
+ * insertion order; elements are removed in the same order in which they
+ * were added. The iteration order is the same as the removal order.
+ *
+ * The {@link #add(Object)}, {@link #remove()}, {@link #peek()}, {@link #poll},
+ * {@link #offer(Object)} operations all perform in constant time.
+ * All other operations perform in linear time or worse.
+ *
+ * This queue prevents null objects from being added.
+ *
+ * @param <E> the type of elements held in this collection
+ */
+public class CircularFifoQueue<E> extends AbstractCollection<E> implements Queue<E>, Serializable {
+
+    private static final long serialVersionUID = -8423413834657610406L;
+
+    /** Underlying storage array. */
+    private transient E[] elements;
+
+    /** Array index of first (oldest) queue element. */
+    private transient int start = 0;
+
+    /**
+     * Index mod maxElements of the array position following the last queue
+     * element. Queue elements start at elements[start] and "wrap around"
+     * elements[maxElements-1], ending at elements[decrement(end)].
+     * For example, elements = {c,a,b}, start=1, end=1 corresponds to
+     * the queue [a,b,c].
+     */
+    private transient int end = 0;
+
+    /** Flag to indicate if the queue is currently full. */
+    private transient boolean full = false;
+
+    /** Capacity of the queue. */
+    private final int maxElements;
+
+    /**
+     * Constructor that creates a queue with the default size of 32.
+     */
+    public CircularFifoQueue() {
+        this(32);
+    }
+
+    /**
+     * Constructor that creates a queue with the specified size.
+     *
+     * @param size the size of the queue (cannot be changed)
+     * @throws IllegalArgumentException if the size is &lt; 1
+     */
+    @SuppressWarnings("unchecked")
+    public CircularFifoQueue(final int size) {
+        if (size <= 0) {
+            throw new IllegalArgumentException("The size must be greater than 0");
+        }
+        elements = (E[]) new Object[size];
+        maxElements = elements.length;
+    }
+
+    /**
+     * Constructor that creates a queue from the specified collection.
+     * The collection size also sets the queue size.
+     *
+     * @param coll the collection to copy into the queue, may not be null
+     * @throws NullPointerException if the collection is null
+     */
+    public CircularFifoQueue(final Collection<? extends E> coll) {
+        this(coll.size());
+        addAll(coll);
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Write the queue out using a custom routine.
+     *
+     * @param out the output stream
+     * @throws IOException if an I/O error occurs while writing to the output stream
+     */
+    private void writeObject(final ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+        out.writeInt(size());
+        for (final E e : this) {
+            out.writeObject(e);
+        }
+    }
+
+    /**
+     * Read the queue in using a custom routine.
+     *
+     * @param in the input stream
+     * @throws IOException if an I/O error occurs while writing to the output stream
+     * @throws ClassNotFoundException if the class of a serialized object can not be found
+     */
+    @SuppressWarnings("unchecked")
+    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
+        in.defaultReadObject();
+        elements = (E[]) new Object[maxElements];
+        final int size = in.readInt();
+        for (int i = 0; i < size; i++) {
+            elements[i] = (E) in.readObject();
+        }
+        start = 0;
+        full = size == maxElements;
+        if (full) {
+            end = 0;
+        } else {
+            end = size;
+        }
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Returns the number of elements stored in the queue.
+     *
+     * @return this queue's size
+     */
+    @Override
+    public int size() {
+        int size;
+
+        if (end < start) {
+            size = maxElements - start + end;
+        } else if (end == start) {
+            size = full ? maxElements : 0;
+        } else {
+            size = end - start;
+        }
+
+        return size;
+    }
+
+    /**
+     * Returns true if this queue is empty; false otherwise.
+     *
+     * @return true if this queue is empty
+     */
+    @Override
+    public boolean isEmpty() {
+        return size() == 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p>
+     * A {@code CircularFifoQueue} can never be full, thus this returns always
+     * {@code false}.
+     *
+     * @return always returns {@code false}
+     */
+    public boolean isFull() {
+        return false;
+    }
+
+    /**
+     * Returns {@code true} if the capacity limit of this queue has been reached,
+     * i.e. the number of elements stored in the queue equals its maximum size.
+     *
+     * @return {@code true} if the capacity limit has been reached, {@code false} otherwise
+     * @since 4.1
+     */
+    public boolean isAtFullCapacity() {
+        return size() == maxElements;
+    }
+
+    /**
+     * Gets the maximum size of the collection (the bound).
+     *
+     * @return the maximum number of elements the collection can hold
+     */
+    public int maxSize() {
+        return maxElements;
+    }
+
+    /**
+     * Clears this queue.
+     */
+    @Override
+    public void clear() {
+        full = false;
+        start = 0;
+        end = 0;
+        Arrays.fill(elements, null);
+    }
+
+    /**
+     * Adds the given element to this queue. If the queue is full, the least recently added
+     * element is discarded so that a new element can be inserted.
+     *
+     * @param element the element to add
+     * @return true, always
+     * @throws NullPointerException if the given element is null
+     */
+    @Override
+    public boolean add(final E element) {
+        if (null == element) {
+            throw new NullPointerException("Attempted to add null object to queue");
+        }
+
+        if (isAtFullCapacity()) {
+            remove();
+        }
+
+        elements[end++] = element;
+
+        if (end >= maxElements) {
+            end = 0;
+        }
+
+        if (end == start) {
+            full = true;
+        }
+
+        return true;
+    }
+
+    /**
+     * Returns the element at the specified position in this queue.
+     *
+     * @param index the position of the element in the queue
+     * @return the element at position {@code index}
+     * @throws NoSuchElementException if the requested position is outside the range [0, size)
+     */
+    public E get(final int index) {
+        final int sz = size();
+        if (index < 0 || index >= sz) {
+            throw new NoSuchElementException(
+                    String.format("The specified index (%1$d) is outside the available range [0, %2$d)",
+                            index, Integer.valueOf(sz)));
+        }
+
+        final int idx = (start + index) % maxElements;
+        return elements[idx];
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Adds the given element to this queue. If the queue is full, the least recently added
+     * element is discarded so that a new element can be inserted.
+     *
+     * @param element the element to add
+     * @return true, always
+     * @throws NullPointerException if the given element is null
+     */
+    @Override
+    public boolean offer(final E element) {
+        return add(element);
+    }
+
+    @Override
+    public E poll() {
+        if (isEmpty()) {
+            return null;
+        }
+        return remove();
+    }
+
+    @Override
+    public E element() {
+        if (isEmpty()) {
+            throw new NoSuchElementException("queue is empty");
+        }
+        return peek();
+    }
+
+    @Override
+    public E peek() {
+        if (isEmpty()) {
+            return null;
+        }
+        return elements[start];
+    }
+
+    @Override
+    public E remove() {
+        if (isEmpty()) {
+            throw new NoSuchElementException("queue is empty");
+        }
+
+        final E element = elements[start];
+        if (null != element) {
+            elements[start++] = null;
+
+            if (start >= maxElements) {
+                start = 0;
+            }
+            full = false;
+        }
+        return element;
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Increments the internal index.
+     *
+     * @param index the index to increment
+     * @return the updated index
+     */
+    private int increment(final int index) {
+        int result = index;
+        result++;
+        if (result >= maxElements) {
+            result = 0;
+        }
+        return result;
+    }
+
+    /**
+     * Decrements the internal index.
+     *
+     * @param index the index to decrement
+     * @return the updated index
+     */
+    private int decrement(final int index) {
+        int result = index;
+        result--;
+        if (result < 0) {
+            result = maxElements - 1;
+        }
+        return result;
+    }
+
+    /**
+     * Returns an iterator over this queue's elements.
+     *
+     * @return an iterator over this queue's elements
+     */
+    @Override
+    public Iterator<E> iterator() {
+        return new Iterator<E>() {
+
+            private int index = start;
+
+            private int lastReturnedIndex = -1;
+
+            private boolean isFirst = full;
+
+            @Override
+            public boolean hasNext() {
+                return isFirst || index != end;
+            }
+
+            @Override
+            public E next() {
+                if (!hasNext()) {
+                    throw new NoSuchElementException();
+                }
+                isFirst = false;
+                lastReturnedIndex = index;
+                index = increment(index);
+                return elements[lastReturnedIndex];
+            }
+
+            @Override
+            public void remove() {
+                if (lastReturnedIndex == -1) {
+                    throw new IllegalStateException();
+                }
+
+                // First element can be removed quickly
+                if (lastReturnedIndex == start) {
+                    CircularFifoQueue.this.remove();
+                    lastReturnedIndex = -1;
+                    return;
+                }
+
+                int pos = lastReturnedIndex + 1;
+                if (start < lastReturnedIndex && pos < end) {
+                    // shift in one part
+                    System.arraycopy(elements, pos, elements, lastReturnedIndex, end - pos);
+                } else {
+                    // Other elements require us to shift the subsequent elements
+                    while (pos != end) {
+                        if (pos >= maxElements) {
+                            elements[pos - 1] = elements[0];
+                            pos = 0;
+                        } else {
+                            elements[decrement(pos)] = elements[pos];
+                            pos = increment(pos);
+                        }
+                    }
+                }
+
+                lastReturnedIndex = -1;
+                end = decrement(end);
+                elements[end] = null;
+                full = false;
+                index = decrement(index);
+            }
+
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/collections/IteratorChain.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/collections/IteratorChain.java b/common/lib/src/main/java/org/apache/syncope/common/lib/collections/IteratorChain.java
new file mode 100644
index 0000000..c26de2a
--- /dev/null
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/collections/IteratorChain.java
@@ -0,0 +1,282 @@
+/*
+ * 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.syncope.common.lib.collections;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Queue;
+
+/**
+ * An IteratorChain is an Iterator that wraps a number of Iterators.
+ *
+ * This class makes multiple iterators look like one to the caller. When any
+ * method from the Iterator interface is called, the IteratorChain will delegate
+ * to a single underlying Iterator. The IteratorChain will invoke the Iterators
+ * in sequence until all Iterators are exhausted.
+ *
+ * Under many circumstances, linking Iterators together in this manner is more
+ * efficient (and convenient) than reading out the contents of each Iterator
+ * into a List and creating a new Iterator.
+ *
+ * Calling a method that adds new Iterator <i>after a method in the Iterator
+ * interface has been called</i> will result in an UnsupportedOperationException.
+ *
+ * NOTE: As from version 3.0, the IteratorChain may contain no iterators. In
+ * this case the class will function as an empty iterator.
+ *
+ * NOTE: As from version 4.0, the IteratorChain stores the iterators in a queue
+ * and removes any reference to them as soon as they are not used anymore. Thus
+ * the methods {@code setIterator(Iterator)} and {@code getIterators()} have been
+ * removed and {@link #size()} will return the number of remaining iterators in
+ * the queue.
+ *
+ * @param <E> the type of elements held in this collection
+ */
+public class IteratorChain<E> implements Iterator<E> {
+
+    /** The chain of iterators. */
+    private final Queue<Iterator<? extends E>> iteratorChain = new LinkedList<>();
+
+    /** The current iterator. */
+    private Iterator<? extends E> currentIterator = null;
+
+    /**
+     * The "last used" Iterator is the Iterator upon which next() or hasNext()
+     * was most recently called used for the remove() operation only.
+     */
+    private Iterator<? extends E> lastUsedIterator = null;
+
+    /**
+     * ComparatorChain is "locked" after the first time compare(Object,Object)
+     * is called.
+     */
+    private boolean isLocked = false;
+
+    //-----------------------------------------------------------------------
+    /**
+     * Construct an IteratorChain with no Iterators.
+     *
+     * You will normally use {@link #addIterator(Iterator)} to add some
+     * iterators after using this constructor.
+     */
+    public IteratorChain() {
+        super();
+    }
+
+    /**
+     * Construct an IteratorChain with a single Iterator.
+     *
+     * This method takes one iterator. The newly constructed iterator will
+     * iterate through that iterator. Thus calling this constructor on its own
+     * will have no effect other than decorating the input iterator.
+     *
+     * You will normally use {@link #addIterator(Iterator)} to add some more
+     * iterators after using this constructor.
+     *
+     * @param iterator the first child iterator in the IteratorChain, not null
+     * @throws NullPointerException if the iterator is null
+     */
+    public IteratorChain(final Iterator<? extends E> iterator) {
+        super();
+        addIterator(iterator);
+    }
+
+    /**
+     * Constructs a new <code>IteratorChain</code> over the two given iterators.
+     *
+     * This method takes two iterators. The newly constructed iterator will
+     * iterate through each one of the input iterators in turn.
+     *
+     * @param first the first child iterator in the IteratorChain, not null
+     * @param second the second child iterator in the IteratorChain, not null
+     * @throws NullPointerException if either iterator is null
+     */
+    public IteratorChain(final Iterator<? extends E> first, final Iterator<? extends E> second) {
+        super();
+        addIterator(first);
+        addIterator(second);
+    }
+
+    /**
+     * Constructs a new <code>IteratorChain</code> over the array of iterators.
+     *
+     * This method takes an array of iterators. The newly constructed iterator
+     * will iterate through each one of the input iterators in turn.
+     *
+     * @param iteratorChain the array of iterators, not null
+     * @throws NullPointerException if iterators array is or contains null
+     */
+    public IteratorChain(final Iterator<? extends E>... iteratorChain) {
+        super();
+        for (final Iterator<? extends E> element : iteratorChain) {
+            addIterator(element);
+        }
+    }
+
+    /**
+     * Constructs a new <code>IteratorChain</code> over the collection of
+     * iterators.
+     *
+     * This method takes a collection of iterators. The newly constructed
+     * iterator will iterate through each one of the input iterators in turn.
+     *
+     * @param iteratorChain the collection of iterators, not null
+     * @throws NullPointerException if iterators collection is or contains null
+     * @throws ClassCastException if iterators collection doesn't contain an
+     * iterator
+     */
+    public IteratorChain(final Collection<Iterator<? extends E>> iteratorChain) {
+        super();
+        for (final Iterator<? extends E> iterator : iteratorChain) {
+            addIterator(iterator);
+        }
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Add an Iterator to the end of the chain
+     *
+     * @param iterator Iterator to add
+     * @throws IllegalStateException if I've already started iterating
+     * @throws NullPointerException if the iterator is null
+     */
+    public void addIterator(final Iterator<? extends E> iterator) {
+        checkLocked();
+        if (iterator == null) {
+            throw new NullPointerException("Iterator must not be null");
+        }
+        iteratorChain.add(iterator);
+    }
+
+    /**
+     * Returns the remaining number of Iterators in the current IteratorChain.
+     *
+     * @return Iterator count
+     */
+    public int size() {
+        return iteratorChain.size();
+    }
+
+    /**
+     * Determine if modifications can still be made to the IteratorChain.
+     * IteratorChains cannot be modified once they have executed a method from
+     * the Iterator interface.
+     *
+     * @return true if IteratorChain cannot be modified, false if it can
+     */
+    public boolean isLocked() {
+        return isLocked;
+    }
+
+    /**
+     * Checks whether the iterator chain is now locked and in use.
+     */
+    private void checkLocked() {
+        if (isLocked) {
+            throw new UnsupportedOperationException(
+                    "IteratorChain cannot be changed after the first use of a method from the Iterator interface");
+        }
+    }
+
+    /**
+     * Lock the chain so no more iterators can be added. This must be called
+     * from all Iterator interface methods.
+     */
+    private void lockChain() {
+        if (!isLocked) {
+            isLocked = true;
+        }
+    }
+
+    /**
+     * Updates the current iterator field to ensure that the current Iterator is
+     * not exhausted
+     */
+    protected void updateCurrentIterator() {
+        if (currentIterator == null) {
+            if (iteratorChain.isEmpty()) {
+                currentIterator = Collections.emptyListIterator();
+            } else {
+                currentIterator = iteratorChain.remove();
+            }
+            // set last used iterator here, in case the user calls remove
+            // before calling hasNext() or next() (although they shouldn't)
+            lastUsedIterator = currentIterator;
+        }
+
+        while (!currentIterator.hasNext() && !iteratorChain.isEmpty()) {
+            currentIterator = iteratorChain.remove();
+        }
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Return true if any Iterator in the IteratorChain has a remaining element.
+     *
+     * @return true if elements remain
+     */
+    @Override
+    public boolean hasNext() {
+        lockChain();
+        updateCurrentIterator();
+        lastUsedIterator = currentIterator;
+
+        return currentIterator.hasNext();
+    }
+
+    /**
+     * Returns the next Object of the current Iterator
+     *
+     * @return Object from the current Iterator
+     * @throws java.util.NoSuchElementException if all the Iterators are
+     * exhausted
+     */
+    @Override
+    public E next() {
+        lockChain();
+        updateCurrentIterator();
+        lastUsedIterator = currentIterator;
+
+        return currentIterator.next();
+    }
+
+    /**
+     * Removes from the underlying collection the last element returned by the
+     * Iterator. As with next() and hasNext(), this method calls remove() on the
+     * underlying Iterator. Therefore, this method may throw an
+     * UnsupportedOperationException if the underlying Iterator does not support
+     * this method.
+     *
+     * @throws UnsupportedOperationException if the remove operator is not
+     * supported by the underlying Iterator
+     * @throws IllegalStateException if the next method has not yet been called,
+     * or the remove method has already been called after the last call to the
+     * next method.
+     */
+    @Override
+    public void remove() {
+        lockChain();
+        if (currentIterator == null) {
+            updateCurrentIterator();
+        }
+        lastUsedIterator.remove();
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/info/SystemInfo.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/info/SystemInfo.java b/common/lib/src/main/java/org/apache/syncope/common/lib/info/SystemInfo.java
index 2a0f1f4..216316b 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/info/SystemInfo.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/info/SystemInfo.java
@@ -24,8 +24,8 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.queue.CircularFifoQueue;
 import org.apache.syncope.common.lib.AbstractBaseBean;
+import org.apache.syncope.common.lib.collections.CircularFifoQueue;
 
 @XmlRootElement(name = "systemInfo")
 @XmlType

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/GenericMapType.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/GenericMapType.java b/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/GenericMapType.java
index e57a401..48dca0b 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/GenericMapType.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/GenericMapType.java
@@ -28,9 +28,7 @@ public class GenericMapType<K, V> {
     }
 
     public GenericMapType(final Map<K, V> map) {
-        for (Map.Entry<K, V> e : map.entrySet()) {
-            entry.add(new GenericMapEntryType<>(e));
-        }
+        map.entrySet().forEach(e -> entry.add(new GenericMapEntryType<>(e)));
     }
 
     public List<GenericMapEntryType<K, V>> getEntry() {

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/XmlGenericMapAdapter.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/XmlGenericMapAdapter.java b/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/XmlGenericMapAdapter.java
index 1855164..63d6825 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/XmlGenericMapAdapter.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/jaxb/XmlGenericMapAdapter.java
@@ -26,9 +26,7 @@ public class XmlGenericMapAdapter<K, V> extends XmlAdapter<GenericMapType<K, V>,
     public Map<K, V> unmarshal(final GenericMapType<K, V> v) throws Exception {
         Map<K, V> map = new HashMap<>();
 
-        for (GenericMapEntryType<K, V> mapEntryType : v.getEntry()) {
-            map.put(mapEntryType.getKey(), mapEntryType.getValue());
-        }
+        v.getEntry().forEach(mapEntryType -> map.put(mapEntryType.getKey(), mapEntryType.getValue()));
 
         return map;
     }
@@ -37,12 +35,12 @@ public class XmlGenericMapAdapter<K, V> extends XmlAdapter<GenericMapType<K, V>,
     public GenericMapType<K, V> marshal(final Map<K, V> v) throws Exception {
         GenericMapType<K, V> mapType = new GenericMapType<>();
 
-        for (Map.Entry<K, V> entry : v.entrySet()) {
+        v.entrySet().stream().map(entry -> {
             GenericMapEntryType<K, V> mapEntryType = new GenericMapEntryType<>();
             mapEntryType.setKey(entry.getKey());
             mapEntryType.setValue(entry.getValue());
-            mapType.getEntry().add(mapEntryType);
-        }
+            return mapEntryType;
+        }).forEachOrdered(mapEntryType -> mapType.getEntry().add(mapEntryType));
 
         return mapType;
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/patch/GroupPatch.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/patch/GroupPatch.java b/common/lib/src/main/java/org/apache/syncope/common/lib/patch/GroupPatch.java
index 0cf5f31..3bfaeab 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/patch/GroupPatch.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/patch/GroupPatch.java
@@ -24,13 +24,12 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.common.lib.jaxb.XmlGenericMapAdapter;
 import org.apache.syncope.common.lib.to.TypeExtensionTO;
 
@@ -92,14 +91,9 @@ public class GroupPatch extends AnyPatch {
     }
 
     @JsonIgnore
-    public TypeExtensionTO getTypeExtension(final String anyType) {
-        return IterableUtils.find(typeExtensions, new Predicate<TypeExtensionTO>() {
-
-            @Override
-            public boolean evaluate(final TypeExtensionTO typeExtension) {
-                return anyType != null && anyType.equals(typeExtension.getAnyType());
-            }
-        });
+    public Optional<TypeExtensionTO> getTypeExtension(final String anyType) {
+        return typeExtensions.stream().filter(
+                typeExtension -> anyType != null && anyType.equals(typeExtension.getAnyType())).findFirst();
     }
 
     @XmlElementWrapper(name = "typeExtensions")

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/patch/PasswordPatch.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/patch/PasswordPatch.java b/common/lib/src/main/java/org/apache/syncope/common/lib/patch/PasswordPatch.java
index 93e6b9e..b02e52e 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/patch/PasswordPatch.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/patch/PasswordPatch.java
@@ -27,7 +27,6 @@ import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.CollectionUtils;
 
 @XmlRootElement(name = "passwordPatch")
 @XmlType
@@ -56,7 +55,9 @@ public class PasswordPatch extends StringReplacePatchItem {
         }
 
         public Builder resources(final String... resources) {
-            CollectionUtils.addAll(getInstance().getResources(), resources);
+            for (String resource : resources) {
+                getInstance().getResources().add(resource);
+            }
             return this;
         }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/search/SpecialAttr.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/search/SpecialAttr.java b/common/lib/src/main/java/org/apache/syncope/common/lib/search/SpecialAttr.java
index c744169..1a90376 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/search/SpecialAttr.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/search/SpecialAttr.java
@@ -19,8 +19,7 @@
 package org.apache.syncope.common.lib.search;
 
 import java.util.Arrays;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
+import java.util.Optional;
 
 public enum SpecialAttr {
 
@@ -79,14 +78,8 @@ public enum SpecialAttr {
         return literal;
     }
 
-    public static SpecialAttr fromString(final String value) {
-        return IterableUtils.find(Arrays.asList(values()), new Predicate<SpecialAttr>() {
-
-            @Override
-            public boolean evaluate(final SpecialAttr specialAttr) {
-                return specialAttr.literal.equals(value);
-            }
-        });
+    public static Optional<SpecialAttr> fromString(final String value) {
+        return Arrays.stream(values()).filter(specialAttr -> specialAttr.literal.equals(value)).findFirst();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyObjectTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyObjectTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyObjectTO.java
index af8b0ea..7641687 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyObjectTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyObjectTO.java
@@ -22,12 +22,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 
 @XmlRootElement(name = "anyObject")
 @XmlType
@@ -53,14 +52,10 @@ public class AnyObjectTO extends AnyTO implements GroupableRelatableTO {
 
     @JsonIgnore
     @Override
-    public RelationshipTO getRelationship(final String type, final String rightKey) {
-        return IterableUtils.find(relationships, new Predicate<RelationshipTO>() {
-
-            @Override
-            public boolean evaluate(final RelationshipTO object) {
-                return type.equals(object.getType()) && rightKey.equals(object.getRightKey());
-            }
-        });
+    public Optional<RelationshipTO> getRelationship(final String type, final String rightKey) {
+        return relationships.stream().filter(
+                relationship -> type.equals(relationship.getType()) && rightKey.equals(relationship.getRightKey())).
+                findFirst();
     }
 
     @XmlElementWrapper(name = "relationships")
@@ -73,14 +68,8 @@ public class AnyObjectTO extends AnyTO implements GroupableRelatableTO {
 
     @JsonIgnore
     @Override
-    public MembershipTO getMembership(final String groupKey) {
-        return IterableUtils.find(memberships, new Predicate<MembershipTO>() {
-
-            @Override
-            public boolean evaluate(final MembershipTO object) {
-                return groupKey.equals(object.getGroupKey());
-            }
-        });
+    public Optional<MembershipTO> getMembership(final String groupKey) {
+        return memberships.stream().filter(membership -> groupKey.equals(membership.getGroupKey())).findFirst();
     }
 
     @XmlElementWrapper(name = "memberships")

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyTO.java
index 7796b62..e411e1a 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/AnyTO.java
@@ -24,13 +24,12 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 
 @XmlType
 @XmlSeeAlso({ UserTO.class, GroupTO.class, AnyObjectTO.class })
@@ -117,14 +116,8 @@ public abstract class AnyTO extends AbstractAnnotatedBean implements EntityTO, A
 
     @JsonIgnore
     @Override
-    public AttrTO getPlainAttr(final String schema) {
-        return IterableUtils.find(plainAttrs, new Predicate<AttrTO>() {
-
-            @Override
-            public boolean evaluate(final AttrTO object) {
-                return object.getSchema().equals(schema);
-            }
-        });
+    public Optional<AttrTO> getPlainAttr(final String schema) {
+        return plainAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
     }
 
     @XmlElementWrapper(name = "derAttrs")
@@ -137,14 +130,8 @@ public abstract class AnyTO extends AbstractAnnotatedBean implements EntityTO, A
 
     @JsonIgnore
     @Override
-    public AttrTO getDerAttr(final String schema) {
-        return IterableUtils.find(derAttrs, new Predicate<AttrTO>() {
-
-            @Override
-            public boolean evaluate(final AttrTO object) {
-                return object.getSchema().equals(schema);
-            }
-        });
+    public Optional<AttrTO> getDerAttr(final String schema) {
+        return derAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
     }
 
     @XmlElementWrapper(name = "virAttrs")
@@ -157,14 +144,8 @@ public abstract class AnyTO extends AbstractAnnotatedBean implements EntityTO, A
 
     @JsonIgnore
     @Override
-    public AttrTO getVirAttr(final String schema) {
-        return IterableUtils.find(virAttrs, new Predicate<AttrTO>() {
-
-            @Override
-            public boolean evaluate(final AttrTO object) {
-                return object.getSchema().equals(schema);
-            }
-        });
+    public Optional<AttrTO> getVirAttr(final String schema) {
+        return virAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
     }
 
     @XmlElementWrapper(name = "resources")

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttrTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttrTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttrTO.java
index 7822a6b..0c71ca6 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttrTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttrTO.java
@@ -28,7 +28,6 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.CollectionUtils;
 
 @XmlRootElement(name = "attribute")
 @XmlType
@@ -56,7 +55,9 @@ public class AttrTO extends AbstractBaseBean {
         }
 
         public Builder values(final String... values) {
-            CollectionUtils.addAll(instance.getValues(), values);
+            for (String value : values) {
+                instance.getValues().add(value);
+            }
             return this;
         }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttributableTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttributableTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttributableTO.java
index 79e57b8..d0f900c 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttributableTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/AttributableTO.java
@@ -18,19 +18,20 @@
  */
 package org.apache.syncope.common.lib.to;
 
+import java.util.Optional;
 import java.util.Set;
 
 public interface AttributableTO {
 
     Set<AttrTO> getPlainAttrs();
 
-    AttrTO getPlainAttr(String schema);
+    Optional<AttrTO> getPlainAttr(String schema);
 
     Set<AttrTO> getDerAttrs();
 
-    AttrTO getDerAttr(String schema);
+    Optional<AttrTO> getDerAttr(String schema);
 
     Set<AttrTO> getVirAttrs();
 
-    AttrTO getVirAttr(String schema);
+    Optional<AttrTO> getVirAttr(String schema);
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/BulkActionResult.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/BulkActionResult.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/BulkActionResult.java
index c2e67f4..6458fdb 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/BulkActionResult.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/BulkActionResult.java
@@ -69,11 +69,9 @@ public class BulkActionResult extends AbstractBaseBean {
     public List<String> getResultByStatus(final Status status) {
         final List<String> result = new ArrayList<>();
 
-        for (Map.Entry<String, Status> entry : results.entrySet()) {
-            if (entry.getValue() == status) {
-                result.add(entry.getKey());
-            }
-        }
+        results.entrySet().stream().
+                filter((entry) -> (entry.getValue() == status)).
+                forEachOrdered(entry -> result.add(entry.getKey()));
 
         return Collections.unmodifiableList(result);
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnInstanceTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnInstanceTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnInstanceTO.java
index 23fb590..76424fe 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnInstanceTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnInstanceTO.java
@@ -23,14 +23,13 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import javax.ws.rs.PathParam;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.common.lib.AbstractBaseBean;
 import org.apache.syncope.common.lib.types.ConnConfProperty;
 import org.apache.syncope.common.lib.types.ConnectorCapability;
@@ -122,14 +121,8 @@ public class ConnInstanceTO extends AbstractBaseBean implements EntityTO {
     }
 
     @JsonIgnore
-    public ConnConfProperty getConf(final String schemaName) {
-        return IterableUtils.find(conf, new Predicate<ConnConfProperty>() {
-
-            @Override
-            public boolean evaluate(final ConnConfProperty object) {
-                return object.getSchema().getName().equals(schemaName);
-            }
-        });
+    public Optional<ConnConfProperty> getConf(final String schemaName) {
+        return conf.stream().filter(property -> property.getSchema().getName().equals(schemaName)).findFirst();
     }
 
     @XmlElementWrapper(name = "capabilities")

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnObjectTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnObjectTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnObjectTO.java
index 6301d68..6086066 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnObjectTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/ConnObjectTO.java
@@ -21,13 +21,12 @@ package org.apache.syncope.common.lib.to;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import java.util.LinkedHashSet;
+import java.util.Optional;
 import java.util.Set;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.common.lib.AbstractBaseBean;
 
 @XmlRootElement(name = "connObject")
@@ -46,13 +45,7 @@ public class ConnObjectTO extends AbstractBaseBean {
     }
 
     @JsonIgnore
-    public AttrTO getAttr(final String schema) {
-        return IterableUtils.find(attrs, new Predicate<AttrTO>() {
-
-            @Override
-            public boolean evaluate(final AttrTO object) {
-                return object.getSchema().equals(schema);
-            }
-        });
+    public Optional<AttrTO> getAttr(final String schema) {
+        return attrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupTO.java
index 0ae0885..c531840 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupTO.java
@@ -24,13 +24,12 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.common.lib.jaxb.XmlGenericMapAdapter;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 
@@ -102,14 +101,10 @@ public class GroupTO extends AnyTO {
     }
 
     @JsonIgnore
-    public TypeExtensionTO getTypeExtension(final String anyType) {
-        return IterableUtils.find(typeExtensions, new Predicate<TypeExtensionTO>() {
-
-            @Override
-            public boolean evaluate(final TypeExtensionTO typeExtension) {
-                return anyType != null && anyType.equals(typeExtension.getAnyType());
-            }
-        });
+    public Optional<TypeExtensionTO> getTypeExtension(final String anyType) {
+        return typeExtensions.stream().filter(
+                typeExtension -> anyType != null && anyType.equals(typeExtension.getAnyType())).
+                findFirst();
     }
 
     @XmlElementWrapper(name = "typeExtensions")

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupableRelatableTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupableRelatableTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupableRelatableTO.java
index f2b8dbc..37fcb3a 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupableRelatableTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/GroupableRelatableTO.java
@@ -19,16 +19,17 @@
 package org.apache.syncope.common.lib.to;
 
 import java.util.List;
+import java.util.Optional;
 
 public interface GroupableRelatableTO {
 
-    MembershipTO getMembership(String groupKey);
+    Optional<MembershipTO> getMembership(String groupKey);
 
     List<MembershipTO> getMemberships();
 
     List<MembershipTO> getDynMemberships();
 
-    RelationshipTO getRelationship(String type, String rightKey);
+    Optional<RelationshipTO> getRelationship(String type, String rightKey);
 
     List<RelationshipTO> getRelationships();
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java
index 23c91ac..c3be6f2 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java
@@ -25,8 +25,6 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.common.lib.AbstractBaseBean;
 
 @XmlRootElement(name = "mapping")
@@ -51,13 +49,7 @@ public class MappingTO extends AbstractBaseBean implements ItemContainerTO {
 
     @Override
     public ItemTO getConnObjectKeyItem() {
-        return IterableUtils.find(getItems(), new Predicate<ItemTO>() {
-
-            @Override
-            public boolean evaluate(final ItemTO item) {
-                return item.isConnObjectKey();
-            }
-        });
+        return getItems().stream().filter(item -> item.isConnObjectKey()).findFirst().get();
     }
 
     protected boolean addConnObjectKeyItem(final ItemTO connObjectItem) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/MembershipTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/MembershipTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/MembershipTO.java
index 5737c7f..9163aba 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/MembershipTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/MembershipTO.java
@@ -21,13 +21,12 @@ package org.apache.syncope.common.lib.to;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import java.util.HashSet;
+import java.util.Optional;
 import java.util.Set;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 
 @XmlRootElement(name = "membership")
@@ -111,14 +110,8 @@ public class MembershipTO extends RelationshipTO implements AttributableTO {
 
     @JsonIgnore
     @Override
-    public AttrTO getPlainAttr(final String schema) {
-        return IterableUtils.find(plainAttrs, new Predicate<AttrTO>() {
-
-            @Override
-            public boolean evaluate(final AttrTO object) {
-                return object.getSchema().equals(schema);
-            }
-        });
+    public Optional<AttrTO> getPlainAttr(final String schema) {
+        return plainAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
     }
 
     @XmlElementWrapper(name = "derAttrs")
@@ -131,14 +124,8 @@ public class MembershipTO extends RelationshipTO implements AttributableTO {
 
     @JsonIgnore
     @Override
-    public AttrTO getDerAttr(final String schema) {
-        return IterableUtils.find(derAttrs, new Predicate<AttrTO>() {
-
-            @Override
-            public boolean evaluate(final AttrTO object) {
-                return object.getSchema().equals(schema);
-            }
-        });
+    public Optional<AttrTO> getDerAttr(final String schema) {
+        return derAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
     }
 
     @XmlElementWrapper(name = "virAttrs")
@@ -151,13 +138,7 @@ public class MembershipTO extends RelationshipTO implements AttributableTO {
 
     @JsonIgnore
     @Override
-    public AttrTO getVirAttr(final String schema) {
-        return IterableUtils.find(virAttrs, new Predicate<AttrTO>() {
-
-            @Override
-            public boolean evaluate(final AttrTO object) {
-                return object.getSchema().equals(schema);
-            }
-        });
+    public Optional<AttrTO> getVirAttr(final String schema) {
+        return virAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java
index c18b05e..ae4255f 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java
@@ -25,8 +25,6 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.common.lib.AbstractBaseBean;
 
 @XmlRootElement(name = "orgUnit")
@@ -81,13 +79,7 @@ public class OrgUnitTO extends AbstractBaseBean implements EntityTO, ItemContain
 
     @Override
     public ItemTO getConnObjectKeyItem() {
-        return IterableUtils.find(getItems(), new Predicate<ItemTO>() {
-
-            @Override
-            public boolean evaluate(final ItemTO item) {
-                return item.isConnObjectKey();
-            }
-        });
+        return getItems().stream().filter(item -> item.isConnObjectKey()).findFirst().get();
     }
 
     protected boolean addConnObjectKeyItem(final ItemTO connObjectItem) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/ResourceTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/ResourceTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/ResourceTO.java
index 4bc9c0d..6286e93 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/ResourceTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/ResourceTO.java
@@ -23,14 +23,13 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import javax.ws.rs.PathParam;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.common.lib.AbstractBaseBean;
 import org.apache.syncope.common.lib.types.ConnConfProperty;
 import org.apache.syncope.common.lib.types.ConnectorCapability;
@@ -186,14 +185,10 @@ public class ResourceTO extends AbstractBaseBean implements EntityTO {
     }
 
     @JsonIgnore
-    public ProvisionTO getProvision(final String anyType) {
-        return IterableUtils.find(provisions, new Predicate<ProvisionTO>() {
-
-            @Override
-            public boolean evaluate(final ProvisionTO provisionTO) {
-                return anyType != null && anyType.equals(provisionTO.getAnyType());
-            }
-        });
+    public Optional<ProvisionTO> getProvision(final String anyType) {
+        return provisions.stream().filter(
+                provision -> anyType != null && anyType.equals(provision.getAnyType())).
+                findFirst();
     }
 
     @XmlElementWrapper(name = "provisions")

http://git-wip-us.apache.org/repos/asf/syncope/blob/74ee038a/common/lib/src/main/java/org/apache/syncope/common/lib/to/UserTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/UserTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/UserTO.java
index 6deab32..3e9cd4d 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/UserTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/UserTO.java
@@ -24,12 +24,11 @@ import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
@@ -197,14 +196,10 @@ public class UserTO extends AnyTO implements GroupableRelatableTO {
 
     @JsonIgnore
     @Override
-    public RelationshipTO getRelationship(final String type, final String rightKey) {
-        return IterableUtils.find(relationships, new Predicate<RelationshipTO>() {
-
-            @Override
-            public boolean evaluate(final RelationshipTO object) {
-                return type.equals(object.getType()) && rightKey.equals(object.getRightKey());
-            }
-        });
+    public Optional<RelationshipTO> getRelationship(final String type, final String rightKey) {
+        return relationships.stream().filter(
+                relationship -> type.equals(relationship.getType()) && rightKey.equals(relationship.getRightKey())).
+                findFirst();
     }
 
     @XmlElementWrapper(name = "relationships")
@@ -217,14 +212,8 @@ public class UserTO extends AnyTO implements GroupableRelatableTO {
 
     @JsonIgnore
     @Override
-    public MembershipTO getMembership(final String groupKey) {
-        return IterableUtils.find(memberships, new Predicate<MembershipTO>() {
-
-            @Override
-            public boolean evaluate(final MembershipTO object) {
-                return groupKey.equals(object.getGroupKey());
-            }
-        });
+    public Optional<MembershipTO> getMembership(final String groupKey) {
+        return memberships.stream().filter(membership -> groupKey.equals(membership.getGroupKey())).findFirst();
     }
 
     @XmlElementWrapper(name = "memberships")


Mime
View raw message