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> first, Predicate<? super T> second) 

Source Link

Document

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

Usage

From source file:org.apache.beam.sdk.options.PipelineOptionsFactory.java

/**
 * Validates that every non-static or synthetic method is either a known method such as
 * {@link PipelineOptions#as} or a bean property.
 *
 * @param iface The interface to validate.
 * @param klass The proxy class representing the interface.
 *///from w w w .  jav  a2  s  .  c o m
private static void validateMethodsAreEitherBeanMethodOrKnownMethod(Class<? extends PipelineOptions> iface,
        Class<? extends PipelineOptions> klass, List<PropertyDescriptor> descriptors) {
    Set<Method> knownMethods = Sets.newHashSet(IGNORED_METHODS);
    // Ignore synthetic methods
    for (Method method : klass.getMethods()) {
        if (Modifier.isStatic(method.getModifiers()) || method.isSynthetic()) {
            knownMethods.add(method);
        }
    }
    // Ignore methods on the base PipelineOptions interface.
    try {
        knownMethods.add(iface.getMethod("as", Class.class));
        knownMethods.add(iface.getMethod("outputRuntimeOptions"));
        knownMethods.add(iface.getMethod("populateDisplayData", DisplayData.Builder.class));
    } catch (NoSuchMethodException | SecurityException e) {
        throw new RuntimeException(e);
    }
    for (PropertyDescriptor descriptor : descriptors) {
        knownMethods.add(descriptor.getReadMethod());
        knownMethods.add(descriptor.getWriteMethod());
    }
    final Set<String> knownMethodsNames = Sets.newHashSet();
    for (Method method : knownMethods) {
        knownMethodsNames.add(method.getName());
    }

    // Verify that no additional methods are on an interface that aren't a bean property.
    // Because methods can have multiple declarations, we do a name-based comparison
    // here to prevent false positives.
    SortedSet<Method> unknownMethods = new TreeSet<>(MethodComparator.INSTANCE);
    unknownMethods.addAll(Sets.filter(Sets.difference(Sets.newHashSet(iface.getMethods()), knownMethods),
            Predicates.and(NOT_SYNTHETIC_PREDICATE, new Predicate<Method>() {
                @Override
                public boolean apply(@Nonnull Method input) {
                    return !knownMethodsNames.contains(input.getName());
                }
            })));
    checkArgument(unknownMethods.isEmpty(), "Methods %s on [%s] do not conform to being bean properties.",
            FluentIterable.from(unknownMethods).transform(ReflectHelpers.METHOD_FORMATTER), iface.getName());
}

From source file:org.apache.flex.compiler.internal.scopes.ASScope.java

public IDefinition findProperty(ICompilerProject project, String baseName, Predicate<IDefinition> additional,
        Set<INamespaceDefinition> nsSet, DependencyType dt, boolean canEscapeWith) {
    NamespaceSetPredicate nsPred = new NamespaceSetPredicate(project, nsSet);

    List<IDefinition> storage = new ArrayList<IDefinition>();
    Predicate<IDefinition> pred = Predicates.and(additional, nsPred);
    FilteredCollection<IDefinition> defs = new FilteredCollection<IDefinition>(pred, storage);
    findProperty(defs, (CompilerProject) project, baseName, nsPred, dt, false);
    IDefinition def = null;//from   ww  w.j a va 2s.c o  m
    def = getSingleResult(project, storage);
    return filterWith(def, canEscapeWith);
}

From source file:org.apache.flex.compiler.internal.scopes.ASScope.java

/**
 * The main public entry point for the findprop operation in the compiler
 * with an explicit qualifier namespace. This method uses the
 * {@link ASScopeCache} to improve performance.
 *
 * @param project {@link ICompilerProject} whose symbol table is used to
 * resolve namespace references in the "use namespace" set this scope.
 * @param qual {@link INamespaceDefinition} which must match the qualifier
 * namespace of the found {@link IDefinition}.
 * @param baseName base name of the property we are looking for.
 * @param dt The type of dependency that should be added to the dependency
 * graph when resolving this reference across a compilation unit boundary.
 * @return A single {@link IDefinition} to which the specified qualifier and
 * base name resolves to in this scope, or null. Null is returned when no
 * definition is found <b>and</b> when more than one definition is found.
 *///from  ww w  . j av  a2s  .  c  o  m
public IDefinition findPropertyQualified(ICompilerProject project, Predicate<IDefinition> additional,
        INamespaceDefinition qual, String baseName, DependencyType dt) {
    if (qual == null)
        return null;

    NamespaceSetPredicate nsPred = new NamespaceSetPredicate(project, ImmutableSet.of(qual));
    Predicate<IDefinition> pred = Predicates.and(additional, nsPred);
    List<IDefinition> defs = new ArrayList<IDefinition>();
    FilteredCollection<IDefinition> filteredCollection = new FilteredCollection<IDefinition>(pred, defs);
    findProperty(filteredCollection, (CompilerProject) project, baseName, nsPred, dt, false);
    return getSingleResult(project, defs);
}

From source file:com.eucalyptus.cluster.Cluster.java

private void rollbackInstanceEvacuations(final String sourceHost) {
    Predicate<VmInstance> filterHost = new Predicate<VmInstance>() {

        @Override//from  ww w  .  j  a  va 2s.c om
        public boolean apply(@Nullable VmInstance input) {
            String vmHost = URI.create(input.getServiceTag()).getHost();
            return Strings.nullToEmpty(vmHost).equals(sourceHost);
        }
    };
    Predicate<VmInstance> rollbackMigration = new Predicate<VmInstance>() {

        @Override
        public boolean apply(@Nullable VmInstance input) {
            input.abortMigration();
            return true;
        }
    };
    Predicate<VmInstance> filterAndAbort = Predicates.and(this.filterPartition, rollbackMigration);
    Predicate<VmInstance> rollbackMigrationTx = Entities.asTransaction(VmInstance.class, filterAndAbort);
    VmInstances.list(rollbackMigrationTx);
}

From source file:org.apache.flex.compiler.internal.legacy.ASDefinitionFilter.java

/**
 * Generate a predicate that will filter based on the various flags set on
 * the ASDefinitionFilter.//from  w  w  w  .ja  v  a 2 s.c o  m
 * 
 * @param project the Project the lookup is occurring in
 * @param scope the scope where we are performing the lookup
 * @return a Predicate that can be used to filter lookup results according
 * to the settings of the ASDefinitionFilter
 */
public Predicate<IDefinition> computePredicate(ICompilerProject project, ASScope scope) {
    Predicate<IDefinition> pred = null;

    pred = new FilterPredicate(project, scope, this);

    if (fAccessRule instanceof AccessValue.SpecialAccessValue) {
        Predicate<IDefinition> accessValPredicate = computeAccessValuePredicate(project, scope);
        if (accessValPredicate != null) {
            pred = Predicates.and(pred, accessValPredicate);
        }
    }
    if (!includeExcludedClasses()) {
        Predicate<IDefinition> excludePred = new ExcludedPredicate(scope);
        pred = Predicates.and(pred, excludePred);
    }
    return pred;
}

From source file:com.eucalyptus.cluster.Cluster.java

@SuppressWarnings("unchecked")
private void prepareInstanceEvacuations(final String sourceHost) {
    Predicate<VmInstance> filterHost = new Predicate<VmInstance>() {

        @Override/* w  w  w  .j  av a 2s.  com*/
        public boolean apply(@Nullable VmInstance input) {
            String vmHost = URI.create(input.getServiceTag()).getHost();
            return Strings.nullToEmpty(vmHost).equals(sourceHost);
        }
    };
    Predicate<VmInstance> startMigration = new Predicate<VmInstance>() {

        @Override
        public boolean apply(@Nullable VmInstance input) {
            input.startMigration();
            return true;
        }
    };
    Predicate<VmInstance> filterAndAbort = Predicates.and(this.filterPartition, startMigration);
    Predicate<VmInstance> startMigrationTx = Entities.asTransaction(VmInstance.class, filterAndAbort);
    VmInstances.list(startMigrationTx);
}

From source file:com.eucalyptus.compute.vpc.VpcManager.java

private static Predicate<NetworkAclEntry> entryPredicate(final Boolean egress, final Integer ruleNumber) {
    return Predicates.and(
            ruleNumber == null ? Predicates.<NetworkAclEntry>alwaysTrue()
                    : CollectionUtils.propertyPredicate(ruleNumber,
                            NetworkAcls.NetworkAclEntryFilterIntegerFunctions.RULE_NUMBER),
            CollectionUtils.propertyPredicate(egress,
                    NetworkAcls.NetworkAclEntryFilterBooleanFunctions.EGRESS));
}