Example usage for com.google.common.collect Iterators any

List of usage examples for com.google.common.collect Iterators any

Introduction

In this page you can find the example usage for com.google.common.collect Iterators any.

Prototype

public static <T> boolean any(Iterator<T> iterator, Predicate<? super T> predicate) 

Source Link

Document

Returns true if one or more elements returned by iterator satisfy the given predicate.

Usage

From source file:com.facebook.buck.parser.DaemonicParserState.java

/**
 * @param path The {@link Path} to test.
 * @return true if {@code path} is a temporary or backup file.
 *//*from www  .j av  a  2s .c  om*/
private boolean isTempFile(Cell cell, Path path) {
    final String fileName = path.getFileName().toString();
    Predicate<Pattern> patternMatches = pattern -> pattern.matcher(fileName).matches();
    return Iterators.any(cell.getTempFilePatterns().iterator(), patternMatches);
}

From source file:ome.logic.AdminImpl.java

@RolesAllowed("user")
@Transactional(readOnly = false)//from   w  ww.  j  a v a 2  s .c o m
public void removeGroups(final Experimenter user, final ExperimenterGroup... groups) {
    if (user == null) {
        return;
    }
    if (groups == null) {
        return;
    }

    adminOrPiOfGroups(null, groups);

    final Roles roles = getSecurityRoles();
    final boolean removeSystemOrUser = Iterators.any(Iterators.forArray(groups),
            Predicates.or(roles.IS_SYSTEM_GROUP, roles.IS_USER_GROUP));
    if (removeSystemOrUser && roles.isRootUser(user)) {
        throw new ValidationException("experimenter '" + roles.getRootName() + "' may not be removed from the '"
                + roles.getSystemGroupName() + "' or '" + roles.getUserGroupName() + "' group");
    }
    final EventContext eventContext = getEventContext();
    final boolean userOperatingOnThemself = eventContext.getCurrentUserId().equals(user.getId());
    if (removeSystemOrUser && userOperatingOnThemself) {
        throw new ValidationException("experimenters may not remove themselves from the '"
                + roles.getSystemGroupName() + "' or '" + roles.getUserGroupName() + "' group");
    }

    /* The properly loaded user object is needed for collecting the group-experimenter map. */
    final Experimenter loadedUser = userProxy(user.getId());

    final Set<Long> resultingGroupIds = new HashSet<Long>();
    for (final GroupExperimenterMap map : loadedUser.<GroupExperimenterMap>collectGroupExperimenterMap(null)) {
        resultingGroupIds.add(map.parent().getId());
    }
    for (final ExperimenterGroup group : groups) {
        resultingGroupIds.remove(group.getId());
    }
    if (resultingGroupIds.isEmpty()) {
        throw new ValidationException("experimenter must remain a member of some group");
    } else if (resultingGroupIds.equals(Collections.singleton(roles.getUserGroupId()))) {
        throw new ValidationException("experimenter cannot be a member of only the '" + roles.getUserGroupName()
                + "' group, a different default group is also required");
    }
    roleProvider.removeGroups(user, groups);

    getBeanHelper().getLogger().info(String.format("Removed user %s from groups %s", user, groups));
}

From source file:com.facebook.buck.parser.ParallelDaemonicParserState.java

/**
 * @param path The {@link Path} to test.
 * @return true if {@code path} is a temporary or backup file.
 *///from w  w  w  . ja  va2  s . c  o  m
private boolean isTempFile(Cell cell, Path path) {
    final String fileName = path.getFileName().toString();
    Predicate<Pattern> patternMatches = new Predicate<Pattern>() {
        @Override
        public boolean apply(Pattern pattern) {
            return pattern.matcher(fileName).matches();
        }
    };
    return Iterators.any(cell.getTempFilePatterns().iterator(), patternMatches);
}

From source file:com.microsoft.intellij.helpers.o365.Office365ManagerImpl.java

@Override
@NotNull/*  w ww .j av a  2s.co  m*/
public ListenableFuture<List<ServicePrincipal>> getO365ServicePrincipalsForApp(
        @NotNull final Application application) {
    return requestFutureWithToken(new RequestCallback<ListenableFuture<List<ServicePrincipal>>>() {
        @Override
        public ListenableFuture<List<ServicePrincipal>> execute() throws Throwable {
            @SuppressWarnings("unchecked")
            ListenableFuture<List<ServicePrincipal>>[] futures = new ListenableFuture[] {
                    getServicePrincipalsForApp(application), getServicePrincipalsForO365() };

            final String[] filterAppIds = new String[] { ServiceAppIds.SHARE_POINT, ServiceAppIds.EXCHANGE,
                    ServiceAppIds.AZURE_ACTIVE_DIRECTORY };

            return Futures.transform(Futures.allAsList(futures),
                    new AsyncFunction<List<List<ServicePrincipal>>, List<ServicePrincipal>>() {
                        @Override
                        public ListenableFuture<List<ServicePrincipal>> apply(
                                List<List<ServicePrincipal>> lists) throws Exception {
                            // According to Guava documentation for allAsList, the list of results is in the
                            // same order as the input list. So first we get the service principals for the app
                            // filtered for O365 and Graph service principals.
                            final List<ServicePrincipal> servicePrincipalsForApp = Lists.newArrayList(
                                    Iterables.filter(lists.get(0), new Predicate<ServicePrincipal>() {
                                        @Override
                                        public boolean apply(final ServicePrincipal servicePrincipal) {
                                            // we are only interested in O365 and Graph service principals
                                            return Iterators.any(Iterators.forArray(filterAppIds),
                                                    new Predicate<String>() {
                                                        @Override
                                                        public boolean apply(String appId) {
                                                            return appId.equals(servicePrincipal.getappId());
                                                        }
                                                    });
                                        }
                                    }));

                            // next we get the O365/graph service principals
                            final List<ServicePrincipal> servicePrincipalsForO365 = lists.get(1);

                            // then we add service principals from servicePrincipalsForO365 to servicePrincipalsForApp
                            // where the service principal is not available in the latter
                            Iterable<ServicePrincipal> servicePrincipalsToBeAdded = Iterables
                                    .filter(servicePrincipalsForO365, new Predicate<ServicePrincipal>() {
                                        @Override
                                        public boolean apply(ServicePrincipal servicePrincipal) {
                                            return !servicePrincipalsForApp.contains(servicePrincipal);
                                        }
                                    });
                            Iterables.addAll(servicePrincipalsForApp, servicePrincipalsToBeAdded);

                            // assign the appid to the service principal and reset permissions on new service principals;
                            // we do Lists.newArrayList calls below to create a copy of the service lists because Lists.transform
                            // invokes the transformation function lazily and this causes problems for us; we force immediate
                            // evaluation of our transfomer by copying the elements to a new list
                            List<ServicePrincipal> servicePrincipals = Lists
                                    .newArrayList(Lists.transform(servicePrincipalsForApp,
                                            new Function<ServicePrincipal, ServicePrincipal>() {
                                                @Override
                                                public ServicePrincipal apply(
                                                        ServicePrincipal servicePrincipal) {
                                                    if (!servicePrincipal.getappId()
                                                            .equals(application.getappId())) {
                                                        servicePrincipal.setappId(application.getappId());
                                                        servicePrincipal.setoauth2Permissions(
                                                                Lists.newArrayList(Lists.transform(
                                                                        servicePrincipal.getoauth2Permissions(),
                                                                        new Function<OAuth2Permission, OAuth2Permission>() {
                                                                            @Override
                                                                            public OAuth2Permission apply(
                                                                                    OAuth2Permission oAuth2Permission) {
                                                                                oAuth2Permission
                                                                                        .setisEnabled(false);
                                                                                return oAuth2Permission;
                                                                            }
                                                                        })));
                                                    }

                                                    return servicePrincipal;
                                                }
                                            }));

                            return Futures.immediateFuture(servicePrincipals);
                        }
                    });
        }
    });
}

From source file:com.facebook.buck.parser.Parser.java

/**
 * @param path The {@link Path} to test.
 * @return true if {@code path} is a temporary or backup file.
 *//* www .j  av a 2 s .  co  m*/
private boolean isTempFile(Path path) {
    final String fileName = path.getFileName().toString();
    Predicate<Pattern> patternMatches = new Predicate<Pattern>() {
        @Override
        public boolean apply(Pattern pattern) {
            return pattern.matcher(fileName).matches();
        }
    };
    return Iterators.any(tempFilePatterns.iterator(), patternMatches);
}

From source file:com.microsoftopentechnologies.intellij.helpers.o365.Office365RestAPIManager.java

@Override
public ListenableFuture<List<ServicePrincipal>> getO365ServicePrincipalsForApp(
        @NotNull final Application application) throws ParseException {
    return requestWithToken(new RequestCallback<List<ServicePrincipal>>() {
        @Override/*from   www.j  a v a2 s.  co  m*/
        public ListenableFuture<List<ServicePrincipal>> execute() throws ParseException {
            @SuppressWarnings("unchecked")
            ListenableFuture<List<ServicePrincipal>>[] futures = new ListenableFuture[] {
                    getServicePrincipalsForApp(application), getServicePrincipalsForO365() };

            final String[] filterAppIds = new String[] { ServiceAppIds.SHARE_POINT, ServiceAppIds.EXCHANGE,
                    ServiceAppIds.AZURE_ACTIVE_DIRECTORY };

            return Futures.transform(Futures.allAsList(futures),
                    new AsyncFunction<List<List<ServicePrincipal>>, List<ServicePrincipal>>() {
                        @Override
                        public ListenableFuture<List<ServicePrincipal>> apply(
                                List<List<ServicePrincipal>> lists) throws Exception {
                            // According to Guava documentation for allAsList, the list of results is in the
                            // same order as the input list. So first we get the service principals for the app
                            // filtered for O365 and Graph service principals.
                            final List<ServicePrincipal> servicePrincipalsForApp = Lists.newArrayList(
                                    Iterables.filter(lists.get(0), new Predicate<ServicePrincipal>() {
                                        @Override
                                        public boolean apply(final ServicePrincipal servicePrincipal) {
                                            // we are only interested in O365 and Graph service principals
                                            return Iterators.any(Iterators.forArray(filterAppIds),
                                                    new Predicate<String>() {
                                                        @Override
                                                        public boolean apply(String appId) {
                                                            return appId.equals(servicePrincipal.getappId());
                                                        }
                                                    });
                                        }
                                    }));

                            // next we get the O365/graph service principals
                            final List<ServicePrincipal> servicePrincipalsForO365 = lists.get(1);

                            // then we add service principals from servicePrincipalsForO365 to servicePrincipalsForApp
                            // where the service principal is not available in the latter
                            Iterable<ServicePrincipal> servicePrincipalsToBeAdded = Iterables
                                    .filter(servicePrincipalsForO365, new Predicate<ServicePrincipal>() {
                                        @Override
                                        public boolean apply(ServicePrincipal servicePrincipal) {
                                            return !servicePrincipalsForApp.contains(servicePrincipal);
                                        }
                                    });
                            Iterables.addAll(servicePrincipalsForApp, servicePrincipalsToBeAdded);

                            // assign the appid to the service principal and reset permissions on new service principals;
                            // we do Lists.newArrayList calls below to create a copy of the service lists because Lists.transform
                            // invokes the transformation function lazily and this causes problems for us; we force immediate
                            // evaluation of our transfomer by copying the elements to a new list
                            List<ServicePrincipal> servicePrincipals = Lists
                                    .newArrayList(Lists.transform(servicePrincipalsForApp,
                                            new Function<ServicePrincipal, ServicePrincipal>() {
                                                @Override
                                                public ServicePrincipal apply(
                                                        ServicePrincipal servicePrincipal) {
                                                    if (!servicePrincipal.getappId()
                                                            .equals(application.getappId())) {
                                                        servicePrincipal.setappId(application.getappId());
                                                        servicePrincipal.setoauth2Permissions(
                                                                Lists.newArrayList(Lists.transform(
                                                                        servicePrincipal.getoauth2Permissions(),
                                                                        new Function<OAuth2Permission, OAuth2Permission>() {
                                                                            @Override
                                                                            public OAuth2Permission apply(
                                                                                    OAuth2Permission oAuth2Permission) {
                                                                                oAuth2Permission
                                                                                        .setisEnabled(false);
                                                                                return oAuth2Permission;
                                                                            }
                                                                        })));
                                                    }

                                                    return servicePrincipal;
                                                }
                                            }));

                            return Futures.immediateFuture(servicePrincipals);
                        }
                    });
        }
    });
}