|
5 | 5 | import org.jdeferred.Promise; |
6 | 6 | import org.jdeferred.impl.DeferredObject; |
7 | 7 |
|
8 | | -public class PipeDemo { |
| 8 | +class PipeDemo { |
9 | 9 |
|
10 | | - public static enum Result { |
| 10 | + public enum Result { |
11 | 11 | SUCCESS, FAILURE |
12 | 12 | }; |
13 | 13 |
|
14 | | - static Result status; |
| 14 | + private static Result status; |
15 | 15 |
|
16 | | - public static Result validate(int num) { |
17 | | - Deferred<Integer, ?, ?> d = new DeferredObject<Integer, Object, Object>(); |
| 16 | + static Result validate(int num) { |
| 17 | + Deferred<Integer, ?, ?> d = new DeferredObject<>(); |
18 | 18 | Promise<Integer, ?, ?> p = d.promise(); |
19 | 19 |
|
20 | | - p.then(new DonePipe<Integer, Integer, Exception, Void>() { |
21 | | - public Deferred<Integer, Exception, Void> pipeDone(Integer result) { |
22 | | - if (result < 90) { |
23 | | - return new DeferredObject<Integer, Exception, Void>().resolve(result); |
24 | | - } else { |
25 | | - return new DeferredObject<Integer, Exception, Void>().reject(new Exception("Unacceptable value")); |
26 | | - } |
| 20 | + p.then((DonePipe<Integer, Integer, Exception, Void>) result -> { |
| 21 | + if (result < 90) { |
| 22 | + return new DeferredObject<Integer, Exception, Void>() |
| 23 | + .resolve(result); |
| 24 | + } else { |
| 25 | + return new DeferredObject<Integer, Exception, Void>() |
| 26 | + .reject(new Exception("Unacceptable value")); |
27 | 27 | } |
28 | | - }).done((result) -> { |
29 | | - status = Result.SUCCESS; |
30 | | - }).fail((result) -> { |
31 | | - status = Result.FAILURE; |
32 | | - }); |
| 28 | + }).done(r -> status = Result.SUCCESS) |
| 29 | + .fail(r -> status = Result.FAILURE); |
33 | 30 |
|
34 | 31 | d.resolve(num); |
35 | 32 |
|
36 | 33 | return status; |
37 | 34 | } |
38 | | - |
39 | 35 | } |
0 commit comments