Removing the Filter class, keeping Filter.filterOf
This commit is contained in:
parent
59104d03a1
commit
46b9b3cd43
3 changed files with 11 additions and 21 deletions
|
|
@ -148,8 +148,8 @@ public class JavaFutureTests {
|
|||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Promise<String> cf = Futures.promise(system.dispatcher());
|
||||
Future<String> f = cf;
|
||||
Future<String> r = f.filter(Filter.create(new Filter<String>() {
|
||||
public boolean filter(String r) {
|
||||
Future<String> r = f.filter(Filter.filterOf(new Function<String, Boolean>() {
|
||||
public Boolean apply(String r) {
|
||||
latch.countDown();
|
||||
return r.equals("foo");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1047,10 +1047,11 @@ abstract class Recover[+T] extends japi.RecoverBridge[T] {
|
|||
* possible to use `Future.filter` by constructing such a function indirectly:
|
||||
*
|
||||
* {{{
|
||||
* import static akka.dispatch.Filter.filterOf;
|
||||
* Future<String> f = ...;
|
||||
* f.filter(Filter.create(new Filter<String>() {
|
||||
* f.filter(filterOf(new Function<String, Boolean>() {
|
||||
* @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
|
||||
* 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 {
|
||||
def create[T](f: Filter[T]): (T ⇒ Boolean) = new Function1[T, Boolean] {
|
||||
def apply(result: T): Boolean = f.filter(result)
|
||||
}
|
||||
def filterOf[T](f: akka.japi.Function[T, java.lang.Boolean]): (T ⇒ Boolean) =
|
||||
new Function1[T, Boolean] { def apply(result: T): Boolean = f(result).booleanValue() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -317,14 +317,14 @@ public class FutureDocTestBase {
|
|||
public void useFilter() throws Exception {
|
||||
//#filter
|
||||
Future<Integer> future1 = Futures.successful(4, system.dispatcher());
|
||||
Future<Integer> successfulFilter = future1.filter(Filter.create(new Filter<Integer>() {
|
||||
public boolean filter(Integer i) {
|
||||
Future<Integer> successfulFilter = future1.filter(Filter.filterOf(new Function<Integer, Boolean>() {
|
||||
public Boolean apply(Integer i) {
|
||||
return i % 2 == 0;
|
||||
}
|
||||
}));
|
||||
|
||||
Future<Integer> failedFilter = future1.filter(Filter.create(new Filter<Integer>() {
|
||||
public boolean filter(Integer i) {
|
||||
Future<Integer> failedFilter = future1.filter(Filter.filterOf(new Function<Integer, Boolean>() {
|
||||
public Boolean apply(Integer i) {
|
||||
return i % 2 != 0;
|
||||
}
|
||||
}));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue