Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/mixed/MaterializeSingleObserver.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.mixed;
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 * A consumer that implements the consumer types of Maybe, Single and Completable
22 * and turns their signals into Notifications for a SingleObserver.
23 * <p>History: 2.2.4 - experimental
24 * @param <T> the element type of the source
25 * @since 3.0.0
26 */
27 public final class MaterializeSingleObserver<T>
28 implements SingleObserver<T>, MaybeObserver<T>, CompletableObserver, Disposable {
29
30 final SingleObserver<? super Notification<T>> downstream;
31
32 Disposable upstream;
33
34 public MaterializeSingleObserver(SingleObserver<? super Notification<T>> downstream) {
35 this.downstream = downstream;
36 }
37
38 @Override
39 public void onSubscribe(Disposable d) {
40 if (DisposableHelper.validate(upstream, d)) {
41 this.upstream = d;
42 downstream.onSubscribe(this);
43 }
44 }
45
46 @Override
47 public void onComplete() {
48 downstream.onSuccess(Notification.createOnComplete());
49 }
50
51 @Override
52 public void onSuccess(T t) {
53 downstream.onSuccess(Notification.createOnNext(t));
54 }
55
56 @Override
57 public void onError(Throwable e) {
58 downstream.onSuccess(Notification.createOnError(e));
59 }
60
61 @Override
62 public boolean isDisposed() {
63 return upstream.isDisposed();
64 }
65
66 @Override
67 public void dispose() {
68 upstream.dispose();
69 }
70 }