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:com.censoredsoftware.library.util.StringUtil2.java

/**
 * Returns true if the <code>string</code> contains any of the strings held in the <code>collection</code>.
 *
 * @param check      the string to check.
 * @param collection the collection given.
 *//*from   ww w.  ja va2  s .c  om*/
public static boolean containsAnyInCollection(final String check, Collection<String> collection) {
    return Iterables.any(collection, new Predicate<String>() {
        @Override
        public boolean apply(String string) {
            return StringUtils.containsIgnoreCase(check, string);
        }
    });
}

From source file:edu.umn.msi.tropix.persistence.service.impl.utils.PersistenceModelUtils.java

public static <T extends TropixObject> Iterable<T> typeFilter(final Iterable<T> objects,
        final Iterable<TropixObjectType> types) {
    return Iterables.filter(objects, new Predicate<TropixObject>() {
        public boolean apply(final TropixObject object) {
            return Iterables.any(types, new Predicate<TropixObjectType>() {
                public boolean apply(final TropixObjectType type) {
                    return type.isInstance(object);
                }/*w  ww .j a  v  a 2  s  .  c  o  m*/
            });
        }
    });
}

From source file:org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.java

public static Predicate<Firewall> hasPortRange(final Range<Integer> portRange) {
    return new Predicate<Firewall>() {

        @Override//from   w w  w  .  j ava 2s  .  c o  m
        public boolean apply(Firewall fw) {
            return Iterables.any(fw.getAllowed(), new Predicate<Rule>() {
                @Override
                public boolean apply(Rule input) {
                    return input.getPorts().encloses(portRange);
                }
            });
        }
    };
}

From source file:com.thinkbiganalytics.metadata.sla.alerts.ServiceLevelAgreementActionUtil.java

public static boolean isValidConfiguration(List<Class<? extends ServiceLevelAgreementAction>> actionClasses) {

    List<ServiceLevelAgreementActionValidation> validation = validateActionConfiguration(actionClasses);
    return Iterables.any(validation, new Predicate<ServiceLevelAgreementActionValidation>() {
        @Override//from  w w w  . ja  v a2s  . c o  m
        public boolean apply(ServiceLevelAgreementActionValidation serviceLevelAgreementActionValidation) {
            return !serviceLevelAgreementActionValidation.isValid();
        }
    });

}

From source file:com.webbfontaine.valuewebb.irms.impl.function.TtRuleFunctions.java

public boolean isDocumentAttached(TTSourceBean sourceBean, final String docType) {
    LOGGER.debug("Searching for match for docType: {}", docType);

    List<TtDoc> ttDocs = sourceBean.getTtGen().getTtDocs();
    return Iterables.any(ttDocs, new Predicate<TtDoc>() {
        @Override/*from www . ja  v a 2  s .c om*/
        public boolean apply(TtDoc input) {
            return docType.equals(input.getType());
        }
    });
}

From source file:com.marvelution.bamboo.plugins.sonar.tasks.predicates.SonarPredicates.java

/**
 * Get the Has Sonar Tasks {@link Predicate}
 * /*from   w  w  w.j  av  a  2s.  c o  m*/
 * @return the {@link Predicate}
 */
public static Predicate<Buildable> hasSonarTasks() {
    return new Predicate<Buildable>() {
        @Override
        public boolean apply(Buildable buildable) {
            return Iterables.any(buildable.getBuildDefinition().getTaskDefinitions(), isSonarTask());
        }
    };
}

From source file:org.apache.beam.runners.spark.aggregators.metrics.sink.InMemoryMetrics.java

@SuppressWarnings({ "unchecked", "WeakerAccess" })
public static <T> T valueOf(final String name) {
    final T retVal;

    // this might fail in case we have multiple aggregators with the same suffix after
    // the last dot, but it should be good enough for tests.
    if (extendedMetricsRegistry != null && Iterables.any(extendedMetricsRegistry.getGauges().keySet(),
            Predicates.containsPattern(name + "$"))) {
        String key = Iterables.find(extendedMetricsRegistry.getGauges().keySet(),
                Predicates.containsPattern(name + "$"));
        retVal = (T) extendedMetricsRegistry.getGauges().get(key).getValue();
    } else {//from w  ww .j  a  v  a 2 s  .co  m
        retVal = null;
    }

    return retVal;
}

From source file:de.monticore.utils.ASTNodes.java

/**
 * Checks whether two ASTNodes are in a vertical relationship with each other with any number of
 * other nodes in between./*from w w w .j a  va2  s  . c  o  m*/
 * <p>
 * This operation is O(n), where n is the number of nodes contained in the subtree spanned by the
 * ancestor.
 *
 * @param ancestor  the node further up in the AST
 * @param successor the node further down in the AST
 * @return true if there exists a descending path from the ancestor to the successor
 */
public static boolean areAncestorAndSuccessor(ASTNode ancestor, ASTNode successor) {
    Iterable<ASTNode> successors = Util.preOrder(ancestor, ASTNode::get_Children);
    return Iterables.any(successors, otherSuccessor -> otherSuccessor == successor);
}

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

public static Matcher<List<User>> containsId(final String id) {
    return new BaseMatcher<List<User>>() {

        @Override//from  www . j a va  2s  . c  o 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.getId(), id);
                }
            });
        }

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

From source file:org.sonar.plugins.web.checks.sonar.LinkToImageCheck.java

private static boolean isPoitingToAnImage(String target) {
    final String upperTarget = target.toUpperCase(Locale.ENGLISH);
    return Iterables.any(IMG_SUFFIXES, new Predicate<String>() {
        @Override/*w ww  .  ja  va  2  s.  c  om*/
        public boolean apply(@Nullable String input) {
            return input != null && upperTarget.endsWith(input);
        }
    });
}