Example usage for com.google.common.base Predicates and

List of usage examples for com.google.common.base Predicates and

Introduction

In this page you can find the example usage for com.google.common.base Predicates and.

Prototype

public static <T> Predicate<T> and(Predicate<? super T>... components) 

Source Link

Document

Returns a predicate that evaluates to true if each of its components evaluates to true .

Usage

From source file:org.jenkinsci.plugins.bulkbuilder.model.Builder.java

/**
 * Build Jenkins projects//from   w  w  w  . j  a va  2  s .  c o m
 */
protected int build(ArrayList filters) {
    int i = 0;

    // Build composite predicate of all build prefs
    Predicate<AbstractProject<?, ?>> compositePredicate = Predicates.and(filters);

    List<AbstractProject<?, ?>> projects = getProjects(this.view);

    // Use composite predicate to identify target projects
    Iterable<AbstractProject<?, ?>> targetProjects = Iterables.filter(projects, compositePredicate);

    for (AbstractProject<?, ?> project : targetProjects) {
        LOGGER.log(Level.FINE, "Scheduling build for job '" + project.getDisplayName() + "'");
        if (performBuildProject(project)) {
            i++;
        }
    }

    return i;
}

From source file:org.sonar.core.review.ReviewDao.java

public Collection<ReviewDto> selectOpenByResourceId(long resourceId,
        @Nullable Predicate<ReviewDto>... predicates) {
    Collection<ReviewDto> reviews = cacheByResource.getUnchecked(resourceId);
    if (!reviews.isEmpty() && predicates != null) {
        reviews = Collections2.filter(reviews, Predicates.and(predicates));
    }/* ww  w .  ja  v a  2  s  . c  o m*/
    return reviews;
}

From source file:net.derquinse.common.meta.MetaFlag.java

/**
 * Returns a predicate that evaluates to {@code true} if this flag and each of the provided
 * components evaluates to {@code true}. The components are evaluated in order (after the flag),
 * and evaluation will be "short-circuited" as soon as a false predicate is found. It defensively
 * copies the iterable passed in, so future changes to it won't alter the behavior of this
 * predicate./*from w  ww  . j  a  v  a  2 s. co m*/
 */
public final Predicate<C> and(Iterable<? extends Predicate<? super C>> components) {
    return Predicates.and(Iterables.concat(ImmutableList.of(this), components));
}

From source file:eu.bcvsolutions.idm.core.api.config.swagger.AbstractSwaggerConfig.java

/**
 * Expose endpoints from given base packages. Security endpoint will be in all docs.
 *
 * @param basePackages/*from w w w  .  j a v  a  2 s.c o m*/
 * @return
 */
protected Predicate<RequestHandler> getApis(String... basePackages) {
    Assert.notEmpty(basePackages);
    //
    List<Predicate<RequestHandler>> predicates = new ArrayList<>();
    // endpoints from packages
    predicates.add(Predicates.or(Arrays.asList(basePackages).stream().map(RequestHandlerSelectors::basePackage)
            .collect(Collectors.toList())));
    // and with annotations
    predicates.add(RequestHandlerSelectors.withClassAnnotation(Api.class));
    //
    return Predicates.and(predicates);
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.log.LogListener.java

@SuppressWarnings("unchecked")
@VisibleForTesting//from  ww  w. j a  va2  s.co m
public static LogListener createLogListener(Settings settings, ServerConfiguration configuration,
        ReportHistory history, EventBus bus, ExpiringReportHistory expiringReportHistory,
        ProblemsDatabaseService serverProblemsStatusIndex) {
    Predicate<? super IStatus>[] statusPredicates = decorateForDebug(
            // @formatter:off
            new AcceptProductPredicate(configuration), new EclipseBuildIdPresentPredicate(),
            new ErrorStatusOnlyPredicate(), new ActiveShellPredicate(), new HistoryReadyPredicate(history),
            new IgnorePatternPredicate(configuration.getIgnoredPluginMessagesPatterns()),
            new ReporterNotDisabledPredicate(settings), new WhitelistedPluginIdPresentPredicate(configuration),
            new WorkbenchRunningPredicate(PlatformUI.getWorkbench()));
    // @formatter:on
    Predicate<IStatus> statusFilters = Predicates.and(statusPredicates);

    Predicate<? super ErrorReport>[] reportPredicates = decorateForDebug(
            // @formatter:off
            new AcceptOtherPackagesPredicate(configuration), new AcceptUiFreezesPredicate(configuration),
            new CompleteUiFreezeReportPredicate(),
            new ProblemDatabaseIgnoredPredicate(serverProblemsStatusIndex, settings),
            new ReportsHistoryPredicate(expiringReportHistory, settings),
            new UnseenErrorReportPredicate(history, settings),
            new ValidSizeErrorReportPredicate(configuration));
    // @formatter:on
    Predicate<ErrorReport> reportFilters = Predicates.and(reportPredicates);
    LogListener listener = new LogListener(statusFilters, reportFilters, settings, configuration, bus);
    return listener;
}

From source file:org.opensaml.security.credential.impl.AbstractCriteriaFilteringCredentialResolver.java

/** {@inheritDoc} */
@Nonnull//from   w w  w .  ja  va 2  s. c  o m
public Iterable<Credential> resolve(@Nullable final CriteriaSet criteriaSet) throws ResolverException {
    Iterable<Credential> storeCandidates = resolveFromSource(criteriaSet);
    Set<Predicate<Credential>> predicates = getPredicates(criteriaSet);
    if (predicates.isEmpty()) {
        return storeCandidates;
    } else {
        Predicate<Credential> aggregatePredicate = null;
        if (isSatisfyAllPredicates()) {
            aggregatePredicate = Predicates.and(predicates);
        } else {
            aggregatePredicate = Predicates.or(predicates);
        }
        return Iterables.filter(storeCandidates, aggregatePredicate);
    }
}

From source file:br.com.ingenieux.mojo.beanstalk.cmd.env.waitfor.WaitForEnvironmentCommand.java

public Collection<EnvironmentDescription> lookupInternal(WaitForEnvironmentContext context) {
    List<Predicate<EnvironmentDescription>> envPredicates = getEnvironmentDescriptionPredicate(context);

    DescribeEnvironmentsRequest req = new DescribeEnvironmentsRequest()
            .withApplicationName(context.getApplicationName()).withIncludeDeleted(true);

    final List<EnvironmentDescription> envs = parentMojo.getService().describeEnvironments(req)
            .getEnvironments();//from w w  w. ja v a  2s  .  com

    return Collections2.filter(envs, Predicates.and(envPredicates));
}

From source file:com.b2international.snowowl.datastore.request.SearchMergeRequest.java

@Override
public MergeCollection execute(RepositoryContext context) {

    final List<Predicate<Merge>> predicates = Lists.newArrayList();

    if (options.containsKey("source")) {
        predicates.add(new SourcePredicate(options.getString("source")));
    }//from w  ww .j  a  va  2s. c o  m
    if (options.containsKey("target")) {
        predicates.add(new TargetPredicate(options.getString("target")));
    }
    if (options.containsKey("status")) {
        predicates.add(new StatusPredicate(options.get("status", Merge.Status.class)));
    }

    return context.service(MergeService.class).search(Predicates.and(predicates));
}

From source file:org.richfaces.demo.RF10888.java

public Object getFilteredData() {
    @SuppressWarnings("unchecked")
    List<Person> resultList = (List<Person>) persistenceService.getEntityManager()
            .createQuery("SELECT p from Person as p").getResultList();

    List<Predicate<Person>> predicates = Lists.newArrayList();

    if (!Strings.isNullOrEmpty(name)) {
        predicates.add(contains(name, new Function<Person, CharSequence>() {
            public CharSequence apply(Person input) {
                return input.getName();
            }//from  w  ww .  j  a  v  a  2 s.  com
        }));
    }
    if (!Strings.isNullOrEmpty(surname)) {
        predicates.add(contains(surname, new Function<Person, CharSequence>() {
            public CharSequence apply(Person input) {
                return input.getSurname();
            }
        }));
    }
    if (!Strings.isNullOrEmpty(email)) {
        predicates.add(contains(email, new Function<Person, CharSequence>() {
            public CharSequence apply(Person input) {
                return input.getEmail();
            }
        }));
    }

    return Lists.newArrayList(Collections2.filter(resultList, Predicates.and(predicates)));
}

From source file:org.spongepowered.common.config.type.GlobalConfig.java

public Map<String, Predicate<InetAddress>> getIpSets() {
    return ImmutableMap
            .copyOf(Maps.transformValues(this.ipSets, new Function<List<IpSet>, Predicate<InetAddress>>() {
                @Nullable/*from w ww. ja v a 2s . co m*/
                @Override
                public Predicate<InetAddress> apply(List<IpSet> input) {
                    return Predicates.and(input);
                }
            }));
}