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:uk.ac.open.kmi.iserve.discovery.util.MatchResultPredicates.java

/**
 * Generates a Predicate that only accepts the Match Results within a range. The range may be closed or open at each
 * of the boundaries. {@code BoundType.CLOSED} means that the boundary should also be accepted. {@code BoundType.OPEN}
 * on the other indicates that the boundary itself should not be accepted.
 *
 * @param minMatchType the matchType that defines the lower boundary
 * @param minBound     the lower {@code BoundType}
 * @param maxMatchType the matchType that defines the upper boundary
 * @param maxBound     the upper {@code BoundType}
 * @param <T>          a subclass of MatchResult
 * @param <S>          a subclass of MatchType
 * @return the Predicate//from ww w . j a v a 2s  .  co m
 */
public static <T extends MatchResult, S extends MatchType> Predicate<T> withinRange(S minMatchType,
        BoundType minBound, S maxMatchType, BoundType maxBound) {

    Predicate<T> lowerPredicate;
    Predicate<T> upperPredicate;

    if (minBound.equals(BoundType.CLOSED)) {
        lowerPredicate = greaterOrEqualTo(minMatchType);
    } else {
        lowerPredicate = greaterThan(minMatchType);
    }

    if (maxBound.equals(BoundType.CLOSED)) {
        upperPredicate = lowerOrEqualTo(maxMatchType);
    } else {
        upperPredicate = lowerThan(maxMatchType);
    }

    return Predicates.and(lowerPredicate, upperPredicate);
}

From source file:com.eucalyptus.autoscaling.common.internal.instances.PersistenceAutoScalingInstances.java

@Override
public <T> List<T> listByState(final LifecycleState lifecycleState, final ConfigurationState configurationState,
        final Function<? super AutoScalingInstance, T> transform) throws AutoScalingMetadataException {
    final AutoScalingInstance example = AutoScalingInstance.withStates(lifecycleState, configurationState);
    return persistenceSupport.listByExample(example, Predicates.and(lifecycleState, configurationState),
            transform);//ww w . ja va2 s .c  o  m
}

From source file:com.twitter.common.args.ArgFilters.java

/**
 * Creates a filter that selects a single {@literal @CmdLine} {@link Arg}.
 *
 * @param clazz The class that declares the command line arg to be selected.
 * @param name The {@link com.twitter.common.args.CmdLine#name()} of the arg to select.
 * @return A filter that selects a single specified command line arg.
 *//*from   ww  w.ja  v a 2  s .  co  m*/
public static Predicate<Field> selectCmdLineArg(Class<?> clazz, final String name) {
    MorePreconditions.checkNotBlank(name);
    return Predicates.and(selectClass(clazz), new Predicate<Field>() {
        @Override
        public boolean apply(Field field) {
            return field.getAnnotation(CmdLine.class).name().equals(name);
        }
    });
}

From source file:com.marvelution.hudson.plugins.apiv2.resources.impl.SearchRestResourceImpl.java

/**
 * @param keys//from   w ww  .ja  v  a 2s .c  o m
 * @param jobName
 * @return
 */
private Predicate<IssueCache> getSearchPredicates(String[] keys, String jobName) {
    List<Predicate<IssueCache>> issuePredicates = Lists.newArrayList();
    for (String key : keys) {
        if (JiraKeyUtils.isValidProjectKey(key)) {
            issuePredicates.add(IssueCachePredicates.isRelatedToJIRAProject(key));
        } else if (JiraKeyUtils.isValidIssueKey(key)) {
            issuePredicates.add(IssueCachePredicates.isRelatedToJIRAIssue(key));
        }
    }
    if (StringUtils.isNotBlank(jobName)) {
        return Predicates.and(IssueCachePredicates.isRelatedToHudsonJob(jobName),
                Predicates.or(issuePredicates));
    } else {
        return Predicates.or(issuePredicates);
    }
}

From source file:org.jclouds.compute.internal.BaseLoadBalancerService.java

@Override
public Set<String> loadBalanceNodesMatching(Predicate<NodeMetadata> filter, String loadBalancerName,
        String protocol, int loadBalancerPort, int instancePort) {
    checkNotNull(loadBalancerName, "loadBalancerName");
    checkNotNull(protocol, "protocol");
    checkArgument(protocol.toUpperCase().equals("HTTP") || protocol.toUpperCase().equals("TCP"),
            "Acceptable values for protocol are HTTP or TCP");

    Map<Location, Set<String>> locationMap = Maps.newHashMap();
    for (NodeMetadata node : Iterables.filter(
            context.getComputeService().listNodesDetailsMatching(NodePredicates.all()),
            Predicates.and(filter, Predicates.not(NodePredicates.TERMINATED)))) {
        Set<String> ids = locationMap.get(node.getLocation());
        if (ids == null)
            ids = Sets.newHashSet();/*from   w w  w . j av  a  2s.c  o  m*/
        ids.add(node.getProviderId());
        locationMap.put(node.getLocation(), ids);
    }
    Set<String> dnsNames = Sets.newHashSet();
    for (Location location : locationMap.keySet()) {
        logger.debug(">> creating load balancer (%s)", loadBalancerName);
        String dnsName = loadBalancerStrategy.execute(location, loadBalancerName, protocol, loadBalancerPort,
                instancePort, locationMap.get(location));
        dnsNames.add(dnsName);
        logger.debug("<< created load balancer (%s) DNS (%s)", loadBalancerName, dnsName);
    }
    return dnsNames;
}

From source file:org.apache.beam.sdk.util.FileIOChannelFactory.java

/**
 * {@inheritDoc}// w  ww.  j  av  a2 s  .c  o  m
 *
 * <p>Wildcards in the directory portion are not supported.
 */
@Override
public Collection<String> match(String spec) throws IOException {
    File file = specToFile(spec);

    File parent = file.getAbsoluteFile().getParentFile();
    if (!parent.exists()) {
        return Collections.EMPTY_LIST;
    }

    // Method getAbsolutePath() on Windows platform may return something like
    // "c:\temp\file.txt". FileSystem.getPathMatcher() call below will treat
    // '\' (backslash) as an escape character, instead of a directory
    // separator. Replacing backslash with double-backslash solves the problem.
    // We perform the replacement on all platforms, even those that allow
    // backslash as a part of the filename, because Globs.toRegexPattern will
    // eat one backslash.
    String pathToMatch = file.getAbsolutePath().replaceAll(Matcher.quoteReplacement("\\"),
            Matcher.quoteReplacement("\\\\"));

    final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pathToMatch);

    Iterable<File> files = com.google.common.io.Files.fileTreeTraverser().preOrderTraversal(parent);
    Iterable<File> matchedFiles = Iterables.filter(files,
            Predicates.and(com.google.common.io.Files.isFile(), new Predicate<File>() {
                @Override
                public boolean apply(File input) {
                    return matcher.matches(input.toPath());
                }
            }));

    List<String> result = new LinkedList<>();
    for (File match : matchedFiles) {
        result.add(match.getPath());
    }

    return result;
}

From source file:forge.game.GameFormat.java

private Predicate<PaperCard> buildFilterRules() {
    final Predicate<PaperCard> banNames = Predicates.not(IPaperCard.Predicates.names(this.bannedCardNames_ro));
    if (this.allowedSetCodes_ro.isEmpty()) {
        return banNames;
    }//from ww  w.  j ava2s .c om
    return Predicates.and(banNames,
            StaticData.instance().getCommonCards().wasPrintedInSets(this.allowedSetCodes_ro));
}

From source file:fi.vm.sade.organisaatio.service.OrganisationDateValidator.java

@Override
public boolean apply(@Nullable Entry<Organisaatio, Organisaatio> parentChild) {
    if (isSkipParentDateValidation) {
        return Predicates.and(endDateValidator, dateValidator).apply(parentChild);
    } else {//from  ww  w .  ja va  2 s  .co  m
        return Predicates.and(startDateValidator, endDateValidator, dateValidator).apply(parentChild);
    }
}

From source file:com.google.android.droiddriver.base.AbstractUiElement.java

@Override
public List<UiElement> getChildren(Predicate<? super UiElement> predicate) {
    predicate = Predicates.and(Predicates.notNull(), predicate);
    // TODO: Use internal data when we take snapshot of current node tree.
    ImmutableList.Builder<UiElement> builder = ImmutableList.builder();
    for (int i = 0; i < getChildCount(); i++) {
        UiElement child = getChild(i);/* www. j a  va  2s .c o m*/
        if (predicate.apply(child)) {
            builder.add(child);
        }
    }
    return builder.build();
}

From source file:org.concord.energy3d.scene.CameraControl.java

public void setupMouseTriggers(final LogicalLayer layer, final boolean dragOnly) {
    // Mouse look
    final Predicate<TwoInputStates> someMouseDown = Predicates.or(TriggerConditions.leftButtonDown(),
            Predicates.or(TriggerConditions.rightButtonDown(), TriggerConditions.middleButtonDown()));
    final Predicate<TwoInputStates> dragged = Predicates.and(TriggerConditions.mouseMoved(),
            Predicates.and(someMouseDown, Predicates.not(new KeyHeldCondition(Key.LCONTROL))));
    final TriggerAction dragAction = new TriggerAction() {

        // Test boolean to allow us to ignore first mouse event. First event can wildly vary based on platform.
        private boolean firstPing = true;

        @Override//w ww  .ja  va  2 s  .  co m
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            if (!enabled || !mouseEnabled)
                return;
            final MouseState mouse = inputStates.getCurrent().getMouseState();
            if (mouse.getDx() != 0 || mouse.getDy() != 0) {
                if (!firstPing) {
                    final boolean left = leftMouseButtonEnabled
                            && mouse.getButtonState(MouseButton.LEFT) == ButtonState.DOWN;
                    final boolean right = rightMouseButtonEnabled
                            && mouse.getButtonState(MouseButton.RIGHT) == ButtonState.DOWN;
                    final boolean middle = mouse.getButtonState(MouseButton.MIDDLE) == ButtonState.DOWN;
                    if (left && leftButtonAction == ButtonAction.MOVE
                            || right && rightButtonAction == ButtonAction.MOVE) {
                        final double fac = Camera.getCurrentCamera().getLocation().length() * 150;
                        final double dx = -mouse.getDx() * fac / Camera.getCurrentCamera().getWidth();
                        final double dy = -mouse.getDy() * fac / Camera.getCurrentCamera().getHeight() / 4.0;
                        move(source.getCanvasRenderer().getCamera(), dx, dy);
                        SceneManager.getInstance().getCameraNode().updateFromCamera();
                        Scene.getInstance().updateEditShapes();
                    } else if (left && leftButtonAction == ButtonAction.ROTATE
                            || right && rightButtonAction == ButtonAction.ROTATE) {
                        rotate(source.getCanvasRenderer().getCamera(), -mouse.getDx(), -mouse.getDy());
                        SceneManager.getInstance().getCameraNode().updateFromCamera();
                        Scene.getInstance().updateEditShapes();
                    } else if (middle || left && leftButtonAction == ButtonAction.ZOOM
                            || right && rightButtonAction == ButtonAction.ZOOM) {
                        int dy = inputStates.getCurrent().getMouseState().getDy();
                        if (dy < -4)
                            dy = -4;
                        if (dy > 4)
                            dy = 4;
                        zoom(source, tpf, -dy / 1.0);
                    }
                } else {
                    firstPing = false;
                }
            }
        }
    };

    _mouseTrigger = new InputTrigger(dragOnly ? dragged : TriggerConditions.mouseMoved(), dragAction);
    layer.registerTrigger(_mouseTrigger);

    layer.registerTrigger(new InputTrigger(new MouseWheelMovedCondition(), new TriggerAction() {
        @Override
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            zoom(source, tpf, inputStates.getCurrent().getMouseState().getDwheel());
        }
    }));
}