Skip to content

Commit e13874d

Browse files
authored
3.x: disambiguate startWith+1 to startWithItem & startWithIterable (#6530)
1 parent 98561ce commit e13874d

20 files changed

+53
-37
lines changed

src/main/java/io/reactivex/Flowable.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -14598,20 +14598,23 @@ public final Flowable<T> sorted(Comparator<? super T> sortFunction) {
1459814598
* is expected to honor backpressure as well. If it violates this rule, it <em>may</em> throw an
1459914599
* {@code IllegalStateException} when the source {@code Publisher} completes.</dd>
1460014600
* <dt><b>Scheduler:</b></dt>
14601-
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
14601+
* <dd>{@code startWithIterable} does not operate by default on a particular {@link Scheduler}.</dd>
1460214602
* </dl>
1460314603
*
1460414604
* @param items
1460514605
* an Iterable that contains the items you want the modified Publisher to emit first
1460614606
* @return a Flowable that emits the items in the specified {@link Iterable} and then emits the items
1460714607
* emitted by the source Publisher
1460814608
* @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
14609+
* @see #startWithArray(Object...)
14610+
* @see #startWithItem(Object)
14611+
* @since 3.0.0
1460914612
*/
1461014613
@SuppressWarnings("unchecked")
1461114614
@CheckReturnValue
1461214615
@BackpressureSupport(BackpressureKind.FULL)
1461314616
@SchedulerSupport(SchedulerSupport.NONE)
14614-
public final Flowable<T> startWith(Iterable<? extends T> items) {
14617+
public final Flowable<T> startWithIterable(Iterable<? extends T> items) {
1461514618
return concatArray(fromIterable(items), this);
1461614619
}
1461714620

@@ -14656,23 +14659,26 @@ public final Flowable<T> startWith(Publisher<? extends T> other) {
1465614659
* is expected to honor backpressure as well. If it violates this rule, it <em>may</em> throw an
1465714660
* {@code IllegalStateException} when the source {@code Publisher} completes.</dd>
1465814661
* <dt><b>Scheduler:</b></dt>
14659-
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
14662+
* <dd>{@code startWithItem} does not operate by default on a particular {@link Scheduler}.</dd>
1466014663
* </dl>
1466114664
*
14662-
* @param value
14665+
* @param item
1466314666
* the item to emit first
1466414667
* @return a Flowable that emits the specified item before it begins to emit items emitted by the source
1466514668
* Publisher
1466614669
* @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
14670+
* @see #startWithArray(Object...)
14671+
* @see #startWithIterable(Iterable)
14672+
* @since 3.0.0
1466714673
*/
1466814674
@SuppressWarnings("unchecked")
1466914675
@CheckReturnValue
1467014676
@NonNull
1467114677
@BackpressureSupport(BackpressureKind.FULL)
1467214678
@SchedulerSupport(SchedulerSupport.NONE)
14673-
public final Flowable<T> startWith(T value) {
14674-
ObjectHelper.requireNonNull(value, "value is null");
14675-
return concatArray(just(value), this);
14679+
public final Flowable<T> startWithItem(T item) {
14680+
ObjectHelper.requireNonNull(item, "item is null");
14681+
return concatArray(just(item), this);
1467614682
}
1467714683

1467814684
/**
@@ -14694,6 +14700,8 @@ public final Flowable<T> startWith(T value) {
1469414700
* @return a Flowable that emits the specified items before it begins to emit items emitted by the source
1469514701
* Publisher
1469614702
* @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
14703+
* @see #startWithItem(Object)
14704+
* @see #startWithIterable(Iterable)
1469714705
*/
1469814706
@SuppressWarnings("unchecked")
1469914707
@CheckReturnValue

src/main/java/io/reactivex/Observable.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -12036,19 +12036,22 @@ public final Observable<T> sorted(Comparator<? super T> sortFunction) {
1203612036
* <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWith.png" alt="">
1203712037
* <dl>
1203812038
* <dt><b>Scheduler:</b></dt>
12039-
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
12039+
* <dd>{@code startWithIterable} does not operate by default on a particular {@link Scheduler}.</dd>
1204012040
* </dl>
1204112041
*
1204212042
* @param items
1204312043
* an Iterable that contains the items you want the modified ObservableSource to emit first
1204412044
* @return an Observable that emits the items in the specified {@link Iterable} and then emits the items
1204512045
* emitted by the source ObservableSource
1204612046
* @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
12047+
* @since 3.0.0
12048+
* @see #startWithItem(Object)
12049+
* @see #startWithArray(Object...)
1204712050
*/
1204812051
@SuppressWarnings("unchecked")
1204912052
@CheckReturnValue
1205012053
@SchedulerSupport(SchedulerSupport.NONE)
12051-
public final Observable<T> startWith(Iterable<? extends T> items) {
12054+
public final Observable<T> startWithIterable(Iterable<? extends T> items) {
1205212055
return concatArray(fromIterable(items), this);
1205312056
}
1205412057

@@ -12083,19 +12086,22 @@ public final Observable<T> startWith(ObservableSource<? extends T> other) {
1208312086
* <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWith.item.png" alt="">
1208412087
* <dl>
1208512088
* <dt><b>Scheduler:</b></dt>
12086-
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
12089+
* <dd>{@code startWithItem} does not operate by default on a particular {@link Scheduler}.</dd>
1208712090
* </dl>
1208812091
*
1208912092
* @param item
1209012093
* the item to emit first
1209112094
* @return an Observable that emits the specified item before it begins to emit items emitted by the source
1209212095
* ObservableSource
1209312096
* @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
12097+
* @see #startWithArray(Object...)
12098+
* @see #startWithIterable(Iterable)
12099+
* @since 3.0.0
1209412100
*/
1209512101
@SuppressWarnings("unchecked")
1209612102
@CheckReturnValue
1209712103
@SchedulerSupport(SchedulerSupport.NONE)
12098-
public final Observable<T> startWith(T item) {
12104+
public final Observable<T> startWithItem(T item) {
1209912105
ObjectHelper.requireNonNull(item, "item is null");
1210012106
return concatArray(just(item), this);
1210112107
}
@@ -12115,6 +12121,8 @@ public final Observable<T> startWith(T item) {
1211512121
* @return an Observable that emits the specified items before it begins to emit items emitted by the source
1211612122
* ObservableSource
1211712123
* @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
12124+
* @see #startWithItem(Object)
12125+
* @see #startWithIterable(Iterable)
1211812126
*/
1211912127
@SuppressWarnings("unchecked")
1212012128
@CheckReturnValue

src/test/java/io/reactivex/flowable/FlowableCovarianceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public Flowable<Movie> apply(List<List<Movie>> listOfLists) {
212212
@Override
213213
public Publisher<Movie> apply(Flowable<List<Movie>> movieList) {
214214
return movieList
215-
.startWith(new ArrayList<Movie>())
215+
.startWithItem(new ArrayList<Movie>())
216216
.buffer(2, 1)
217217
.skip(1)
218218
.flatMap(calculateDelta);

src/test/java/io/reactivex/flowable/FlowableNullTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -2103,12 +2103,12 @@ public void skipWhileNull() {
21032103

21042104
@Test(expected = NullPointerException.class)
21052105
public void startWithIterableNull() {
2106-
just1.startWith((Iterable<Integer>)null);
2106+
just1.startWithIterable((Iterable<Integer>)null);
21072107
}
21082108

21092109
@Test(expected = NullPointerException.class)
21102110
public void startWithIterableIteratorNull() {
2111-
just1.startWith(new Iterable<Integer>() {
2111+
just1.startWithIterable(new Iterable<Integer>() {
21122112
@Override
21132113
public Iterator<Integer> iterator() {
21142114
return null;
@@ -2118,12 +2118,12 @@ public Iterator<Integer> iterator() {
21182118

21192119
@Test(expected = NullPointerException.class)
21202120
public void startWithIterableOneNull() {
2121-
just1.startWith(Arrays.asList(1, null)).blockingSubscribe();
2121+
just1.startWithIterable(Arrays.asList(1, null)).blockingSubscribe();
21222122
}
21232123

21242124
@Test(expected = NullPointerException.class)
21252125
public void startWithSingleNull() {
2126-
just1.startWith((Integer)null);
2126+
just1.startWithItem((Integer)null);
21272127
}
21282128

21292129
@Test(expected = NullPointerException.class)

src/test/java/io/reactivex/flowable/FlowableStartWithTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void startWithIterable() {
3737
List<String> li = new ArrayList<String>();
3838
li.add("alpha");
3939
li.add("beta");
40-
List<String> values = Flowable.just("one", "two").startWith(li).toList().blockingGet();
40+
List<String> values = Flowable.just("one", "two").startWithIterable(li).toList().blockingGet();
4141

4242
assertEquals("alpha", values.get(0));
4343
assertEquals("beta", values.get(1));

src/test/java/io/reactivex/flowable/FlowableTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ public void justWithScheduler() {
968968
@Test
969969
public void startWithWithScheduler() {
970970
TestScheduler scheduler = new TestScheduler();
971-
Flowable<Integer> flowable = Flowable.just(3, 4).startWith(Arrays.asList(1, 2)).subscribeOn(scheduler);
971+
Flowable<Integer> flowable = Flowable.just(3, 4).startWithIterable(Arrays.asList(1, 2)).subscribeOn(scheduler);
972972

973973
Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
974974

src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ public Object apply(Object[] a) throws Exception {
13631363
}
13641364
},
13651365
128,
1366-
Flowable.error(new TestException()).startWith(1),
1366+
Flowable.error(new TestException()).startWithItem(1),
13671367
Flowable.empty()
13681368
)
13691369
.test()

src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ public void errorInParentFlowable() {
499499
TestSubscriberEx<Integer> ts = new TestSubscriberEx<Integer>();
500500
Flowable.mergeDelayError(
501501
Flowable.just(Flowable.just(1), Flowable.just(2))
502-
.startWith(Flowable.<Integer> error(new RuntimeException()))
502+
.startWithItem(Flowable.<Integer> error(new RuntimeException()))
503503
).subscribe(ts);
504504
ts.awaitDone(5, TimeUnit.SECONDS);
505505
ts.assertTerminated();

src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public Flowable<Object> apply(Flowable<? extends Throwable> t1) {
145145
public Integer apply(Throwable t1) {
146146
return 1;
147147
}
148-
}).startWith(1).cast(Object.class);
148+
}).startWithItem(1).cast(Object.class);
149149
}
150150
})
151151
.doOnError(new Consumer<Throwable>() {
@@ -183,7 +183,7 @@ public Flowable<Object> apply(Flowable<? extends Throwable> t1) {
183183
public Integer apply(Throwable t1) {
184184
return 0;
185185
}
186-
}).startWith(0).cast(Object.class);
186+
}).startWithItem(0).cast(Object.class);
187187
}
188188
}).subscribe(subscriber);
189189

src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public void takeFlatMapCompletes() {
289289
.flatMap(new Function<Flowable<Integer>, Flowable<Integer>>() {
290290
@Override
291291
public Flowable<Integer> apply(Flowable<Integer> w) {
292-
return w.startWith(indicator);
292+
return w.startWithItem(indicator);
293293
}
294294
}).subscribe(ts);
295295

src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public void run() {
200200
.flatMap(new Function<Flowable<Integer>, Flowable<Integer>>() {
201201
@Override
202202
public Flowable<Integer> apply(Flowable<Integer> w) {
203-
return w.startWith(indicator)
203+
return w.startWithItem(indicator)
204204
.doOnComplete(new Action() {
205205
@Override
206206
public void run() {

src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ public Object apply(Object[] a) throws Exception {
951951
}
952952
},
953953
128,
954-
Observable.error(new TestException()).startWith(1),
954+
Observable.error(new TestException()).startWithItem(1),
955955
Observable.empty()
956956
)
957957
.test()

src/test/java/io/reactivex/internal/operators/observable/ObservableMergeDelayErrorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public void errorInParentObservable() {
493493
TestObserverEx<Integer> to = new TestObserverEx<Integer>();
494494
Observable.mergeDelayError(
495495
Observable.just(Observable.just(1), Observable.just(2))
496-
.startWith(Observable.<Integer> error(new RuntimeException()))
496+
.startWithItem(Observable.<Integer> error(new RuntimeException()))
497497
).subscribe(to);
498498
to.awaitDone(5, TimeUnit.SECONDS);
499499
to.assertTerminated();

src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public Observable<Object> apply(Observable<? extends Throwable> t1) {
147147
public Object apply(Throwable t1) {
148148
return 1;
149149
}
150-
}).startWith(1);
150+
}).startWithItem(1);
151151
}
152152
})
153153
.doOnError(new Consumer<Throwable>() {
@@ -185,7 +185,7 @@ public Observable<Object> apply(Observable<? extends Throwable> t1) {
185185
public Integer apply(Throwable t1) {
186186
return 0;
187187
}
188-
}).startWith(0).cast(Object.class);
188+
}).startWithItem(0).cast(Object.class);
189189
}
190190
}).subscribe(observer);
191191

src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public void takeFlatMapCompletes() {
251251
.flatMap(new Function<Observable<Integer>, Observable<Integer>>() {
252252
@Override
253253
public Observable<Integer> apply(Observable<Integer> w) {
254-
return w.startWith(indicator);
254+
return w.startWithItem(indicator);
255255
}
256256
}).subscribe(to);
257257

src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public void run() {
200200
.flatMap(new Function<Observable<Integer>, Observable<Integer>>() {
201201
@Override
202202
public Observable<Integer> apply(Observable<Integer> w) {
203-
return w.startWith(indicator)
203+
return w.startWithItem(indicator)
204204
.doOnComplete(new Action() {
205205
@Override
206206
public void run() {

src/test/java/io/reactivex/observable/ObservableCovarianceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public Observable<Movie> apply(List<List<Movie>> listOfLists) {
211211
@Override
212212
public Observable<Movie> apply(Observable<List<Movie>> movieList) {
213213
return movieList
214-
.startWith(new ArrayList<Movie>())
214+
.startWithItem(new ArrayList<Movie>())
215215
.buffer(2, 1)
216216
.skip(1)
217217
.flatMap(calculateDelta);

src/test/java/io/reactivex/observable/ObservableNullTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -2140,12 +2140,12 @@ public void skipWhileNull() {
21402140

21412141
@Test(expected = NullPointerException.class)
21422142
public void startWithIterableNull() {
2143-
just1.startWith((Iterable<Integer>)null);
2143+
just1.startWithIterable((Iterable<Integer>)null);
21442144
}
21452145

21462146
@Test(expected = NullPointerException.class)
21472147
public void startWithIterableIteratorNull() {
2148-
just1.startWith(new Iterable<Integer>() {
2148+
just1.startWithIterable(new Iterable<Integer>() {
21492149
@Override
21502150
public Iterator<Integer> iterator() {
21512151
return null;
@@ -2155,12 +2155,12 @@ public Iterator<Integer> iterator() {
21552155

21562156
@Test(expected = NullPointerException.class)
21572157
public void startWithIterableOneNull() {
2158-
just1.startWith(Arrays.asList(1, null)).blockingSubscribe();
2158+
just1.startWithIterable(Arrays.asList(1, null)).blockingSubscribe();
21592159
}
21602160

21612161
@Test(expected = NullPointerException.class)
21622162
public void startWithSingleNull() {
2163-
just1.startWith((Integer)null);
2163+
just1.startWithItem((Integer)null);
21642164
}
21652165

21662166
@Test(expected = NullPointerException.class)

src/test/java/io/reactivex/observable/ObservableStartWithTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void startWithIterable() {
3737
List<String> li = new ArrayList<String>();
3838
li.add("alpha");
3939
li.add("beta");
40-
List<String> values = Observable.just("one", "two").startWith(li).toList().blockingGet();
40+
List<String> values = Observable.just("one", "two").startWithIterable(li).toList().blockingGet();
4141

4242
assertEquals("alpha", values.get(0));
4343
assertEquals("beta", values.get(1));

src/test/java/io/reactivex/observable/ObservableTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ public void justWithScheduler() {
990990
@Test
991991
public void startWithWithScheduler() {
992992
TestScheduler scheduler = new TestScheduler();
993-
Observable<Integer> o = Observable.just(3, 4).startWith(Arrays.asList(1, 2)).subscribeOn(scheduler);
993+
Observable<Integer> o = Observable.just(3, 4).startWithIterable(Arrays.asList(1, 2)).subscribeOn(scheduler);
994994

995995
Observer<Integer> observer = TestHelper.mockObserver();
996996

0 commit comments

Comments
 (0)