Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/single/SingleHide.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.single;
15
16 import io.reactivex.rxjava3.core.*;
17 import io.reactivex.rxjava3.disposables.Disposable;
18 import io.reactivex.rxjava3.internal.disposables.DisposableHelper;
19
20 public final class SingleHide<T> extends Single<T> {
21
22 final SingleSource<? extends T> source;
23
24 public SingleHide(SingleSource<? extends T> source) {
25 this.source = source;
26 }
27
28 @Override
29 protected void subscribeActual(SingleObserver<? super T> observer) {
30 source.subscribe(new HideSingleObserver<T>(observer));
31 }
32
33 static final class HideSingleObserver<T> implements SingleObserver<T>, Disposable {
34
35 final SingleObserver<? super T> downstream;
36
37 Disposable upstream;
38
39 HideSingleObserver(SingleObserver<? super T> downstream) {
40 this.downstream = downstream;
41 }
42
43 @Override
44 public void dispose() {
45 upstream.dispose();
46 }
47
48 @Override
49 public boolean isDisposed() {
50 return upstream.isDisposed();
51 }
52
53 @Override
54 public void onSubscribe(Disposable d) {
55 if (DisposableHelper.validate(this.upstream, d)) {
56 this.upstream = d;
57 downstream.onSubscribe(this);
58 }
59 }
60
61 @Override
62 public void onSuccess(T value) {
63 downstream.onSuccess(value);
64 }
65
66 @Override
67 public void onError(Throwable e) {
68 downstream.onError(e);
69 }
70 }
71
72 }