|
1 | | -/** |
2 | | - * Copyright 2013 Netflix, Inc. |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 | | - * use this file except in compliance with the License. You may obtain a copy of |
6 | | - * the License at |
7 | | - * |
8 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 | | - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 | | - * License for the specific language governing permissions and limitations under |
14 | | - * the License. |
15 | | - */ |
16 | | -package rx.joins; |
17 | | - |
18 | | -import rx.Notification; |
19 | | -import rx.util.functions.Action0; |
20 | | -import rx.util.functions.Action2; |
21 | | - |
22 | | -/** |
23 | | - * Represents an active plan. |
24 | | - */ |
25 | | -public class ActivePlan2<T1, T2> extends ActivePlan0 { |
26 | | - private final Action2<T1, T2> onNext; |
27 | | - private final Action0 onCompleted; |
28 | | - private final JoinObserver1<T1> first; |
29 | | - private final JoinObserver1<T2> second; |
30 | | - public ActivePlan2(JoinObserver1<T1> first, JoinObserver1<T2> second, Action2<T1, T2> onNext, Action0 onCompleted) { |
31 | | - this.onNext = onNext; |
32 | | - this.onCompleted = onCompleted; |
33 | | - this.first = first; |
34 | | - this.second = second; |
35 | | - addJoinObserver(first); |
36 | | - addJoinObserver(second); |
37 | | - } |
38 | | - |
39 | | - @Override |
40 | | - public void match() { |
41 | | - if (!first.queue().isEmpty() && !second.queue().isEmpty()) { |
42 | | - Notification<T1> n1 = first.queue().peek(); |
43 | | - Notification<T2> n2 = second.queue().peek(); |
44 | | - |
45 | | - if (n1.isOnCompleted() || n2.isOnCompleted()) { |
46 | | - onCompleted.call(); |
47 | | - } else { |
48 | | - dequeue(); |
49 | | - onNext.call(n1.getValue(), n2.getValue()); |
50 | | - } |
51 | | - } |
52 | | - } |
53 | | - |
54 | | -} |
| 1 | +/** |
| 2 | + * Copyright 2013 Netflix, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | +package rx.joins; |
| 17 | + |
| 18 | +import rx.Notification; |
| 19 | +import rx.util.functions.Action0; |
| 20 | +import rx.util.functions.Action2; |
| 21 | + |
| 22 | +/** |
| 23 | + * Represents an active plan. |
| 24 | + */ |
| 25 | +public class ActivePlan2<T1, T2> extends ActivePlan0 { |
| 26 | + private final Action2<T1, T2> onNext; |
| 27 | + private final Action0 onCompleted; |
| 28 | + private final JoinObserver1<T1> first; |
| 29 | + private final JoinObserver1<T2> second; |
| 30 | + public ActivePlan2(JoinObserver1<T1> first, JoinObserver1<T2> second, Action2<T1, T2> onNext, Action0 onCompleted) { |
| 31 | + this.onNext = onNext; |
| 32 | + this.onCompleted = onCompleted; |
| 33 | + this.first = first; |
| 34 | + this.second = second; |
| 35 | + addJoinObserver(first); |
| 36 | + addJoinObserver(second); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public void match() { |
| 41 | + if (!first.queue().isEmpty() && !second.queue().isEmpty()) { |
| 42 | + Notification<T1> n1 = first.queue().peek(); |
| 43 | + Notification<T2> n2 = second.queue().peek(); |
| 44 | + |
| 45 | + if (n1.isOnCompleted() || n2.isOnCompleted()) { |
| 46 | + onCompleted.call(); |
| 47 | + } else { |
| 48 | + dequeue(); |
| 49 | + onNext.call(n1.getValue(), n2.getValue()); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments