Skip to content

Commit 574efe5

Browse files
Observable.startWith: refactor varargs to overloads
ReactiveX#359 Varargs cause compiler warnings
1 parent 665f80a commit 574efe5

File tree

2 files changed

+242
-3
lines changed

2 files changed

+242
-3
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 209 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,13 +3279,219 @@ public Observable<List<T>> toSortedList(Func2<? super T, ? super T, Integer> sor
32793279
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
32803280
*
32813281
* @param values
3282-
* the items you want the modified Observable to emit first
3282+
* Iterable of the items you want the modified Observable to emit first
32833283
* @return an Observable that exhibits the modified behavior
32843284
*/
3285-
@SuppressWarnings("unchecked")
3286-
public Observable<T> startWith(T... values) {
3285+
public Observable<T> startWith(Iterable<T> values) {
32873286
return concat(Observable.<T> from(values), this);
32883287
}
3288+
3289+
/**
3290+
* Emit a specified set of items before beginning to emit items from the source Observable.
3291+
* <p>
3292+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
3293+
*
3294+
* @param t1
3295+
* item to include
3296+
* @param values
3297+
* Iterable of the items you want the modified Observable to emit first
3298+
* @return an Observable that exhibits the modified behavior
3299+
*/
3300+
public Observable<T> startWith(T t1) {
3301+
return concat(Observable.<T> from(t1), this);
3302+
}
3303+
3304+
/**
3305+
* Emit a specified set of items before beginning to emit items from the source Observable.
3306+
* <p>
3307+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
3308+
*
3309+
* @param t1
3310+
* item to include
3311+
* @param t2
3312+
* item to include
3313+
* @param values
3314+
* Iterable of the items you want the modified Observable to emit first
3315+
* @return an Observable that exhibits the modified behavior
3316+
*/
3317+
public Observable<T> startWith(T t1, T t2) {
3318+
return concat(Observable.<T> from(t1, t2), this);
3319+
}
3320+
3321+
/**
3322+
* Emit a specified set of items before beginning to emit items from the source Observable.
3323+
* <p>
3324+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
3325+
*
3326+
* @param t1
3327+
* item to include
3328+
* @param t2
3329+
* item to include
3330+
* @param t3
3331+
* item to include
3332+
* @param values
3333+
* Iterable of the items you want the modified Observable to emit first
3334+
* @return an Observable that exhibits the modified behavior
3335+
*/
3336+
public Observable<T> startWith(T t1, T t2, T t3) {
3337+
return concat(Observable.<T> from(t1, t2, t3), this);
3338+
}
3339+
3340+
/**
3341+
* Emit a specified set of items before beginning to emit items from the source Observable.
3342+
* <p>
3343+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
3344+
*
3345+
* @param t1
3346+
* item to include
3347+
* @param t2
3348+
* item to include
3349+
* @param t3
3350+
* item to include
3351+
* @param t4
3352+
* item to include
3353+
* @param values
3354+
* Iterable of the items you want the modified Observable to emit first
3355+
* @return an Observable that exhibits the modified behavior
3356+
*/
3357+
public Observable<T> startWith(T t1, T t2, T t3, T t4) {
3358+
return concat(Observable.<T> from(t1, t2, t3, t4), this);
3359+
}
3360+
3361+
/**
3362+
* Emit a specified set of items before beginning to emit items from the source Observable.
3363+
* <p>
3364+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
3365+
*
3366+
* @param t1
3367+
* item to include
3368+
* @param t2
3369+
* item to include
3370+
* @param t3
3371+
* item to include
3372+
* @param t4
3373+
* item to include
3374+
* @param t5
3375+
* item to include
3376+
* @param values
3377+
* Iterable of the items you want the modified Observable to emit first
3378+
* @return an Observable that exhibits the modified behavior
3379+
*/
3380+
public Observable<T> startWith(T t1, T t2, T t3, T t4, T t5) {
3381+
return concat(Observable.<T> from(t1, t2, t3, t4, t5), this);
3382+
}
3383+
3384+
/**
3385+
* Emit a specified set of items before beginning to emit items from the source Observable.
3386+
* <p>
3387+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
3388+
*
3389+
* @param t1
3390+
* item to include
3391+
* @param t2
3392+
* item to include
3393+
* @param t3
3394+
* item to include
3395+
* @param t4
3396+
* item to include
3397+
* @param t5
3398+
* item to include
3399+
* @param t6
3400+
* item to include
3401+
* @param values
3402+
* Iterable of the items you want the modified Observable to emit first
3403+
* @return an Observable that exhibits the modified behavior
3404+
*/
3405+
public Observable<T> startWith(T t1, T t2, T t3, T t4, T t5, T t6) {
3406+
return concat(Observable.<T> from(t1, t2, t3, t4, t5, t6), this);
3407+
}
3408+
3409+
/**
3410+
* Emit a specified set of items before beginning to emit items from the source Observable.
3411+
* <p>
3412+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
3413+
*
3414+
* @param t1
3415+
* item to include
3416+
* @param t2
3417+
* item to include
3418+
* @param t3
3419+
* item to include
3420+
* @param t4
3421+
* item to include
3422+
* @param t5
3423+
* item to include
3424+
* @param t6
3425+
* item to include
3426+
* @param t7
3427+
* item to include
3428+
* @param values
3429+
* Iterable of the items you want the modified Observable to emit first
3430+
* @return an Observable that exhibits the modified behavior
3431+
*/
3432+
public Observable<T> startWith(T t1, T t2, T t3, T t4, T t5, T t6, T t7) {
3433+
return concat(Observable.<T> from(t1, t2, t3, t4, t5, t6, t7), this);
3434+
}
3435+
3436+
/**
3437+
* Emit a specified set of items before beginning to emit items from the source Observable.
3438+
* <p>
3439+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
3440+
*
3441+
* @param t1
3442+
* item to include
3443+
* @param t2
3444+
* item to include
3445+
* @param t3
3446+
* item to include
3447+
* @param t4
3448+
* item to include
3449+
* @param t5
3450+
* item to include
3451+
* @param t6
3452+
* item to include
3453+
* @param t7
3454+
* item to include
3455+
* @param t8
3456+
* item to include
3457+
* @param values
3458+
* Iterable of the items you want the modified Observable to emit first
3459+
* @return an Observable that exhibits the modified behavior
3460+
*/
3461+
public Observable<T> startWith(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8) {
3462+
return concat(Observable.<T> from(t1, t2, t3, t4, t5, t6, t7, t8), this);
3463+
}
3464+
3465+
/**
3466+
* Emit a specified set of items before beginning to emit items from the source Observable.
3467+
* <p>
3468+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
3469+
*
3470+
* @param t1
3471+
* item to include
3472+
* @param t2
3473+
* item to include
3474+
* @param t3
3475+
* item to include
3476+
* @param t4
3477+
* item to include
3478+
* @param t5
3479+
* item to include
3480+
* @param t6
3481+
* item to include
3482+
* @param t7
3483+
* item to include
3484+
* @param t8
3485+
* item to include
3486+
* @param t9
3487+
* item to include
3488+
* @param values
3489+
* Iterable of the items you want the modified Observable to emit first
3490+
* @return an Observable that exhibits the modified behavior
3491+
*/
3492+
public Observable<T> startWith(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8, T t9) {
3493+
return concat(Observable.<T> from(t1, t2, t3, t4, t5, t6, t7, t8, t9), this);
3494+
}
32893495

32903496
/**
32913497
* Groups the items emitted by an Observable according to a specified criterion, and emits these
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package rx;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import org.junit.Test;
9+
10+
public class StartWithTests {
11+
12+
@Test
13+
public void startWith1() {
14+
List<String> values = Observable.from("one", "two").startWith("zero").toList().toBlockingObservable().single();
15+
16+
assertEquals("zero", values.get(0));
17+
assertEquals("two", values.get(2));
18+
}
19+
20+
@Test
21+
public void startWithIterable() {
22+
List<String> li = new ArrayList<String>();
23+
li.add("alpha");
24+
li.add("beta");
25+
List<String> values = Observable.from("one", "two").startWith(li).toList().toBlockingObservable().single();
26+
27+
assertEquals("alpha", values.get(0));
28+
assertEquals("beta", values.get(1));
29+
assertEquals("one", values.get(2));
30+
assertEquals("two", values.get(3));
31+
}
32+
33+
}

0 commit comments

Comments
 (0)