|
1 | | -/** |
2 | | - * Copyright 2014 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 java.util.ArrayList; |
19 | | -import java.util.List; |
20 | | - |
21 | | -import rx.Notification; |
22 | | -import rx.functions.Action0; |
23 | | -import rx.functions.ActionN; |
24 | | - |
25 | | -/** |
26 | | - * Represents an active plan. |
27 | | - */ |
28 | | -public final class ActivePlanN extends ActivePlan0 { |
29 | | - private final ActionN onNext; |
30 | | - private final Action0 onCompleted; |
31 | | - private final List<JoinObserver1<? extends Object>> observers; |
32 | | - |
33 | | - ActivePlanN(List<JoinObserver1<? extends Object>> observers, |
34 | | - ActionN onNext, |
35 | | - Action0 onCompleted) { |
36 | | - this.onNext = onNext; |
37 | | - this.onCompleted = onCompleted; |
38 | | - this.observers = new ArrayList<JoinObserver1<? extends Object>>(observers); |
39 | | - for (JoinObserver1<? extends Object> jo : this.observers) { |
40 | | - addJoinObserver(jo); |
41 | | - } |
42 | | - } |
43 | | - |
44 | | - @Override |
45 | | - protected void match() { |
46 | | - Object[] notifications = new Object[this.observers.size()]; |
47 | | - int j = 0; |
48 | | - int completedCount = 0; |
49 | | - for (JoinObserver1<? extends Object> jo : this.observers) { |
50 | | - if (jo.queue().isEmpty()) { |
51 | | - return; |
52 | | - } |
53 | | - Notification<? extends Object> n = jo.queue().peek(); |
54 | | - if (n.isOnCompleted()) { |
55 | | - completedCount++; |
56 | | - } |
57 | | - notifications[j] = n.getValue(); |
58 | | - j++; |
59 | | - } |
60 | | - if (completedCount == j) { |
61 | | - onCompleted.call(); |
62 | | - } else { |
63 | | - dequeue(); |
64 | | - onNext.call(notifications); |
65 | | - } |
66 | | - } |
67 | | - |
68 | | -} |
| 1 | +/** |
| 2 | + * Copyright 2014 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 java.util.ArrayList; |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +import rx.Notification; |
| 22 | +import rx.functions.Action0; |
| 23 | +import rx.functions.ActionN; |
| 24 | + |
| 25 | +/** |
| 26 | + * Represents an active plan. |
| 27 | + */ |
| 28 | +public final class ActivePlanN extends ActivePlan0 { |
| 29 | + private final ActionN onNext; |
| 30 | + private final Action0 onCompleted; |
| 31 | + private final List<JoinObserver1<? extends Object>> observers; |
| 32 | + |
| 33 | + ActivePlanN(List<JoinObserver1<? extends Object>> observers, |
| 34 | + ActionN onNext, |
| 35 | + Action0 onCompleted) { |
| 36 | + this.onNext = onNext; |
| 37 | + this.onCompleted = onCompleted; |
| 38 | + this.observers = new ArrayList<JoinObserver1<? extends Object>>(observers); |
| 39 | + for (JoinObserver1<? extends Object> jo : this.observers) { |
| 40 | + addJoinObserver(jo); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + protected void match() { |
| 46 | + Object[] notifications = new Object[this.observers.size()]; |
| 47 | + int j = 0; |
| 48 | + int completedCount = 0; |
| 49 | + for (JoinObserver1<? extends Object> jo : this.observers) { |
| 50 | + if (jo.queue().isEmpty()) { |
| 51 | + return; |
| 52 | + } |
| 53 | + Notification<? extends Object> n = jo.queue().peek(); |
| 54 | + if (n.isOnCompleted()) { |
| 55 | + completedCount++; |
| 56 | + } |
| 57 | + notifications[j] = n.getValue(); |
| 58 | + j++; |
| 59 | + } |
| 60 | + if (completedCount == j) { |
| 61 | + onCompleted.call(); |
| 62 | + } else { |
| 63 | + dequeue(); |
| 64 | + onNext.call(notifications); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments