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:com.eucalyptus.autoscaling.common.internal.activities.PersistenceScalingActivities.java

@Override
public <T> List<T> list(@Nullable final OwnerFullName ownerFullName,
        @Nullable final AutoScalingGroupMetadata group, @Nonnull final Collection<String> activityIds,
        @Nonnull final Predicate<? super ScalingActivity> filter,
        @Nonnull final Function<? super ScalingActivity, T> transform) throws AutoScalingMetadataException {
    final ScalingActivity example = ScalingActivity.withOwner(ownerFullName);
    final Conjunction conjunction = Restrictions.conjunction();
    final Collection<Predicate<? super ScalingActivity>> predicates = Lists.newArrayList();
    predicates.add(filter);/*from  w  w w  .  j a  v  a2s.  c om*/
    if (group != null) {
        predicates.add(CollectionUtils.propertyPredicate(group.getArn(),
                Functions.compose(AutoScalingMetadatas.toArn(), ScalingActivities.group())));
        conjunction.add(Restrictions.eq("autoScalingGroupName", group.getDisplayName()));
    }
    if (!activityIds.isEmpty()) {
        conjunction.add(Restrictions.in("displayName", activityIds));
    }
    return persistenceSupport.listByExample(example, Predicates.and(predicates), conjunction,
            Collections.<String, String>emptyMap(), transform);
}

From source file:org.sonatype.nexus.repository.http.HttpConditions.java

/**
 * Builds a {@link Predicate} that contains conditions in passed in {@link Request} or {@code null} if
 * request does not contains any condition. The predicate applies to {@link Response} if it meets all the conditions
 * found (they all are logically AND bound).
 *//*from  ww w  . j a  va  2 s.c  o m*/
@Nullable
public static Predicate<Response> requestPredicate(@Nonnull final Request request) {
    checkNotNull(request);
    final List<Predicate<Response>> predicates = new ArrayList<>();
    final Predicate<Response> ifModifiedSince = ifModifiedSince(request);
    if (ifModifiedSince != null) {
        predicates.add(ifModifiedSince);
    }
    final Predicate<Response> ifUnmodifiedSince = ifUnmodifiedSince(request);
    if (ifUnmodifiedSince != null) {
        predicates.add(ifUnmodifiedSince);
    }
    final Predicate<Response> ifMatch = ifMatch(request);
    if (ifMatch != null) {
        predicates.add(ifMatch);
    }
    final Predicate<Response> ifNoneMatch = ifNoneMatch(request);
    if (ifNoneMatch != null) {
        predicates.add(ifNoneMatch);
    }

    if (!predicates.isEmpty()) {
        return Predicates.and(predicates);
    }
    return null;
}

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

public Predicate<InetAddress> getIpSet(String name) {
    return this.ipSets.containsKey(name) ? Predicates.and(this.ipSets.get(name)) : null;
}

From source file:ezbake.data.graph.blueprints.visibility.VisibilityFilterQuery.java

/**
 * Filter an iterable of elements against the combination of all
 * predicates on this query./*from www .  j a v  a 2  s  . c o m*/
 *
 * @param it iterable of elements
 * @return elements that match every predicated on this query
 */
protected <T extends Element> Iterable<T> filterElements(Iterable<T> it) {
    return Iterables.filter(it, Predicates.and(predicates));
}

From source file:com.wavemaker.tools.apidocs.tools.parser.util.MethodUtils.java

/**
 * It will returns all Non static {@link Method}s of given {@link Class}.
 *
 * @param type {@link Class} to be scanned for methods.
 * @param predicates custom predicates to filter.
 * @return {@link Set} of filtered {@link Method}s.
 *///from  w w w .ja v a2s  . com
public static Set<Method> getAllNonStaticMethods(Class<?> type, Predicate<? super Method>... predicates) {
    List<Predicate<? super Method>> predicateList = new LinkedList<>();

    predicateList.add(NonStaticMemberPredicate.getInstance());

    if (ArrayUtils.isNotEmpty(predicates)) {
        predicateList.addAll(Arrays.asList(predicates));
    }

    return getMethods(type, Predicates.and(predicateList));

}

From source file:org.eclipse.papyrus.uml.diagram.common.listeners.AbstractPapyrusModifcationTriggerListener.java

/**
 * Get the referencing views/*from   w ww.j a va  2  s  .  c  o  m*/
 * @param oldEObject
 * @param predicates Additionnal predecate use to speciy search
 * @return
 */
protected Iterable<View> getReferencingView(EObject oldEObject, Predicate<? super View>... predicates) {
    ECrossReferenceAdapter eCrossReferencer = CrossReferenceAdapter.getCrossReferenceAdapter(oldEObject);
    Collection<Setting> settings = eCrossReferencer.getInverseReferences(oldEObject, false);
    Predicate<Setting> predicate = new Predicate<Setting>() {

        public boolean apply(Setting input) {
            EObject from = input.getEObject();
            /*
             * Is a view
             */
            if (from instanceof View
                    && NotationPackage.Literals.VIEW__ELEMENT.equals(input.getEStructuralFeature())) {
                return true;
            }
            return false;
        }
    };

    Iterable<Setting> referencingView = Iterables.filter(settings, predicate);
    Iterable<View> views = Iterables.transform(referencingView, new Function<Setting, View>() {

        public View apply(Setting from) {
            return (View) from.getEObject();
        }
    });

    return Iterables.filter(views, Predicates.and(predicates));
}

From source file:org.sonatype.nexus.plugins.capabilities.internal.rest.StoresResource.java

/**
 * Returns repositories filtered based on query parameters.
 *///from  w  w w  .jav  a 2  s. c  o  m
@GET
@Path("/repositories")
@Produces({ APPLICATION_XML, APPLICATION_JSON })
@RequiresPermissions("nexus:repositories:read")
public List<SelectableEntryXO> getRepositories(
        final @QueryParam(RepositoryCombobox.ALL_REPOS_ENTRY) Boolean allReposEntry,
        final @QueryParam(RepositoryCombobox.REGARDLESS_VIEW_PERMISSIONS) Boolean regardlessViewPermissions,
        final @QueryParam(RepositoryCombobox.FACET) List<String> facets,
        final @QueryParam(RepositoryCombobox.CONTENT_CLASS) List<String> contentClasses) {
    final Predicate<Repository> predicate = Predicates.and(removeNulls(
            hasRightsToView(regardlessViewPermissions), hasAnyOfFacets(facets), hasNoneOfFacets(facets),
            hasAnyOfContentClasses(contentClasses), hasNoneOfContentClasses(contentClasses)));

    List<SelectableEntryXO> entries = Lists.transform(Lists
            .newArrayList(Iterables.filter(repositoryRegistry.getRepositories(), new Predicate<Repository>() {
                @Override
                public boolean apply(@Nullable final Repository input) {
                    return input != null && predicate.apply(input);
                }
            })), new Function<Repository, SelectableEntryXO>() {
                @Override
                public SelectableEntryXO apply(final Repository input) {
                    return new SelectableEntryXO().withId(input.getId()).withName(input.getName());
                }
            });

    if (allReposEntry != null && allReposEntry) {
        entries = Lists.newArrayList(entries);
        entries.add(0, new SelectableEntryXO().withId("*").withName(messages.allRepositoriesName()));
    }

    return entries;
}

From source file:cc.arduino.contributions.packages.ui.ContributionIndexTableModel.java

public void updateIndexFilter(String filters[], Predicate<ContributedPlatform>... additionalFilters) {
    contributions.clear();// ww w. j  av a  2  s  .  c o  m
    Predicate<ContributedPlatform> filter = Predicates.and(additionalFilters);
    for (ContributedPackage pack : index.getPackages()) {
        for (ContributedPlatform platform : pack.getPlatforms()) {
            if (!filter.apply(platform)) {
                continue;
            }
            if (!stringContainsAll(platform.getName(), filters))
                continue;
            addContribution(platform);
        }
    }
    fireTableDataChanged();
}

From source file:clocker.docker.location.strategy.affinity.AffinityRules.java

public AffinityRules parse(Iterable<String> rules) {
    List<Predicate<Entity>> predicates = Lists.newArrayList();
    for (String rule : rules) {
        Predicate<Entity> predicate = predicate(rule);
        predicates.add(predicate);/*  w w w  .  j  a v a  2 s . c  o  m*/
    }

    affinityRules = Predicates.and(predicates);
    return this;
}

From source file:cc.arduino.contributions.libraries.ui.LibrariesIndexTableModel.java

public void updateIndexFilter(String filters[], Predicate<ContributedLibrary>... additionalFilters) {
    selectedCategoryFilter = Predicates.and(additionalFilters);
    selectedFilters = filters;//w w w. j  a v  a  2 s . c o  m
    update();
}