Skip to content

Instantly share code, notes, and snippets.

@weissjeffm
Created December 2, 2010 19:13
Show Gist options
  • Save weissjeffm/725871 to your computer and use it in GitHub Desktop.
Save weissjeffm/725871 to your computer and use it in GitHub Desktop.
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