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:com.b2international.snowowl.datastore.remotejobs.SingleRemoteJobFamily.java

public static Predicate<RemoteJob> create(Collection<String> ids) {
    return Predicates.and(RemoteJobFamily.INSTANCE, new SingleRemoteJobFamily(ids));
}

From source file:com.b2international.snowowl.datastore.server.remotejobs.RemoteJobRuleFamily.java

public static Predicate<Job> create(final ISchedulingRule rule) {
    return Predicates.and(RemoteJobFamily.INSTANCE, new RemoteJobRuleFamily(rule));
}

From source file:ivorius.ivtoolkit.maze.components.MazeComponentConnector.java

public static <M extends WeightedMazeComponent<C>, C> List<ShiftedMazeComponent<M, C>> randomlyConnect(
        MorphingMazeComponent<C> morphingComponent, List<M> components,
        ConnectionStrategy<C> connectionStrategy, final MazeComponentPlacementStrategy<M, C> placementStrategy,
        Random random) {//from ww  w .j a  va  2s. com
    List<ShiftedMazeComponent<M, C>> result = new ArrayList<>();
    Deque<Triple<MazeRoom, MazeRoomConnection, C>> exitStack = new ArrayDeque<>();

    Predicate<ShiftedMazeComponent<M, C>> componentPredicate = Predicates.and(
            MazeComponents.<M, C>compatibilityPredicate(morphingComponent, connectionStrategy),
            MazeComponentPlacementStrategies.placeable(placementStrategy));
    WeightedSelector.WeightFunction<ShiftedMazeComponent<M, C>> weightFunction = getWeightFunction();

    addAllExits(placementStrategy, exitStack, morphingComponent.exits().entrySet());

    while (exitStack.size() > 0) {
        Triple<MazeRoom, MazeRoomConnection, C> triple = exitStack.removeLast();
        MazeRoom room = triple.getLeft();

        if (morphingComponent.rooms().contains(room))
            continue; // Has been filled while queued

        MazeRoomConnection exit = triple.getMiddle();
        C connection = triple.getRight();

        List<ShiftedMazeComponent<M, C>> placeable = FluentIterable.from(components)
                .transformAndConcat(MazeComponents.<M, C>shiftAllFunction(exit, connection, connectionStrategy))
                .filter(componentPredicate).toList();

        if (placeable.size() == 0) {
            IvToolkitCoreContainer.logger.warn("Did not find fitting component for maze!");
            IvToolkitCoreContainer.logger.warn("Suggested: X with exits "
                    + FluentIterable.from(morphingComponent.exits().entrySet()).filter(entryConnectsTo(room)));
            continue;
        }

        ShiftedMazeComponent<M, C> selected = WeightedSelector.canSelect(placeable, weightFunction)
                ? WeightedSelector.select(random, placeable, weightFunction)
                : placeable.get(random.nextInt(placeable.size())); // All weight 0 = select at random

        addAllExits(placementStrategy, exitStack, selected.exits().entrySet());

        morphingComponent.add(selected);
        result.add(selected);
    }

    return result;
}

From source file:org.zalando.crypto.Decrypters.java

public static List<Decrypter> findByPrefix(List<Decrypter> decrypters, String prefix) {
    Preconditions.checkNotNull(decrypters, "'Decrypter's-list should not be null");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(prefix), "'prefix' should never be null or empty.");
    return Lists.newArrayList(Iterables.filter(decrypters,
            Predicates.and(new PrefixedDecrypterPredicate(), new PrefixPredicate(prefix))));
}

From source file:com.flowlogix.ejb.StatefulUtil.java

/**
 * Pings all pingable SFSBs in the session
 * //w  ww . j a  v  a2s .  c  o  m
 * @param session 
 * @return true if successful, false if any of the pings failed
 */
public static boolean pingStateful(Session session) {
    boolean rv = true;

    List<String> attrNames = FluentIterable.from(session.getAttributeKeys())
            .transform(new Function<Object, String>() {
                @Override
                public String apply(Object f) {
                    if (f instanceof String) {
                        return (String) f;
                    } else {
                        return null;
                    }
                }
            }).filter(Predicates.and(Predicates.notNull(), Predicates.contains(ejbPattern))).toList();
    for (String attrName : attrNames) {
        synchronized (session.getId().toString().intern()) {
            try {
                Object _pingable = session.getAttribute(attrName);
                if (_pingable instanceof Pingable) {
                    Pingable pingable = (Pingable) _pingable;
                    pingable.ping();
                }
            } catch (EJBException e) {
                log.debug("Failed to Ping Stateful EJB: ", e);
                rv = false; // signal failure if any of the pings fail
                session.removeAttribute(attrName);
            }
        }
    }

    return rv;
}

From source file:com.example.SwaggerConfiger.java

@Bean
public Docket restApi() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
            .paths(Predicates.and(ant("/**"), Predicates.not(ant("/error")))).build();
}

From source file:org.n52.sos.ogc.sensorML.elements.SmlIdentifierPredicates.java

public static Predicate<SmlIdentifier> nameAndDefinition(String name, String definition) {
    return Predicates.and(name(name), definition(definition));
}

From source file:org.liquigraph.core.api.ChangelogDiffMaker.java

@SuppressWarnings("unchecked")
private static Predicate<Changeset> executionFilter(Collection<Changeset> persistedChangesets) {
    return or(not(in(persistedChangesets)), Predicates.and(ChangesetRunOnChange.RUN_ON_CHANGE,
            ChangesetChecksumHasChanged.CHECKSUM_HAS_CHANGED(persistedChangesets)), RUN_ALWAYS);
}

From source file:org.apache.isis.applib.services.exceprecog.ExceptionRecognizerForTypeLegacy.java

protected final static Predicate<Throwable> ofTypeExcluding(final Class<? extends Throwable> exceptionType,
        final String... messages) {
    return Predicates.and(ofType(exceptionType), excluding(messages));
}

From source file:com.eucalyptus.autoscaling.common.AutoScalingMetadatas.java

public static <T extends AutoScalingMetadataWithResourceName> Predicate<T> filterPrivilegesByIdOrArn(
        final Class<T> metadataClass, final Collection<String> requestedItems) {
    final Collection<String> names = AutoScalingResourceName.simpleNames(requestedItems);
    final Collection<String> arns = AutoScalingResourceName.arns(requestedItems);
    return Predicates.and(
            !arns.isEmpty() && !names.isEmpty()
                    ? Predicates.<T>or(AutoScalingMetadatas.<T>filterById(names),
                            AutoScalingMetadatas.<T>filterByArn(arns))
                    : !arns.isEmpty() ? AutoScalingMetadatas.<T>filterByArn(arns)
                            : AutoScalingMetadatas.<T>filterById(names),
            RestrictedTypes.filteringFor(metadataClass).byPrivileges().buildPredicate());
}