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:org.garethaye.minimax.framework.BotUtils.java

public static boolean isFull(List<List<Integer>> board) {
    return !Iterables.any(board, new Predicate<List<Integer>>() {
        @Override/*from   w  w  w .  j a v a  2s. com*/
        public boolean apply(List<Integer> row) {
            return row.contains(0);
        }
    });
}

From source file:org.eclipse.sirius.tests.unit.contribution.Freezer.java

public static void freeze(EObject obj) {
    if (!Iterables.any(obj.eAdapters(), Predicates.instanceOf(Freezer.class))) {
        obj.eAdapters().add(new Freezer());
    }/*w  ww . j  ava2 s  .  c om*/
}

From source file:com.complexible.common.base.Preconditions2.java

public static <S, T extends Exception> void check(final Iterable<S> theObject, final Predicate<S> thePredicate,
        Class<T> theExceptionType) throws T {
    check(Iterables.any(theObject, thePredicate), theExceptionType, null);
}

From source file:org.apache.aurora.scheduler.filter.AttributeFilter.java

/**
 * Tests whether a constraint is satisfied by attributes.
 *
 * @param values Host attribute values.//from   w w  w.  ja va  2s  . com
 * @param constraint Constraint to match.
 * @return {@code true} if the attribute satisfies the constraint, {@code false} otherwise.
 */
static boolean matches(Set<String> values, IValueConstraint constraint) {
    boolean match = Iterables.any(constraint.getValues(), Predicates.in(values));
    return constraint.isNegated() ^ match;
}

From source file:com.gantzgulch.sharing.matchers.UserMatcher.java

public static Matcher<List<User>> containsUsername(final String username) {
    return new BaseMatcher<List<User>>() {

        @Override/*from ww w. j  a v a2s .  co m*/
        public boolean matches(Object arg0) {
            List<User> users = Cast.cast(arg0);
            return Iterables.any(users, new Predicate<User>() {
                @Override
                public boolean apply(User input) {
                    return StringUtils.equals(input.getUsername(), username);
                }
            });
        }

        @Override
        public void describeTo(Description arg0) {
            arg0.appendText("User with username : " + username);
        }
    };
}

From source file:npanday.executable.impl.VersionComparer.java

public static boolean isFrameworkVersionMissmatch(List<String> capability, final String requirement) {
    if (capability != null && capability.size() > 0) {
        if (!Iterables.any(capability, new Predicate<String>() {
            public boolean apply(@Nullable String frameworkVersion) {
                return normalize(requirement).equals(normalize(frameworkVersion));
            }/*from ww  w  .j  a v a  2  s .c om*/
        })) {
            return true;
        }
    }

    return false;
}

From source file:com.github.autermann.utils.Optionals.java

/**
 * A {@link Predicate} to check if any of the supplied {@link Optional}s
 * is present.//from  w  w  w. ja v  a2  s  .c o m
 *
 * @param <T> the type of the {@link Optional}
 *
 * @return the predicate
 */
public static <T> boolean any(Optional<? extends T>... optionals) {
    return Iterables.any(Arrays.asList(optionals), isPresent());
}

From source file:com.complexible.common.base.Preconditions2.java

public static <S, T extends Exception> void check(final Iterable<S> theObject, final Predicate<S> thePredicate,
        final Class<T> theExceptionType, final String theMessage, final Object... theArgs) throws T {
    check(Iterables.any(theObject, thePredicate), theExceptionType, theMessage, theArgs);
}

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

/**
 * /* w  w w . j a va  2 s . c  o m*/
 * @return true, if the security group contains an ingress rule with the given port in the port range
 */
public static Predicate<SecurityGroup> portInRange(final int port) {
    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.getStartPort() <= port && rule.getEndPort() >= port;
                }
            });
        }

        @Override
        public String toString() {
            return "portInRange(" + port + ")";
        }
    };
}

From source file:io.v.rx.UncheckedVException.java

public boolean isIdIn(final Iterable<VException.IDAction> ids) {
    return Iterables.any(ids, id -> id.getID().equals(getCause().getID()));
}