Skip to content

Commit 7f07f46

Browse files
JakeWhartonakarnokd
authored andcommitted
Extract 'WithUpstream' interfaces. (#4326)
This allows use with types that do not extend directly from their base stream types.
1 parent 344453f commit 7f07f46

File tree

153 files changed

+250
-208
lines changed

Some content is hidden

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

153 files changed

+250
-208
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright 2016 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.reactivex.internal.operators.flowable;
15+
16+
import org.reactivestreams.Publisher;
17+
18+
import io.reactivex.Flowable;
19+
import io.reactivex.internal.functions.Objects;
20+
21+
/**
22+
* Abstract base class for operators that take an upstream
23+
* source {@link Publisher}.
24+
*
25+
* @param <T> the upstream value type
26+
* @param <R> the output value type
27+
*/
28+
abstract class AbstractFlowableWithUpstream<T, R> extends Flowable<R> implements FlowableWithUpstream<T> {
29+
30+
/**
31+
* The upstream source Publisher.
32+
*/
33+
protected final Publisher<T> source;
34+
35+
/**
36+
* Constructs a FlowableSource wrapping the given non-null (verified)
37+
* source Publisher.
38+
* @param source the source (upstream) Publisher instance, not null (verified)
39+
*/
40+
public AbstractFlowableWithUpstream(Publisher<T> source) {
41+
this.source = Objects.requireNonNull(source, "source is null");
42+
}
43+
44+
@Override
45+
public final Publisher<T> source() {
46+
return source;
47+
}
48+
}

src/main/java/io/reactivex/internal/operators/flowable/FlowableAll.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import io.reactivex.internal.subscriptions.*;
1919
import io.reactivex.plugins.RxJavaPlugins;
2020

21-
public final class FlowableAll<T> extends FlowableWithUpstream<T, Boolean> {
21+
public final class FlowableAll<T> extends AbstractFlowableWithUpstream<T, Boolean> {
2222

2323
final Predicate<? super T> predicate;
2424

src/main/java/io/reactivex/internal/operators/flowable/FlowableAny.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import io.reactivex.functions.Predicate;
1818
import io.reactivex.internal.subscriptions.*;
1919

20-
public final class FlowableAny<T> extends FlowableWithUpstream<T, Boolean> {
20+
public final class FlowableAny<T> extends AbstractFlowableWithUpstream<T, Boolean> {
2121
final Predicate<? super T> predicate;
2222
public FlowableAny(Publisher<T> source, Predicate<? super T> predicate) {
2323
super(source);

src/main/java/io/reactivex/internal/operators/flowable/FlowableBuffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import io.reactivex.internal.util.*;
2727
import io.reactivex.plugins.RxJavaPlugins;
2828

29-
public final class FlowableBuffer<T, C extends Collection<? super T>> extends FlowableWithUpstream<T, C> {
29+
public final class FlowableBuffer<T, C extends Collection<? super T>> extends AbstractFlowableWithUpstream<T, C> {
3030
final int size;
3131

3232
final int skip;

src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import io.reactivex.subscribers.*;
3131

3232
public final class FlowableBufferBoundary<T, U extends Collection<? super T>, Open, Close>
33-
extends FlowableWithUpstream<T, U> {
33+
extends AbstractFlowableWithUpstream<T, U> {
3434
final Callable<U> bufferSupplier;
3535
final Publisher<? extends Open> bufferOpen;
3636
final Function<? super Open, ? extends Publisher<? extends Close>> bufferClose;

src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferBoundarySupplier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import io.reactivex.subscribers.*;
3030

3131
public final class FlowableBufferBoundarySupplier<T, U extends Collection<? super T>, B>
32-
extends FlowableWithUpstream<T, U> {
32+
extends AbstractFlowableWithUpstream<T, U> {
3333
final Callable<? extends Publisher<B>> boundarySupplier;
3434
final Callable<U> bufferSupplier;
3535

src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferExactBoundary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import io.reactivex.subscribers.*;
2727

2828
public final class FlowableBufferExactBoundary<T, U extends Collection<? super T>, B>
29-
extends FlowableWithUpstream<T, U> {
29+
extends AbstractFlowableWithUpstream<T, U> {
3030
final Publisher<B> boundary;
3131
final Callable<U> bufferSupplier;
3232

src/main/java/io/reactivex/internal/operators/flowable/FlowableBufferTimed.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import io.reactivex.internal.util.QueueDrainHelper;
3030
import io.reactivex.subscribers.SerializedSubscriber;
3131

32-
public final class FlowableBufferTimed<T, U extends Collection<? super T>> extends FlowableWithUpstream<T, U> {
32+
public final class FlowableBufferTimed<T, U extends Collection<? super T>> extends AbstractFlowableWithUpstream<T, U> {
3333

3434
final long timespan;
3535
final long timeskip;

src/main/java/io/reactivex/internal/operators/flowable/FlowableCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @param <T> the source element type
3030
*/
31-
public final class FlowableCache<T> extends FlowableWithUpstream<T, T> {
31+
public final class FlowableCache<T> extends AbstractFlowableWithUpstream<T, T> {
3232
/** The cache and replay state. */
3333
final CacheState<T> state;
3434

src/main/java/io/reactivex/internal/operators/flowable/FlowableCollect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import io.reactivex.functions.BiConsumer;
2121
import io.reactivex.internal.subscriptions.*;
2222

23-
public final class FlowableCollect<T, U> extends FlowableWithUpstream<T, U> {
23+
public final class FlowableCollect<T, U> extends AbstractFlowableWithUpstream<T, U> {
2424

2525
final Callable<? extends U> initialSupplier;
2626
final BiConsumer<? super U, ? super T> collector;

0 commit comments

Comments
 (0)