Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableHide.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
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.rxjava3.internal.operators.flowable;
15
16 import org.reactivestreams.*;
17
18 import io.reactivex.rxjava3.core.*;
19 import io.reactivex.rxjava3.internal.subscriptions.SubscriptionHelper;
20
21 /**
22 * Hides the identity of the wrapped Flowable and its Subscription.
23 * @param <T> the value type
24 *
25 * @since 2.0
26 */
27 public final class FlowableHide<T> extends AbstractFlowableWithUpstream<T, T> {
28
29 public FlowableHide(Flowable<T> source) {
30 super(source);
31 }
32
33 @Override
34 protected void subscribeActual(Subscriber<? super T> s) {
35 source.subscribe(new HideSubscriber<>(s));
36 }
37
38 static final class HideSubscriber<T> implements FlowableSubscriber<T>, Subscription {
39
40 final Subscriber<? super T> downstream;
41
42 Subscription upstream;
43
44 HideSubscriber(Subscriber<? super T> downstream) {
45 this.downstream = downstream;
46 }
47
48 @Override
49 public void request(long n) {
50 upstream.request(n);
51 }
52
53 @Override
54 public void cancel() {
55 upstream.cancel();
56 }
57
58 @Override
59 public void onSubscribe(Subscription s) {
60 if (SubscriptionHelper.validate(this.upstream, s)) {
61 this.upstream = s;
62 downstream.onSubscribe(this);
63 }
64 }
65
66 @Override
67 public void onNext(T t) {
68 downstream.onNext(t);
69 }
70
71 @Override
72 public void onError(Throwable t) {
73 downstream.onError(t);
74 }
75
76 @Override
77 public void onComplete() {
78 downstream.onComplete();
79 }
80 }
81 }