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

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

Introduction

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

Prototype

@GwtIncompatible(value = "java.util.regex.Pattern")
public static Predicate<CharSequence> contains(Pattern 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:com.android.utils.FileUtils.java

/**
 * Find a list of files in a directory, using a specified path pattern.
 *//*from   w  w w  . java2s . c o  m*/
public static List<File> find(@NonNull File base, @NonNull final Pattern pattern) {
    checkArgument(base.isDirectory(), "'base' must be a directory.");
    return Files.fileTreeTraverser().preOrderTraversal(base)
            .filter(Predicates.compose(Predicates.contains(pattern), GET_PATH)).toList();
}

From source file:org.decisiondeck.jlp.parameters.LpParametersUtils.java

public static String toString(LpParameters parameters) {
    final ToStringHelper helper = Objects.toStringHelper(parameters);
    final MapJoiner mapFormatter = Joiner.on(", ").useForNull("null").withKeyValueSeparator("=");
    final String toStrInts = mapFormatter.join(parameters.getIntParameters());
    final String toStrDoubles = mapFormatter.join(parameters.getDoubleParameters());
    final String toStrStrings = mapFormatter.join(parameters.getStringParameters());
    final String toStrObjects = mapFormatter.join(parameters.getObjectParameters());

    final Joiner joiner = Joiner.on(", ");
    final Predicate<CharSequence> isNonEmpty = Predicates.contains(Pattern.compile(".+"));
    final Iterable<String> nonEmptyMaps = Iterables.filter(
            Arrays.asList(new String[] { toStrInts, toStrDoubles, toStrStrings, toStrObjects }), isNonEmpty);
    final String res = joiner.join(nonEmptyMaps);
    helper.addValue(res);/*from   ww w. j  a v a  2 s .  c o m*/
    return helper.toString();
    // final StringBuilder builder = new StringBuilder(helper.toString());
    // joiner.appendTo(builder, Strings.emptyToNull(toStrInts), Strings.emptyToNull(toStrDoubles),
    // Strings.emptyToNull(toStrStrings));
    // mapFormatter.appendTo(builder, getIntParameters());
    // mapFormatter.appendTo(builder, getDoubleParameters());
    // mapFormatter.appendTo(builder, getStringParameters());
    // return res;
}