Example usage for com.google.common.base Predicates containsPattern

List of usage examples for com.google.common.base Predicates containsPattern

Introduction

In this page you can find the example usage for com.google.common.base Predicates containsPattern.

Prototype

@GwtIncompatible(value = "java.util.regex.Pattern")
public static Predicate<CharSequence> containsPattern(String pattern) 

Source Link

Document

Returns a predicate that evaluates to true if the CharSequence being tested contains any match for the given regular expression pattern.

Usage

From source file:org.apache.whirr.service.puppet.predicates.PuppetPredicates.java

public static Predicate<String> isFirstPuppetRoleIn(final Iterable<String> roles) {
    return new Predicate<String>() {

        @Override/*  w  w w .  ja va 2  s .  co m*/
        public boolean apply(String arg0) {
            return Iterables
                    .get(Iterables.filter(roles, Predicates.containsPattern("^" + PUPPET_ROLE_PREFIX + arg0)),
                            0)
                    .equals(PUPPET_ROLE_PREFIX + arg0);
        }

        @Override
        public String toString() {
            return "isFirstPuppetRoleIn(" + roles + ")";

        }
    };

}

From source file:io.ytcode.reflect.util.Utils.java

public static Predicate<Resource> predicateResourceNamePattern(String pattern) {
    return Predicates.compose(Predicates.containsPattern(pattern), new Function<Resource, String>() {
        @Override// ww  w.  j a  v  a  2 s . com
        public String apply(Resource r) {
            return r.name();
        }
    });
}

From source file:org.apache.whirr.service.puppet.predicates.PuppetPredicates.java

public static Predicate<CharSequence> isPuppetRole() {
    return Predicates.containsPattern("^" + PUPPET_ROLE_PREFIX);
}

From source file:com.google.devtools.moe.client.Utils.java

/** @return a Predicate that's true iff a CharSequence doesn't match any of the given regexes */
public static Predicate<CharSequence> nonMatchingPredicateFromRes(List<String> excludeRes) {
    ImmutableList.Builder<Predicate<CharSequence>> rePredicateBuilder = ImmutableList.builder();
    for (String excludeRe : excludeRes) {
        rePredicateBuilder.add(Predicates.not(Predicates.containsPattern(excludeRe)));
    }//w w w  .j a  va  2s.  co m
    return Predicates.and(rePredicateBuilder.build());
}

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 {// ww  w. j  a v  a 2s  .  com
        retVal = null;
    }

    return retVal;
}

From source file:org.apache.whirr.service.puppet.predicates.PuppetPredicates.java

public static Predicate<String> isLastPuppetRoleIn(final Iterable<String> roles) {
    return new Predicate<String>() {

        @Override/*from   www.  jav  a  2 s .  co  m*/
        public boolean apply(String arg0) {
            return Iterables
                    .getLast(Iterables.filter(roles,
                            Predicates.containsPattern("^" + PUPPET_ROLE_PREFIX + arg0)))
                    .equals(PUPPET_ROLE_PREFIX + arg0);
        }

        @Override
        public String toString() {
            return "isLastPuppetRoleIn(" + roles + ")";

        }
    };

}

From source file:org.trnltk.testutil.testmatchers.ParseResultsEqualMatcher.java

@Override
public boolean matchesSafely(Collection<String> item) {
    if (ignoreVerbPresA3Sg) // filter out some verb results to make the test have less results
        item = Collections2.filter(item, Predicates.not(Predicates.containsPattern("\\Zero\\+Pres\\+")));
    return CollectionUtils.isEqualCollection(expectedParseResults, item);
}

From source file:org.apache.whirr.service.puppet.functions.ModulePropertiesFromConfiguration.java

public Map<String, String> apply(final Configuration config) {
    Iterator<String> allKeys = Iterators.transform(config.getKeys(), Functions.toStringFunction());
    Set<String> moduleKeys = Sets.newHashSet(Iterators.<String>filter(allKeys, Predicates.and(
            Predicates.containsPattern(PUPPET + "\\.[^.]+\\." + MODULE_SOURCE_SUBKEY), new Predicate<String>() {

                @Override//from w w w.  j  av a 2s .  co  m
                public boolean apply(String arg0) {
                    // TODO not sure that we have to check this
                    return config.getString(arg0, null) != null;
                }

            })));
    Builder<String, String> builder = ImmutableMap.<String, String>builder();
    for (String key : moduleKeys) {
        builder.put(key, config.getString(key));
    }
    return builder.build();
}

From source file:net.derquinse.common.meta.StringMetaProperty.java

/**
 * Returns a predicate that evaluates to {@code true} if the property value being tested contains
 * any match for the given regular expression pattern. The test used is equivalent to
 * {@code Pattern.compile(pattern).matcher(arg).find()}
 * @throws java.util.regex.PatternSyntaxException if the pattern is invalid
 *//*w w w. j av  a  2 s.c  o m*/
public final Predicate<C> containsPattern(String pattern) {
    return compose(Predicates.containsPattern(pattern));
}

From source file:org.apache.brooklyn.entity.software.base.test.mysql.DynamicToyMySqlEntityBuilder.java

public static final String installDir(Entity e, boolean isLocalhost) {
    String url = downloadUrl(e, isLocalhost);
    String archive = Iterables.find(Splitter.on('/').omitEmptyStrings().split(url),
            Predicates.containsPattern(".tar.gz"));
    return archive.replace(".tar.gz", "");
}