Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/maybe/MaybeHide.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.maybe;
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 upstream Maybe and its Disposable sent through onSubscribe.
22 *
23 * @param <T> the value type
24 */
25 public final class MaybeHide<T> extends AbstractMaybeWithUpstream<T, T> {
26
27 public MaybeHide(MaybeSource<T> source) {
28 super(source);
29 }
30
31 @Override
32 protected void subscribeActual(MaybeObserver<? super T> observer) {
33 source.subscribe(new HideMaybeObserver<>(observer));
34 }
35
36 static final class HideMaybeObserver<T> implements MaybeObserver<T>, Disposable {
37
38 final MaybeObserver<? super T> downstream;
39
40 Disposable upstream;
41
42 HideMaybeObserver(MaybeObserver<? super T> downstream) {
43 this.downstream = downstream;
44 }
45
46 @Override
47 public void dispose() {
48 upstream.dispose();
49 upstream = DisposableHelper.DISPOSED;
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
62 downstream.onSubscribe(this);
63 }
64 }
65
66 @Override
67 public void onSuccess(T value) {
68 downstream.onSuccess(value);
69 }
70
71 @Override
72 public void onError(Throwable e) {
73 downstream.onError(e);
74 }
75
76 @Override
77 public void onComplete() {
78 downstream.onComplete();
79 }
80 }
81 }