Created
December 2, 2010 19:13
-
-
Save weissjeffm/725871 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class ByValuePredicate implements Predicate<Object> { | |
Object value; | |
String fieldName; | |
public ByValuePredicate(String fieldName, Object value) { | |
this.value=value; | |
this.fieldName=fieldName; | |
} | |
public boolean apply(Object toTest) { | |
return toTest.class.getField(fieldName).get(toTest).equals(value); | |
} | |
} | |
List<Object> mylist = etc | |
List<Object> matches = Collections2.filter(mylist, new ByValuePredicate(valuetomatch, "myfield"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment