Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/maybe/MaybeIgnoreElement.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 * Turns an onSuccess into an onComplete, onError and onComplete is relayed as is.
22 *
23 * @param <T> the value type
24 */
25 public final class MaybeIgnoreElement<T> extends AbstractMaybeWithUpstream<T, T> {
26
27 public MaybeIgnoreElement(MaybeSource<T> source) {
28 super(source);
29 }
30
31 @Override
32 protected void subscribeActual(MaybeObserver<? super T> observer) {
33 source.subscribe(new IgnoreMaybeObserver<>(observer));
34 }
35
36 static final class IgnoreMaybeObserver<T> implements MaybeObserver<T>, Disposable {
37
38 final MaybeObserver<? super T> downstream;
39
40 Disposable upstream;
41
42 IgnoreMaybeObserver(MaybeObserver<? super T> downstream) {
43 this.downstream = downstream;
44 }
45
46 @Override
47 public void onSubscribe(Disposable d) {
48 if (DisposableHelper.validate(this.upstream, d)) {
49 this.upstream = d;
50
51 downstream.onSubscribe(this);
52 }
53 }
54
55 @Override
56 public void onSuccess(T value) {
57 upstream = DisposableHelper.DISPOSED;
58 downstream.onComplete();
59 }
60
61 @Override
62 public void onError(Throwable e) {
63 upstream = DisposableHelper.DISPOSED;
64 downstream.onError(e);
65 }
66
67 @Override
68 public void onComplete() {
69 upstream = DisposableHelper.DISPOSED;
70 downstream.onComplete();
71 }
72
73 @Override
74 public boolean isDisposed() {
75 return upstream.isDisposed();
76 }
77
78 @Override
79 public void dispose() {
80 upstream.dispose();
81 upstream = DisposableHelper.DISPOSED;
82 }
83
84 }
85
86 }