Example usage for com.google.common.collect Iterables any

List of usage examples for com.google.common.collect Iterables any

Introduction

In this page you can find the example usage for com.google.common.collect Iterables any.

Prototype

public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns true if any element in iterable satisfies the predicate.

Usage

From source file:de.cosmocode.commons.validation.AbstractRule.java

@Override
public boolean any(Iterable<? extends T> inputs) {
    Preconditions.checkNotNull(inputs, "Inputs");
    return Iterables.any(inputs, this);
}

From source file:uk.ac.stfc.isis.ibex.ui.synoptic.editor.dialogs.SaveSynopticViewModel.java

private boolean isDuplicate(final String name) {
    return Iterables.any(existingSynoptics, new Predicate<String>() {
        @Override/*from   ww w  .ja v  a2s . co m*/
        public boolean apply(String existing) {
            return existing.equalsIgnoreCase(name);
        }
    });
}

From source file:com.google.errorprone.refaster.UNewArray.java

@Override
@Nullable//from w w w . j a v a  2s .c om
public Choice<Unifier> visitNewArray(NewArrayTree newArray, @Nullable Unifier unifier) {
    boolean hasRepeated = getInitializers() != null
            && Iterables.any(getInitializers(), Predicates.instanceOf(URepeated.class));
    return unifyNullable(unifier, getType(), newArray.getType())
            .thenChoose(unifications(getDimensions(), newArray.getDimensions()))
            .thenChoose(unifications(getInitializers(), newArray.getInitializers(), hasRepeated));
}

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

/**
 * /*from   w ww  .ja  v  a  2  s . c o  m*/
 * @return true, if the security group contains an ingress rule with the given cidr and the given port in range
 */
public static Predicate<SecurityGroup> portInRangeForCidr(final int port, final String cidr) {
    return new Predicate<SecurityGroup>() {

        @Override
        public boolean apply(SecurityGroup group) {
            return Iterables.any(group.getIngressRules(), new Predicate<IngressRule>() {
                @Override
                public boolean apply(IngressRule rule) {
                    return rule.getCIDR() != null && rule.getCIDR().equals(cidr) && rule.getStartPort() <= port
                            && rule.getEndPort() >= port;
                }
            });
        }

        @Override
        public String toString() {
            return "portInRangeForCidr(" + port + ", " + cidr + ")";
        }
    };
}

From source file:org.magnum.mcc.paths.Path.java

/**
 * Construct a path using an ordered set of nodes and a weight for the path.
 * // ww  w . jav a 2s  .c o m
 * Assuming this graph:
 * 
 * a--2--b--4--e | | 3 3 | | c--4--d--1--f | | 7 2 | | i--2--g--2--h--3--j
 * 
 * The path from a to f through d and c would be constructed as follows:
 * 
 * Path<String> path = new Path(new String[]{"a","c","d","f"},8.0);
 * 
 * The nodes can be of arbitrary types. If you have a Node class, then you
 * simply parameterize as follows:
 * 
 * Path<Node> path = ...;
 * 
 * @param nodes
 * @param weight
 */
public Path(T[] nodes, Double weight) {
    checkArgument(nodes != null, "A path must be provided with a non-null list of nodes.");

    checkArgument(!Iterables.any(Arrays.asList(nodes), new Predicate<T>() {
        @Override
        public boolean apply(T arg0) {
            return arg0 == null;
        }
    }), "A path cannot have any null values in its array of nodes.");

    weight_ = weight;
    nodes_ = nodes;
}

From source file:org.trnltk.morphology.morphotactics.suffixformspecifications.HasSuffixFormSinceLastDerivation.java

@Override
public boolean isSatisfiedBy(MorphemeContainer morphemeContainer) {
    Validate.notNull(morphemeContainer);

    final Collection<Suffix> suffixesSinceDerivationSuffix = morphemeContainer
            .getSuffixesSinceDerivationSuffix();
    if (CollectionUtils.isEmpty(suffixesSinceDerivationSuffix))
        return false;

    if (suffixFormStr != null) { // can be blank
        Set<SuffixTransition> transitionsSinceDerivationSuffix = morphemeContainer
                .getTransitionsSinceDerivationSuffix();
        return Iterables.any(transitionsSinceDerivationSuffix, new Predicate<SuffixTransition>() {
            @Override/*from   w w w  .j av a 2 s  .c o m*/
            public boolean apply(SuffixTransition suffixTransition) {
                return suffixTransition.getSuffixFormApplication().getSuffixForm().getSuffix().equals(suffix)
                        && suffixTransition.getSuffixFormApplication().getSuffixForm().getForm()
                                .getSuffixFormStr().equals(suffixFormStr);
            }
        });
    } else {
        return suffixesSinceDerivationSuffix.contains(this.suffix);
    }
}

From source file:com.clarkparsia.pelletserver.client.services.Explain.java

public Explain(KnowledgeBase kb, Endpoint endpoint, MimeType... mimetypes) {
    super(kb, endpoint, mimetypes);

    checkArgument(Iterables.any(this.mimetypes, PelletServerMimeTypes.getPredicate(MIMETYPE)),
            getName() + " service must support %s", MIMETYPE);
}

From source file:com.google.testing.results.DirectoryBasedOutputsCollector.java

public TestResults parse(final Path root) throws IOException {
    final TestResults.Builder builder = TestResults.newBuilder();

    Files.walkFileTree(root, new FileVisitor<Path>() {
        @Override/*from w w w . j a  va 2s.c o  m*/
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            System.out.println("file.getFileName() = " + file.getFileName());
            if (file.getFileName().toString().equals("build-log.txt")) {
                builder.setBuildLog(file.toString());
            }
            if (Iterables.any(file, LOOKS_LIKE_TEST_DIRECTORY)
                    && file.getFileName().toString().endsWith(".xml")) {
                try {
                    builder.addAllTestSuite(xmlParser.parse(Files.newInputStream(file), UTF_8));
                } catch (XmlParseException xmlParseError) {
                    logger.warning("Failed to parse, file = [" + file + "], exc = [" + xmlParseError + "]");
                }
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
            logger.warning("Failed to read, file = [" + file + "], exc = [" + exc + "]");
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }
    });
    return builder.build();
}

From source file:com.twitter.aurora.scheduler.filter.AttributeFilter.java

/**
 * Tests whether an attribute matches a limit constraint.
 *
 * @param attributes Attributes to match against.
 * @param jobKey Key of the job with the limited constraint.
 * @param limit Limit value.// ww w  . ja v a  2  s  . com
 * @param activeTasks All active tasks in the system.
 * @param attributeFetcher Interface for fetching attributes for hosts in the system.
 * @return {@code true} if the limit constraint is satisfied, {@code false} otherwise.
 */
static boolean matches(final Set<Attribute> attributes, final IJobKey jobKey, int limit,
        Iterable<IScheduledTask> activeTasks, final AttributeLoader attributeFetcher) {

    Predicate<IScheduledTask> sameJob = Predicates.compose(Predicates.equalTo(jobKey),
            Tasks.SCHEDULED_TO_JOB_KEY);

    Predicate<IScheduledTask> hasAttribute = new Predicate<IScheduledTask>() {
        @Override
        public boolean apply(IScheduledTask task) {
            Iterable<Attribute> hostAttributes = attributeFetcher.apply(task.getAssignedTask().getSlaveHost());
            return Iterables.any(hostAttributes, Predicates.in(attributes));
        }
    };

    return limit > Iterables.size(Iterables.filter(activeTasks, Predicates.and(sameJob, hasAttribute)));
}

From source file:org.eclipse.sirius.business.internal.movida.registry.CompositeViewpointResourceHandler.java

/**
 * {@inheritDoc}//from  www .  j a  v a 2 s. c o  m
 */
public synchronized boolean handles(final URI uri) {
    return Iterables.any(handlers, new Predicate<ViewpointResourceHandler>() {
        public boolean apply(ViewpointResourceHandler handler) {
            return handler.handles(uri);
        }
    });
}