Skip to content

Instantly share code, notes, and snippets.

@shaon
Last active December 27, 2015 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaon/489ce02823d1bf2e61d4 to your computer and use it in GitHub Desktop.
Save shaon/489ce02823d1bf2e61d4 to your computer and use it in GitHub Desktop.
Basic Predicate example
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.util.List;
import static com.google.common.base.Predicates.and;
public class PredicateMyAss {
public static boolean isStartsWithG(String string) {
Predicate<String> predicate = and(startWithG);
return predicate.apply(string);
}
public static List<String> list = Lists.newArrayList("Google", "Vuava");
private static Predicate<String> startWithG = new Predicate<String>() {
@Override
public boolean apply(final String stringValue) {
return stringValue.startsWith("G");
}
};
public static void main(String[] args) {
System.out.println(isStartsWithG("Voogle"));
System.out.println(Iterables.all(list, startWithG));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment