Example usage for org.apache.commons.collections4 CollectionUtils forAllDo

List of usage examples for org.apache.commons.collections4 CollectionUtils forAllDo

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils forAllDo.

Prototype

@Deprecated
public static <T, C extends Closure<? super T>> C forAllDo(final Iterable<T> collection, final C closure) 

Source Link

Document

Executes the given closure on each element in the collection.

Usage

From source file:com.link_intersystems.lang.reflect.ChooseMostSpecificMemberStrategy.java

protected Member2<?> chooseMostSpecificImpl(List<? extends Member2<?>> potentiallyApplicable) {
    boolean containsVarargsInvokable = CollectionUtils.exists(potentiallyApplicable,
            VarargInvokablePredicate.INSTANCE);
    Member2<?> mostSpecific = null;
    if (containsVarargsInvokable) {
        Member2<?> noVarargsMethod = (Member2<?>) CollectionUtils.find(potentiallyApplicable,
                NotPredicate.notPredicate(VarargInvokablePredicate.INSTANCE));
        mostSpecific = noVarargsMethod;//from   w  w  w  .  j  a  va 2  s.co m
    } else {
        MostSpecificInvokableClosure mostSpecificInvokableClosure = new MostSpecificInvokableClosure();
        CollectionUtils.forAllDo(potentiallyApplicable, mostSpecificInvokableClosure);
        mostSpecific = mostSpecificInvokableClosure.getMostSpecific();
    }
    return mostSpecific;
}

From source file:org.apache.syncope.core.misc.security.SyncopeGrantedAuthority.java

public void addRealms(final List<String> newRealms) {
    CollectionUtils.forAllDo(newRealms, new Closure<String>() {

        @Override/* w w w. j  av  a 2s.  com*/
        public void execute(final String newRealm) {
            addRealm(newRealm);
        }
    });
}

From source file:org.apache.syncope.core.misc.security.SyncopeUserDetailsService.java

@Override
public UserDetails loadUserByUsername(final String username) {
    final Set<SyncopeGrantedAuthority> authorities = new HashSet<>();
    if (anonymousUser.equals(username)) {
        authorities.add(new SyncopeGrantedAuthority(Entitlement.ANONYMOUS));
    } else if (adminUser.equals(username)) {
        CollectionUtils//w w  w.  jav a  2s .  co  m
                .collect(
                        IteratorUtils.filteredIterator(Entitlement.values().iterator(),
                                PredicateUtils
                                        .notPredicate(PredicateUtils.equalPredicate(Entitlement.ANONYMOUS))),
                        new Transformer<String, SyncopeGrantedAuthority>() {

                            @Override
                            public SyncopeGrantedAuthority transform(final String entitlement) {
                                return new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM);
                            }
                        }, authorities);
    } else {
        org.apache.syncope.core.persistence.api.entity.user.User user = userDAO.find(username);
        if (user == null) {
            throw new UsernameNotFoundException("Could not find any user with id " + username);
        }

        // Give entitlements as assigned by roles (with realms, where applicable) - assigned either
        // statically and dynamically
        for (final Role role : userDAO.findAllRoles(user)) {
            CollectionUtils.forAllDo(role.getEntitlements(), new Closure<String>() {

                @Override
                public void execute(final String entitlement) {
                    SyncopeGrantedAuthority authority = new SyncopeGrantedAuthority(entitlement);
                    authorities.add(authority);

                    List<String> realmFullPahs = new ArrayList<>();
                    CollectionUtils.collect(role.getRealms(), new Transformer<Realm, String>() {

                        @Override
                        public String transform(final Realm realm) {
                            return realm.getFullPath();
                        }
                    }, realmFullPahs);
                    authority.addRealms(realmFullPahs);
                }
            });
        }

        // Give group entitlements for owned groups
        for (Group group : groupDAO.findOwnedByUser(user.getKey())) {
            for (String entitlement : Arrays.asList(Entitlement.GROUP_READ, Entitlement.GROUP_UPDATE,
                    Entitlement.GROUP_DELETE)) {

                SyncopeGrantedAuthority authority = new SyncopeGrantedAuthority(entitlement);
                authority.addRealm(
                        RealmUtils.getGroupOwnerRealm(group.getRealm().getFullPath(), group.getKey()));
                authorities.add(authority);
            }
        }
    }

    return new User(username, "<PASSWORD_PLACEHOLDER>", authorities);
}