Skip to content

Commit 5888b23

Browse files
authored
2.x: coverage and cleanup 10/11-1 (#4689)
1 parent 497f35f commit 5888b23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3209
-263
lines changed

src/main/java/io/reactivex/Maybe.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public static <T> Maybe<T> fromCompletable(CompletableSource completableSource)
594594
* @throws NullPointerException if single is null
595595
*/
596596
@SchedulerSupport(SchedulerSupport.NONE)
597-
public static <T> Maybe<T> fromSingle(SingleSource singleSource) {
597+
public static <T> Maybe<T> fromSingle(SingleSource<T> singleSource) {
598598
ObjectHelper.requireNonNull(singleSource, "singleSource is null");
599599
return RxJavaPlugins.onAssembly(new MaybeFromSingle<T>(singleSource));
600600
}
@@ -2883,20 +2883,6 @@ public final <R> R to(Function<? super Maybe<T>, R> convert) {
28832883
}
28842884
}
28852885

2886-
/**
2887-
* Converts this Maybe into a Completable instance composing cancellation
2888-
* through and dropping a success value if emitted.
2889-
* <dl>
2890-
* <dt><b>Scheduler:</b></dt>
2891-
* <dd>{@code toCompletable} does not operate by default on a particular {@link Scheduler}.</dd>
2892-
* </dl>
2893-
* @return the new Completable instance
2894-
*/
2895-
@SchedulerSupport(SchedulerSupport.NONE)
2896-
public final Completable toCompletable() {
2897-
return RxJavaPlugins.onAssembly(new MaybeToCompletable<T>(this));
2898-
}
2899-
29002886
/**
29012887
* Converts this Maybe into a backpressure-aware Flowable instance composing cancellation
29022888
* through.

src/main/java/io/reactivex/internal/operators/maybe/MaybeDoOnEvent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public boolean isDisposed() {
6565
@Override
6666
public void onSubscribe(Disposable d) {
6767
if (DisposableHelper.validate(this.d, d)) {
68+
this.d = d;
69+
6870
actual.onSubscribe(this);
6971
}
7072
}

src/main/java/io/reactivex/internal/operators/maybe/MaybeEqualSingle.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void dispose() {
8282

8383
@Override
8484
public boolean isDisposed() {
85-
return observer1.isDisposed();
85+
return DisposableHelper.isDisposed(observer1.get());
8686
}
8787

8888
@SuppressWarnings("unchecked")
@@ -125,7 +125,7 @@ void error(EqualObserver<T> sender, Throwable ex) {
125125

126126
static final class EqualObserver<T>
127127
extends AtomicReference<Disposable>
128-
implements MaybeObserver<T>, Disposable {
128+
implements MaybeObserver<T> {
129129

130130

131131
private static final long serialVersionUID = -3031974433025990931L;
@@ -138,16 +138,10 @@ static final class EqualObserver<T>
138138
this.parent = parent;
139139
}
140140

141-
@Override
142141
public void dispose() {
143142
DisposableHelper.dispose(this);
144143
}
145144

146-
@Override
147-
public boolean isDisposed() {
148-
return DisposableHelper.isDisposed(get());
149-
}
150-
151145
@Override
152146
public void onSubscribe(Disposable d) {
153147
DisposableHelper.setOnce(this, d);

src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowable.java

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,46 @@ public void cancel() {
135135
d = DisposableHelper.DISPOSED;
136136
}
137137

138+
void fastPath(Subscriber<? super R> a, Iterator<? extends R> iter) {
139+
for (;;) {
140+
if (cancelled) {
141+
return;
142+
}
143+
144+
R v;
145+
146+
try {
147+
v = iter.next();
148+
} catch (Throwable ex) {
149+
Exceptions.throwIfFatal(ex);
150+
a.onError(ex);
151+
return;
152+
}
153+
154+
a.onNext(v);
155+
156+
if (cancelled) {
157+
return;
158+
}
159+
160+
161+
boolean b;
162+
163+
try {
164+
b = iter.hasNext();
165+
} catch (Throwable ex) {
166+
Exceptions.throwIfFatal(ex);
167+
a.onError(ex);
168+
return;
169+
}
170+
171+
if (!b) {
172+
a.onComplete();
173+
return;
174+
}
175+
}
176+
}
177+
138178
void drain() {
139179
if (getAndIncrement() != 0) {
140180
return;
@@ -155,48 +195,14 @@ void drain() {
155195

156196
if (iter != null) {
157197
long r = requested.get();
158-
long e = 0L;
159198

160199
if (r == Long.MAX_VALUE) {
161-
for (;;) {
162-
if (cancelled) {
163-
return;
164-
}
165-
166-
R v;
167-
168-
try {
169-
v = iter.next();
170-
} catch (Throwable ex) {
171-
Exceptions.throwIfFatal(ex);
172-
a.onError(ex);
173-
return;
174-
}
175-
176-
a.onNext(v);
177-
178-
if (cancelled) {
179-
return;
180-
}
181-
182-
183-
boolean b;
184-
185-
try {
186-
b = iter.hasNext();
187-
} catch (Throwable ex) {
188-
Exceptions.throwIfFatal(ex);
189-
a.onError(ex);
190-
return;
191-
}
192-
193-
if (!b) {
194-
a.onComplete();
195-
return;
196-
}
197-
}
200+
fastPath(a, iter);
201+
return;
198202
}
199203

204+
long e = 0L;
205+
200206
while (e != r) {
201207
if (cancelled) {
202208
return;

src/main/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservable.java

Lines changed: 50 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import io.reactivex.functions.Function;
2222
import io.reactivex.internal.disposables.DisposableHelper;
2323
import io.reactivex.internal.functions.ObjectHelper;
24-
import io.reactivex.internal.observers.BasicIntQueueDisposable;
24+
import io.reactivex.internal.observers.BasicQueueDisposable;
2525

2626
/**
2727
* Maps a success value into an Iterable and streams it back as a Flowable.
@@ -47,11 +47,9 @@ protected void subscribeActual(Observer<? super R> s) {
4747
}
4848

4949
static final class FlatMapIterableObserver<T, R>
50-
extends BasicIntQueueDisposable<R>
50+
extends BasicQueueDisposable<R>
5151
implements MaybeObserver<T> {
5252

53-
private static final long serialVersionUID = -8938804753851907758L;
54-
5553
final Observer<? super R> actual;
5654

5755
final Function<? super T, ? extends Iterable<? extends R>> mapper;
@@ -81,6 +79,8 @@ public void onSubscribe(Disposable d) {
8179

8280
@Override
8381
public void onSuccess(T value) {
82+
Observer<? super R> a = actual;
83+
8484
Iterator<? extends R> iter;
8585
boolean has;
8686
try {
@@ -89,17 +89,60 @@ public void onSuccess(T value) {
8989
has = iter.hasNext();
9090
} catch (Throwable ex) {
9191
Exceptions.throwIfFatal(ex);
92-
actual.onError(ex);
92+
a.onError(ex);
9393
return;
9494
}
9595

9696
if (!has) {
97-
actual.onComplete();
97+
a.onComplete();
9898
return;
9999
}
100100

101101
this.it = iter;
102-
drain();
102+
103+
if (outputFused && iter != null) {
104+
a.onNext(null);
105+
a.onComplete();
106+
return;
107+
}
108+
109+
for (;;) {
110+
if (cancelled) {
111+
return;
112+
}
113+
114+
R v;
115+
116+
try {
117+
v = iter.next();
118+
} catch (Throwable ex) {
119+
Exceptions.throwIfFatal(ex);
120+
a.onError(ex);
121+
return;
122+
}
123+
124+
a.onNext(v);
125+
126+
if (cancelled) {
127+
return;
128+
}
129+
130+
131+
boolean b;
132+
133+
try {
134+
b = iter.hasNext();
135+
} catch (Throwable ex) {
136+
Exceptions.throwIfFatal(ex);
137+
a.onError(ex);
138+
return;
139+
}
140+
141+
if (!b) {
142+
a.onComplete();
143+
return;
144+
}
145+
}
103146
}
104147

105148
@Override
@@ -125,75 +168,6 @@ public boolean isDisposed() {
125168
return cancelled;
126169
}
127170

128-
void drain() {
129-
if (getAndIncrement() != 0) {
130-
return;
131-
}
132-
133-
Observer<? super R> a = actual;
134-
Iterator<? extends R> iter = this.it;
135-
136-
if (outputFused && iter != null) {
137-
a.onNext(null);
138-
a.onComplete();
139-
return;
140-
}
141-
142-
int missed = 1;
143-
144-
for (;;) {
145-
146-
if (iter != null) {
147-
for (;;) {
148-
if (cancelled) {
149-
return;
150-
}
151-
152-
R v;
153-
154-
try {
155-
v = iter.next();
156-
} catch (Throwable ex) {
157-
Exceptions.throwIfFatal(ex);
158-
a.onError(ex);
159-
return;
160-
}
161-
162-
a.onNext(v);
163-
164-
if (cancelled) {
165-
return;
166-
}
167-
168-
169-
boolean b;
170-
171-
try {
172-
b = iter.hasNext();
173-
} catch (Throwable ex) {
174-
Exceptions.throwIfFatal(ex);
175-
a.onError(ex);
176-
return;
177-
}
178-
179-
if (!b) {
180-
a.onComplete();
181-
return;
182-
}
183-
}
184-
}
185-
186-
missed = addAndGet(-missed);
187-
if (missed == 0) {
188-
break;
189-
}
190-
191-
if (iter == null) {
192-
iter = it;
193-
}
194-
}
195-
}
196-
197171
@Override
198172
public int requestFusion(int mode) {
199173
if ((mode & ASYNC) != 0) {

src/main/java/io/reactivex/internal/operators/maybe/MaybeFromCompletable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void onSubscribe(Disposable d) {
6666
if (DisposableHelper.validate(this.d, d)) {
6767
this.d = d;
6868

69-
actual.onSubscribe(d);
69+
actual.onSubscribe(this);
7070
}
7171
}
7272

src/main/java/io/reactivex/internal/operators/maybe/MaybeFromSingle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void onSubscribe(Disposable d) {
6666
if (DisposableHelper.validate(this.d, d)) {
6767
this.d = d;
6868

69-
actual.onSubscribe(d);
69+
actual.onSubscribe(this);
7070
}
7171
}
7272

0 commit comments

Comments
 (0)