Skip to content

Commit

Permalink
Observable.concat: refactor varargs to overloads
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
benjchristensen committed Sep 9, 2013
1 parent e43a781 commit 781191b
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 14 deletions.
226 changes: 222 additions & 4 deletions rxjava-core/src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,232 @@ public static <T> Observable<T> merge(Observable<? extends T>... source) {
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
*
* @param source
* a series of Observables
* @param observables
* an Observable of Observables
* @return an Observable that emits items that are the result of combining the items emitted by
* the {@code source} Observables, one after the other
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
*/
public static <T> Observable<T> concat(Observable<Observable<T>> observables) {
return create(OperationConcat.concat(observables));
}

/**
* Returns an Observable that emits the items emitted by two or more Observables, one after the
* other.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* an Observable to be concatenated
* @return an Observable that emits items that are the result of combining the items emitted by
* the {@code source} Observables, one after the other
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
*/
@SuppressWarnings("unchecked")
// suppress because the types are checked by the method signature before using a vararg
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2) {
return create(OperationConcat.concat(t1, t2));
}

/**
* Returns an Observable that emits the items emitted by two or more Observables, one after the
* other.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* an Observable to be concatenated
* @return an Observable that emits items that are the result of combining the items emitted by
* the {@code source} Observables, one after the other
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
*/
@SuppressWarnings("unchecked")
// suppress because the types are checked by the method signature before using a vararg
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3) {
return create(OperationConcat.concat(t1, t2, t3));
}

/**
* Returns an Observable that emits the items emitted by two or more Observables, one after the
* other.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @return an Observable that emits items that are the result of combining the items emitted by
* the {@code source} Observables, one after the other
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
*/
@SuppressWarnings("unchecked")
// suppress because the types are checked by the method signature before using a vararg
public static <T> Observable<T> concat(Observable<? extends T> t1, Observable<? extends T> t2, Observable<? extends T> t3, Observable<? extends T> t4) {
return create(OperationConcat.concat(t1, t2, t3, t4));
}

/**
* Returns an Observable that emits the items emitted by two or more Observables, one after the
* other.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @param t5
* an Observable to be concatenated
* @return an Observable that emits items that are the result of combining the items emitted by
* the {@code source} Observables, one after the other
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
*/
@SuppressWarnings("unchecked")
// suppress because the types are checked by the method signature before using a vararg
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) {
return create(OperationConcat.concat(t1, t2, t3, t4, t5));
}

/**
* Returns an Observable that emits the items emitted by two or more Observables, one after the
* other.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @param t5
* an Observable to be concatenated
* @param t6
* an Observable to be concatenated
* @return an Observable that emits items that are the result of combining the items emitted by
* the {@code source} Observables, one after the other
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
*/
@SuppressWarnings("unchecked")
// suppress because the types are checked by the method signature before using a vararg
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) {
return create(OperationConcat.concat(t1, t2, t3, t4, t5, t6));
}

/**
* Returns an Observable that emits the items emitted by two or more Observables, one after the
* other.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @param t5
* an Observable to be concatenated
* @param t6
* an Observable to be concatenated
* @param t7
* an Observable to be concatenated
* @return an Observable that emits items that are the result of combining the items emitted by
* the {@code source} Observables, one after the other
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
*/
public static <T> Observable<T> concat(Observable<? extends T>... source) {
return create(OperationConcat.concat(source));
@SuppressWarnings("unchecked")
// suppress because the types are checked by the method signature before using a vararg
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) {
return create(OperationConcat.concat(t1, t2, t3, t4, t5, t6, t7));
}

/**
* Returns an Observable that emits the items emitted by two or more Observables, one after the
* other.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @param t5
* an Observable to be concatenated
* @param t6
* an Observable to be concatenated
* @param t7
* an Observable to be concatenated
* @param t8
* an Observable to be concatenated
* @return an Observable that emits items that are the result of combining the items emitted by
* the {@code source} Observables, one after the other
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
*/
@SuppressWarnings("unchecked")
// suppress because the types are checked by the method signature before using a vararg
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) {
return create(OperationConcat.concat(t1, t2, t3, t4, t5, t6, t7, t8));
}

/**
* Returns an Observable that emits the items emitted by two or more Observables, one after the
* other.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/concat.png">
*
* @param t1
* an Observable to be concatenated
* @param t2
* an Observable to be concatenated
* @param t3
* an Observable to be concatenated
* @param t4
* an Observable to be concatenated
* @param t5
* an Observable to be concatenated
* @param t6
* an Observable to be concatenated
* @param t7
* an Observable to be concatenated
* @param t8
* an Observable to be concatenated
* @param t9
* an Observable to be concatenated
* @return an Observable that emits items that are the result of combining the items emitted by
* the {@code source} Observables, one after the other
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.concat(v=vs.103).aspx">MSDN: Observable.Concat Method</a>
*/
@SuppressWarnings("unchecked")
// suppress because the types are checked by the method signature before using a vararg
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) {
return create(OperationConcat.concat(t1, t2, t3, t4, t5, t6, t7, t8, t9));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static <T> OnSubscribeFunc<T> concat(final Observable<? extends T>... seq
return concat(Observable.from(sequences));
}

public static <T> OnSubscribeFunc<T> concat(final List<? extends Observable<? extends T>> sequences) {
public static <T> OnSubscribeFunc<T> concat(final Iterable<? extends Observable<? extends T>> sequences) {
return concat(Observable.from(sequences));
}

Expand Down
57 changes: 57 additions & 0 deletions rxjava-core/src/test/java/rx/ConcatTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package rx;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;

public class ConcatTests {

@Test
public void testConcatSimple() {
Observable<String> o1 = Observable.from("one", "two");
Observable<String> o2 = Observable.from("three", "four");

List<String> values = Observable.concat(o1, o2).toList().toBlockingObservable().single();

assertEquals("one", values.get(0));
assertEquals("two", values.get(1));
assertEquals("three", values.get(2));
assertEquals("four", values.get(3));
}

@Test
public void testConcatWithObservableOfObservable() {
Observable<String> o1 = Observable.from("one", "two");
Observable<String> o2 = Observable.from("three", "four");
Observable<String> o3 = Observable.from("five", "six");

Observable<Observable<String>> os = Observable.from(o1, o2, o3);

List<String> values = Observable.concat(os).toList().toBlockingObservable().single();

assertEquals("one", values.get(0));
assertEquals("two", values.get(1));
assertEquals("three", values.get(2));
assertEquals("four", values.get(3));
}

@Test
public void testConcatWithIterableOfObservable() {
Observable<String> o1 = Observable.from("one", "two");
Observable<String> o2 = Observable.from("three", "four");
Observable<String> o3 = Observable.from("five", "six");

@SuppressWarnings("unchecked")
Iterable<Observable<String>> is = Arrays.asList(o1, o2, o3);

List<String> values = Observable.concat(Observable.from(is)).toList().toBlockingObservable().single();

assertEquals("one", values.get(0));
assertEquals("two", values.get(1));
assertEquals("three", values.get(2));
assertEquals("four", values.get(3));
}
}
Loading

0 comments on commit 781191b

Please sign in to comment.