Debian Codegraph @

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