Last active
December 27, 2015 10:49
-
-
Save shaon/489ce02823d1bf2e61d4 to your computer and use it in GitHub Desktop.
Basic Predicate example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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