Closed GoogleCodeExporter closed 9 years ago
It does seem like a gap that we don't have that.
And do we not have a method that composes a Function and a Predicate into a
Predicate? I'm surprised, I thought we had that.
Original comment by kevin...@gmail.com
on 23 Oct 2007 at 7:15
Original comment by kevin...@gmail.com
on 27 May 2008 at 6:29
I built an implementation that mirrors the Functions.forPredicate method:
public static <T> Predicate<T> forFunction(Function<T, Boolean> function) {
return new FunctionPredicate<T>(function);
}
private static class FunctionPredicate<T> implements Predicate<T>, Serializable {
private final Function<T, Boolean> function;
private FunctionPredicate(Function<T, Boolean> function) {
this.function = checkNotNull(function);
}
@Override
public boolean apply(T t) {
return function.apply(t);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof FunctionPredicate) {
FunctionPredicate<?> that = (FunctionPredicate<?>) obj;
return function.equals(that.function);
}
return false;
}
@Override
public int hashCode() {
return function.hashCode();
}
@Override
public String toString() {
return "forFunction(" + function + ")";
}
private static final long serialVersionUID = 0;
}
Original comment by seantparsons
on 12 Mar 2009 at 10:24
Original comment by kevin...@gmail.com
on 18 Mar 2009 at 2:20
Original comment by kevin...@gmail.com
on 17 Sep 2009 at 6:02
This issue has been moved to the Guava project (keeping the same id number).
Simply replace 'google-collections' with 'guava-libraries' in your address
bar and it should take you there.
Original comment by kevinb@google.com
on 5 Jan 2010 at 11:09
Original issue reported on code.google.com by
jonhnnyw...@gmail.com
on 23 Oct 2007 at 7:06