|
15 | 15 | */
|
16 | 16 | package rx.operators;
|
17 | 17 |
|
18 |
| -import rx.Observable; |
19 |
| -import rx.Observable.OnSubscribe; |
| 18 | +import rx.Observable.Operator; |
20 | 19 | import rx.Subscriber;
|
21 | 20 |
|
22 | 21 | /**
|
23 | 22 | * Returns the element at a specified index in a sequence.
|
24 | 23 | */
|
25 |
| -public final class OperatorElementAt<T> implements OnSubscribe<T> { |
| 24 | +public final class OperatorElementAt<T> implements Operator<T, T> { |
26 | 25 |
|
27 |
| - private final Observable<? extends T> source; |
28 | 26 | private final int index;
|
29 | 27 | private final boolean hasDefault;
|
30 | 28 | private final T defaultValue;
|
31 | 29 |
|
32 |
| - public OperatorElementAt(Observable<? extends T> source, int index) { |
33 |
| - this(source, index, null, false); |
| 30 | + public OperatorElementAt(int index) { |
| 31 | + this(index, null, false); |
34 | 32 | }
|
35 | 33 |
|
36 |
| - public OperatorElementAt(Observable<? extends T> source, int index, T defaultValue) { |
37 |
| - this(source, index, defaultValue, true); |
| 34 | + public OperatorElementAt(int index, T defaultValue) { |
| 35 | + this(index, defaultValue, true); |
38 | 36 | }
|
39 | 37 |
|
40 |
| - private OperatorElementAt(Observable<? extends T> source, int index, T defaultValue, boolean hasDefault) { |
| 38 | + private OperatorElementAt(int index, T defaultValue, boolean hasDefault) { |
41 | 39 | if (index < 0) {
|
42 | 40 | throw new IndexOutOfBoundsException(index + " is out of bounds");
|
43 | 41 | }
|
44 |
| - this.source = source; |
45 | 42 | this.index = index;
|
46 | 43 | this.defaultValue = defaultValue;
|
47 | 44 | this.hasDefault = hasDefault;
|
48 | 45 | }
|
49 | 46 |
|
50 | 47 | @Override
|
51 |
| - public void call(final Subscriber<? super T> subscriber) { |
52 |
| - source.subscribe(new Subscriber<T>(subscriber) { |
| 48 | + public Subscriber<? super T> call(final Subscriber<? super T> subscriber) { |
| 49 | + return new Subscriber<T>(subscriber) { |
53 | 50 |
|
54 | 51 | private int currentIndex = 0;
|
55 | 52 |
|
@@ -79,6 +76,7 @@ public void onCompleted() {
|
79 | 76 | }
|
80 | 77 | }
|
81 | 78 | }
|
82 |
| - }); |
| 79 | + }; |
83 | 80 | }
|
| 81 | + |
84 | 82 | }
|
0 commit comments