Skip to content

Commit 781191b

Browse files
Observable.concat: refactor varargs to overloads
ReactiveX#359 Varargs cause compiler warnings As part of this I also changed this: ```java public static <T> Observable<T> concat(Observable<Observable<? extends T>> observables) ``` to ```java public static <T> Observable<T> concat(Observable<Observable<T>> observables) ``` I documented the reasoning of this at ReactiveX#360 (comment)
1 parent e43a781 commit 781191b

File tree

4 files changed

+352
-14
lines changed

4 files changed

+352
-14
lines changed

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

Lines changed: 222 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,14 +979,232 @@ public static <T> Observable<T> merge(Observable<? extends T>... source) {
979979
* <p>
980980
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
981981
*
982-
* @param source
983-
* a series of Observables
982+
* @param observables
983+
* an Observable of Observables
984+
* @return an Observable that emits items that are the result of combining the items emitted by
985+
* the {@code source} Observables, one after the other
986+
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
987+
*/
988+
public static <T> Observable<T> concat(Observable<Observable<T>> observables) {
989+
return create(OperationConcat.concat(observables));
990+
}
991+
992+
/**
993+
* Returns an Observable that emits the items emitted by two or more Observables, one after the
994+
* other.
995+
* <p>
996+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
997+
*
998+
* @param t1
999+
* an Observable to be concatenated
1000+
* @param t2
1001+
* an Observable to be concatenated
1002+
* an Observable to be concatenated
1003+
* @return an Observable that emits items that are the result of combining the items emitted by
1004+
* the {@code source} Observables, one after the other
1005+
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
1006+
*/
1007+
@SuppressWarnings("unchecked")
1008+
// suppress because the types are checked by the method signature before using a vararg
1009+
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2) {
1010+
return create(OperationConcat.concat(t1, t2));
1011+
}
1012+
1013+
/**
1014+
* Returns an Observable that emits the items emitted by two or more Observables, one after the
1015+
* other.
1016+
* <p>
1017+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
1018+
*
1019+
* @param t1
1020+
* an Observable to be concatenated
1021+
* @param t2
1022+
* an Observable to be concatenated
1023+
* @param t3
1024+
* an Observable to be concatenated
1025+
* an Observable to be concatenated
1026+
* @return an Observable that emits items that are the result of combining the items emitted by
1027+
* the {@code source} Observables, one after the other
1028+
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
1029+
*/
1030+
@SuppressWarnings("unchecked")
1031+
// suppress because the types are checked by the method signature before using a vararg
1032+
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3) {
1033+
return create(OperationConcat.concat(t1, t2, t3));
1034+
}
1035+
1036+
/**
1037+
* Returns an Observable that emits the items emitted by two or more Observables, one after the
1038+
* other.
1039+
* <p>
1040+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
1041+
*
1042+
* @param t1
1043+
* an Observable to be concatenated
1044+
* @param t2
1045+
* an Observable to be concatenated
1046+
* @param t3
1047+
* an Observable to be concatenated
1048+
* @param t4
1049+
* an Observable to be concatenated
1050+
* @return an Observable that emits items that are the result of combining the items emitted by
1051+
* the {@code source} Observables, one after the other
1052+
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
1053+
*/
1054+
@SuppressWarnings("unchecked")
1055+
// suppress because the types are checked by the method signature before using a vararg
1056+
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4) {
1057+
return create(OperationConcat.concat(t1, t2, t3, t4));
1058+
}
1059+
1060+
/**
1061+
* Returns an Observable that emits the items emitted by two or more Observables, one after the
1062+
* other.
1063+
* <p>
1064+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
1065+
*
1066+
* @param t1
1067+
* an Observable to be concatenated
1068+
* @param t2
1069+
* an Observable to be concatenated
1070+
* @param t3
1071+
* an Observable to be concatenated
1072+
* @param t4
1073+
* an Observable to be concatenated
1074+
* @param t5
1075+
* an Observable to be concatenated
1076+
* @return an Observable that emits items that are the result of combining the items emitted by
1077+
* the {@code source} Observables, one after the other
1078+
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
1079+
*/
1080+
@SuppressWarnings("unchecked")
1081+
// suppress because the types are checked by the method signature before using a vararg
1082+
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5) {
1083+
return create(OperationConcat.concat(t1, t2, t3, t4, t5));
1084+
}
1085+
1086+
/**
1087+
* Returns an Observable that emits the items emitted by two or more Observables, one after the
1088+
* other.
1089+
* <p>
1090+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
1091+
*
1092+
* @param t1
1093+
* an Observable to be concatenated
1094+
* @param t2
1095+
* an Observable to be concatenated
1096+
* @param t3
1097+
* an Observable to be concatenated
1098+
* @param t4
1099+
* an Observable to be concatenated
1100+
* @param t5
1101+
* an Observable to be concatenated
1102+
* @param t6
1103+
* an Observable to be concatenated
1104+
* @return an Observable that emits items that are the result of combining the items emitted by
1105+
* the {@code source} Observables, one after the other
1106+
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
1107+
*/
1108+
@SuppressWarnings("unchecked")
1109+
// suppress because the types are checked by the method signature before using a vararg
1110+
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6) {
1111+
return create(OperationConcat.concat(t1, t2, t3, t4, t5, t6));
1112+
}
1113+
1114+
/**
1115+
* Returns an Observable that emits the items emitted by two or more Observables, one after the
1116+
* other.
1117+
* <p>
1118+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
1119+
*
1120+
* @param t1
1121+
* an Observable to be concatenated
1122+
* @param t2
1123+
* an Observable to be concatenated
1124+
* @param t3
1125+
* an Observable to be concatenated
1126+
* @param t4
1127+
* an Observable to be concatenated
1128+
* @param t5
1129+
* an Observable to be concatenated
1130+
* @param t6
1131+
* an Observable to be concatenated
1132+
* @param t7
1133+
* an Observable to be concatenated
9841134
* @return an Observable that emits items that are the result of combining the items emitted by
9851135
* the {@code source} Observables, one after the other
9861136
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
9871137
*/
988-
public static <T> Observable<T> concat(Observable<? extends T>... source) {
989-
return create(OperationConcat.concat(source));
1138+
@SuppressWarnings("unchecked")
1139+
// suppress because the types are checked by the method signature before using a vararg
1140+
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7) {
1141+
return create(OperationConcat.concat(t1, t2, t3, t4, t5, t6, t7));
1142+
}
1143+
1144+
/**
1145+
* Returns an Observable that emits the items emitted by two or more Observables, one after the
1146+
* other.
1147+
* <p>
1148+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
1149+
*
1150+
* @param t1
1151+
* an Observable to be concatenated
1152+
* @param t2
1153+
* an Observable to be concatenated
1154+
* @param t3
1155+
* an Observable to be concatenated
1156+
* @param t4
1157+
* an Observable to be concatenated
1158+
* @param t5
1159+
* an Observable to be concatenated
1160+
* @param t6
1161+
* an Observable to be concatenated
1162+
* @param t7
1163+
* an Observable to be concatenated
1164+
* @param t8
1165+
* an Observable to be concatenated
1166+
* @return an Observable that emits items that are the result of combining the items emitted by
1167+
* the {@code source} Observables, one after the other
1168+
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
1169+
*/
1170+
@SuppressWarnings("unchecked")
1171+
// suppress because the types are checked by the method signature before using a vararg
1172+
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7, Observable<? extends T> t8) {
1173+
return create(OperationConcat.concat(t1, t2, t3, t4, t5, t6, t7, t8));
1174+
}
1175+
1176+
/**
1177+
* Returns an Observable that emits the items emitted by two or more Observables, one after the
1178+
* other.
1179+
* <p>
1180+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
1181+
*
1182+
* @param t1
1183+
* an Observable to be concatenated
1184+
* @param t2
1185+
* an Observable to be concatenated
1186+
* @param t3
1187+
* an Observable to be concatenated
1188+
* @param t4
1189+
* an Observable to be concatenated
1190+
* @param t5
1191+
* an Observable to be concatenated
1192+
* @param t6
1193+
* an Observable to be concatenated
1194+
* @param t7
1195+
* an Observable to be concatenated
1196+
* @param t8
1197+
* an Observable to be concatenated
1198+
* @param t9
1199+
* an Observable to be concatenated
1200+
* @return an Observable that emits items that are the result of combining the items emitted by
1201+
* the {@code source} Observables, one after the other
1202+
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
1203+
*/
1204+
@SuppressWarnings("unchecked")
1205+
// suppress because the types are checked by the method signature before using a vararg
1206+
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4, Observable<? extends T> t5, Observable<? extends T> t6, Observable<? extends T> t7, Observable<? extends T> t8, Observable<? extends T> t9) {
1207+
return create(OperationConcat.concat(t1, t2, t3, t4, t5, t6, t7, t8, t9));
9901208
}
9911209

9921210
/**

rxjava-core/src/main/java/rx/operators/OperationConcat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static <T> OnSubscribeFunc<T> concat(final Observable<? extends T>... seq
6060
return concat(Observable.from(sequences));
6161
}
6262

63-
public static <T> OnSubscribeFunc<T> concat(final List<? extends Observable<? extends T>> sequences) {
63+
public static <T> OnSubscribeFunc<T> concat(final Iterable<? extends Observable<? extends T>> sequences) {
6464
return concat(Observable.from(sequences));
6565
}
6666

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package rx;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
7+
8+
import org.junit.Test;
9+
10+
public class ConcatTests {
11+
12+
@Test
13+
public void testConcatSimple() {
14+
Observable<String> o1 = Observable.from("one", "two");
15+
Observable<String> o2 = Observable.from("three", "four");
16+
17+
List<String> values = Observable.concat(o1, o2).toList().toBlockingObservable().single();
18+
19+
assertEquals("one", values.get(0));
20+
assertEquals("two", values.get(1));
21+
assertEquals("three", values.get(2));
22+
assertEquals("four", values.get(3));
23+
}
24+
25+
@Test
26+
public void testConcatWithObservableOfObservable() {
27+
Observable<String> o1 = Observable.from("one", "two");
28+
Observable<String> o2 = Observable.from("three", "four");
29+
Observable<String> o3 = Observable.from("five", "six");
30+
31+
Observable<Observable<String>> os = Observable.from(o1, o2, o3);
32+
33+
List<String> values = Observable.concat(os).toList().toBlockingObservable().single();
34+
35+
assertEquals("one", values.get(0));
36+
assertEquals("two", values.get(1));
37+
assertEquals("three", values.get(2));
38+
assertEquals("four", values.get(3));
39+
}
40+
41+
@Test
42+
public void testConcatWithIterableOfObservable() {
43+
Observable<String> o1 = Observable.from("one", "two");
44+
Observable<String> o2 = Observable.from("three", "four");
45+
Observable<String> o3 = Observable.from("five", "six");
46+
47+
@SuppressWarnings("unchecked")
48+
Iterable<Observable<String>> is = Arrays.asList(o1, o2, o3);
49+
50+
List<String> values = Observable.concat(Observable.from(is)).toList().toBlockingObservable().single();
51+
52+
assertEquals("one", values.get(0));
53+
assertEquals("two", values.get(1));
54+
assertEquals("three", values.get(2));
55+
assertEquals("four", values.get(3));
56+
}
57+
}

0 commit comments

Comments
 (0)