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

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

Introduction

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

Prototype

public static <T> Predicate<T> in(Collection<? extends T> target) 

Source Link

Document

Returns a predicate that evaluates to true if the object reference being tested is a member of the given collection.

Usage

From source file:us.eharning.atomun.mnemonic.spi.electrum.v2.MnemonicBuilderSpiImpl.java

/**
 * Checks that the given extension parameter is valid.
 *
 * @param parameter//from  ww  w  . j  av  a2 s .  co  m
 *         instance containing extension parameters.
 *
 * @throws IllegalArgumentException
 *         if the parameter contains unknown parameters.
 */
private static void checkExtensionNames(ExtensionBuilderParameter parameter) {
    Map<String, Object> extensions = parameter.getExtensions();
    if (!KNOWN_EXTENSION_NAMES.containsAll(extensions.keySet())) {
        Iterable<String> unknownNames = Iterables.filter(extensions.keySet(),
                Predicates.not(Predicates.in(KNOWN_EXTENSION_NAMES)));
        throw new IllegalArgumentException(
                "Found unhandled extension names: " + Iterables.toString(unknownNames));
    }
}

From source file:com.eucalyptus.auth.ws.EuareRequestLoggingFilter.java

private boolean isAction(final Collection<String> parametersOrBody, final Iterable<String> actionNvps) {
    return Iterables.tryFind(actionNvps, Predicates.in(parametersOrBody)).isPresent();
}

From source file:org.pentaho.di.trans.dataservice.serialization.ServiceTrans.java

public static Predicate<ServiceTrans> isReferenceTo(final TransMeta transMeta) {
    return new Predicate<ServiceTrans>() {
        final Set<Reference> references = ImmutableSet.copyOf(references(transMeta));

        @Override// ww w  .j  a  va2  s. c  om
        public boolean apply(ServiceTrans serviceTrans) {
            return Iterables.any(serviceTrans.getReferences(), Predicates.in(references));
        }
    };
}

From source file:net.automatalib.util.graphs.ShortestPaths.java

public static <N, E> Path<N, E> shortestPath(IndefiniteGraph<N, E> graph, N start, int limit,
        Collection<?> targets) {
    return shortestPath(graph, start, limit, Predicates.in(targets));
}

From source file:org.eclipse.emf.compare.rcp.internal.match.MatchEngineFactoryRegistryWrapper.java

/**
 * Return a Collection of enabled {@link IMatchEngine.Factory}.
 * /*w w w  .j av a2  s.  com*/
 * @return Collection<IMatchEngine.Factory>
 */
private Collection<IMatchEngine.Factory> getEnabledFactories() {
    Function<IItemDescriptor<Factory>, Factory> toFactoryFunction = AbstractItemDescriptor.getItemFunction();

    Collection<IItemDescriptor<Factory>> enableFactories = Collections2.filter(registry.getItemDescriptors(),
            Predicates.not(Predicates.in(getDisabledEngines())));
    return Collections2.transform(enableFactories, toFactoryFunction);
}

From source file:org.apache.jackrabbit.oak.upgrade.nodestate.AbstractDecoratedNodeState.java

/**
 * Convenience method to help implementations that hide nodes set the
 * :childOrder (OAK_CHILD_ORDER) property to its correct value.
 * <br>/*from   ww  w .  j  a va2 s.  com*/
 * Intended to be used to implement {@link #decorateProperty(PropertyState)}.
 *
 * @param nodeState The current node state.
 * @param propertyState The property that chould be checked.
 * @return The original propertyState, unless the property is called {@code :childOrder}.
 */
protected static PropertyState fixChildOrderPropertyState(NodeState nodeState, PropertyState propertyState) {
    if (propertyState != null && OAK_CHILD_ORDER.equals(propertyState.getName())) {
        final Collection<String> childNodeNames = new ArrayList<String>();
        Iterables.addAll(childNodeNames, nodeState.getChildNodeNames());
        final Iterable<String> values = Iterables.filter(propertyState.getValue(Type.NAMES),
                Predicates.in(childNodeNames));
        return PropertyStates.createProperty(OAK_CHILD_ORDER, values, Type.NAMES);
    }
    return propertyState;
}

From source file:org.jclouds.compute.callables.SudoAwareInitManager.java

public ExecResponse runAction(String action) {
    ExecResponse returnVal;/*w  w  w.  j a  v  a  2s. c  o m*/
    String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action))
            ? execScriptAsRoot(action)
            : execScriptAsDefaultUser(action);
    returnVal = runCommand(command);
    if (ImmutableSet.of("status", "stdout", "stderr").contains(action))
        logger.trace("<< %s(%d)", action, returnVal.getExitStatus());
    else if (computeLogger.isTraceEnabled())
        computeLogger.trace("<< %s[%s]", action, returnVal);
    else
        computeLogger.debug("<< %s(%d)", action, returnVal.getExitStatus());
    return returnVal;
}

From source file:net.automatalib.util.automata.predicates.TransitionPredicates.java

public static <S, I, T> TransitionPredicate<S, I, T> inputNotIn(Collection<?> inputs) {
    return inputSatisfying(Predicates.not(Predicates.in(inputs)));
}

From source file:org.jclouds.cloudstack.predicates.CorrectHypervisorForZone.java

@Override
public Predicate<Template> apply(final String zoneId) {

    final Set<String> acceptableHypervisorsInZone;
    try {/*from  w w  w. j av  a 2 s.c o m*/
        acceptableHypervisorsInZone = this.hypervisorsSupplier.get().get(zoneId);
    } catch (NullPointerException e) {
        throw new IllegalArgumentException("unknown zone: " + zoneId);
    }
    if (acceptableHypervisorsInZone.size() == 0)
        return Predicates.alwaysFalse();
    return new Predicate<Template>() {

        @Override
        public boolean apply(Template input) {
            return Predicates.in(acceptableHypervisorsInZone).apply(input.getHypervisor());
        }

        @Override
        public String toString() {
            return "hypervisorsInZone(" + zoneId + ", " + acceptableHypervisorsInZone + ")";
        }
    };
}

From source file:com.google.errorprone.bugpatterns.RedundantThrows.java

@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
    List<? extends ExpressionTree> thrown = tree.getThrows();
    if (thrown.isEmpty()) {
        return NO_MATCH;
    }/*from  ww  w . ja  va  2 s.  com*/
    SetMultimap<Symbol, ExpressionTree> exceptionsBySuper = LinkedHashMultimap.create();
    for (ExpressionTree exception : thrown) {
        Type type = getType(exception);
        do {
            type = state.getTypes().supertype(type);
            exceptionsBySuper.put(type.tsym, exception);
        } while (!state.getTypes().isSameType(type, state.getSymtab().objectType));
    }
    Set<ExpressionTree> toRemove = new HashSet<>();
    List<String> messages = new ArrayList<>();
    for (ExpressionTree exception : thrown) {
        Symbol sym = getSymbol(exception);
        if (exceptionsBySuper.containsKey(sym)) {
            Set<ExpressionTree> sub = exceptionsBySuper.get(sym);
            messages.add(String.format("%s %s of %s", oxfordJoin(", ", sub),
                    sub.size() == 1 ? "is a subtype" : "are subtypes", sym.getSimpleName()));
            toRemove.addAll(sub);
        }
    }
    if (toRemove.isEmpty()) {
        return NO_MATCH;
    }
    // sort by order in input
    List<ExpressionTree> delete = ImmutableList
            .<ExpressionTree>copyOf(Iterables.filter(tree.getThrows(), Predicates.in(toRemove)));
    return buildDescription(delete.get(0)).setMessage("Redundant throws clause: " + oxfordJoin("; ", messages))
            .addFix(SuggestedFixes.deleteExceptions(tree, state, delete)).build();
}