Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/observable/ObservableHide.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.observable;
15
16 import io.reactivex.rxjava3.core.*;
17 import io.reactivex.rxjava3.disposables.Disposable;
18 import io.reactivex.rxjava3.internal.disposables.DisposableHelper;
19
20 /**
21 * Hides the identity of the wrapped ObservableSource and its Disposable.
22 * @param <T> the value type
23 *
24 * @since 2.0
25 */
26 public final class ObservableHide<T> extends AbstractObservableWithUpstream<T, T> {
27
28 public ObservableHide(ObservableSource<T> source) {
29 super(source);
30 }
31
32 @Override
33 protected void subscribeActual(Observer<? super T> o) {
34 source.subscribe(new HideDisposable<>(o));
35 }
36
37 static final class HideDisposable<T> implements Observer<T>, Disposable {
38
39 final Observer<? super T> downstream;
40
41 Disposable upstream;
42
43 HideDisposable(Observer<? super T> downstream) {
44 this.downstream = downstream;
45 }
46
47 @Override
48 public void dispose() {
49 upstream.dispose();
50 }
51
52 @Override
53 public boolean isDisposed() {
54 return upstream.isDisposed();
55 }
56
57 @Override
58 public void onSubscribe(Disposable d) {
59 if (DisposableHelper.validate(this.upstream, d)) {
60 this.upstream = d;
61 downstream.onSubscribe(this);
62 }
63 }
64
65 @Override
66 public void onNext(T t) {
67 downstream.onNext(t);
68 }
69
70 @Override
71 public void onError(Throwable t) {
72 downstream.onError(t);
73 }
74
75 @Override
76 public void onComplete() {
77 downstream.onComplete();
78 }
79 }
80 }