Removing the Filter class, keeping Filter.filterOf

This commit is contained in:
Viktor Klang 2012-02-27 11:08:02 +01:00
parent 59104d03a1
commit 46b9b3cd43
3 changed files with 11 additions and 21 deletions

View file

@ -148,8 +148,8 @@ public class JavaFutureTests {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
Promise<String> cf = Futures.promise(system.dispatcher()); Promise<String> cf = Futures.promise(system.dispatcher());
Future<String> f = cf; Future<String> f = cf;
Future<String> r = f.filter(Filter.create(new Filter<String>() { Future<String> r = f.filter(Filter.filterOf(new Function<String, Boolean>() {
public boolean filter(String r) { public Boolean apply(String r) {
latch.countDown(); latch.countDown();
return r.equals("foo"); return r.equals("foo");
} }

View file

@ -1047,10 +1047,11 @@ abstract class Recover[+T] extends japi.RecoverBridge[T] {
* possible to use `Future.filter` by constructing such a function indirectly: * possible to use `Future.filter` by constructing such a function indirectly:
* *
* {{{ * {{{
* import static akka.dispatch.Filter.filterOf;
* Future<String> f = ...; * Future<String> f = ...;
* f.filter(Filter.create(new Filter<String>() { * f.filter(filterOf(new Function<String, Boolean>() {
* @Override * @Override
* public boolean filter(String s) { * public Boolean apply(String s) {
* ... * ...
* } * }
* })); * }));
@ -1060,20 +1061,9 @@ abstract class Recover[+T] extends japi.RecoverBridge[T] {
* thus Java users should prefer `Future.map`, translating non-matching values * thus Java users should prefer `Future.map`, translating non-matching values
* to failure cases. * to failure cases.
*/ */
abstract class Filter[-T] {
/**
* This method will be invoked once when/if a Future that this callback is registered on
* becomes completed with a success.
*
* @return true if the successful value should be propagated to the new Future or not
*/
def filter(result: T): Boolean
}
object Filter { object Filter {
def create[T](f: Filter[T]): (T Boolean) = new Function1[T, Boolean] { def filterOf[T](f: akka.japi.Function[T, java.lang.Boolean]): (T Boolean) =
def apply(result: T): Boolean = f.filter(result) new Function1[T, Boolean] { def apply(result: T): Boolean = f(result).booleanValue() }
}
} }
/** /**

View file

@ -317,14 +317,14 @@ public class FutureDocTestBase {
public void useFilter() throws Exception { public void useFilter() throws Exception {
//#filter //#filter
Future<Integer> future1 = Futures.successful(4, system.dispatcher()); Future<Integer> future1 = Futures.successful(4, system.dispatcher());
Future<Integer> successfulFilter = future1.filter(Filter.create(new Filter<Integer>() { Future<Integer> successfulFilter = future1.filter(Filter.filterOf(new Function<Integer, Boolean>() {
public boolean filter(Integer i) { public Boolean apply(Integer i) {
return i % 2 == 0; return i % 2 == 0;
} }
})); }));
Future<Integer> failedFilter = future1.filter(Filter.create(new Filter<Integer>() { Future<Integer> failedFilter = future1.filter(Filter.filterOf(new Function<Integer, Boolean>() {
public boolean filter(Integer i) { public Boolean apply(Integer i) {
return i % 2 != 0; return i % 2 != 0;
} }
})); }));