Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/disposables/EmptyDisposable.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.disposables;
15
16 import io.reactivex.rxjava3.annotations.Nullable;
17 import io.reactivex.rxjava3.core.*;
18 import io.reactivex.rxjava3.operators.QueueDisposable;
19
20 /**
21 * Represents a stateless empty Disposable that reports being always
22 * empty and disposed.
23 * <p>It is also async-fuseable but empty all the time.
24 * <p>Since EmptyDisposable implements QueueDisposable and is empty,
25 * don't use it in tests and then signal onNext with it;
26 * use Disposables.empty() instead.
27 */
28 public enum EmptyDisposable implements QueueDisposable<Object> {
29 /**
30 * Since EmptyDisposable implements QueueDisposable and is empty,
31 * don't use it in tests and then signal onNext with it;
32 * use Disposables.empty() instead.
33 */
34 INSTANCE,
35 /**
36 * An empty disposable that returns false for isDisposed.
37 */
38 NEVER
39 ;
40
41 @Override
42 public void dispose() {
43 // no-op
44 }
45
46 @Override
47 public boolean isDisposed() {
48 return this == INSTANCE;
49 }
50
51 public static void complete(Observer<?> observer) {
52 observer.onSubscribe(INSTANCE);
53 observer.onComplete();
54 }
55
56 public static void complete(MaybeObserver<?> observer) {
57 observer.onSubscribe(INSTANCE);
58 observer.onComplete();
59 }
60
61 public static void error(Throwable e, Observer<?> observer) {
62 observer.onSubscribe(INSTANCE);
63 observer.onError(e);
64 }
65
66 public static void complete(CompletableObserver observer) {
67 observer.onSubscribe(INSTANCE);
68 observer.onComplete();
69 }
70
71 public static void error(Throwable e, CompletableObserver observer) {
72 observer.onSubscribe(INSTANCE);
73 observer.onError(e);
74 }
75
76 public static void error(Throwable e, SingleObserver<?> observer) {
77 observer.onSubscribe(INSTANCE);
78 observer.onError(e);
79 }
80
81 public static void error(Throwable e, MaybeObserver<?> observer) {
82 observer.onSubscribe(INSTANCE);
83 observer.onError(e);
84 }
85
86 @Override
87 public boolean offer(Object value) {
88 throw new UnsupportedOperationException("Should not be called!");
89 }
90
91 @Override
92 public boolean offer(Object v1, Object v2) {
93 throw new UnsupportedOperationException("Should not be called!");
94 }
95
96 @Nullable
97 @Override
98 public Object poll() {
99 return null; // always empty
100 }
101
102 @Override
103 public boolean isEmpty() {
104 return true; // always empty
105 }
106
107 @Override
108 public void clear() {
109 // nothing to do
110 }
111
112 @Override
113 public int requestFusion(int mode) {
114 return mode & ASYNC;
115 }
116
117 }