Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/observable/ObservableLift.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.observable;
15
16 import io.reactivex.rxjava3.core.*;
17 import io.reactivex.rxjava3.exceptions.Exceptions;
18 import io.reactivex.rxjava3.plugins.RxJavaPlugins;
19
20 import java.util.Objects;
21
22 /**
23 * Allows lifting operators into a chain of Observables.
24 *
25 * <p>By having a concrete ObservableSource as lift, operator fusing can now identify
26 * both the source and the operation inside it via casting, unlike the lambda version of this.
27 *
28 * @param <T> the upstream value type
29 * @param <R> the downstream parameter type
30 */
31 public final class ObservableLift<R, T> extends AbstractObservableWithUpstream<T, R> {
32 /** The actual operator. */
33 final ObservableOperator<? extends R, ? super T> operator;
34
35 public ObservableLift(ObservableSource<T> source, ObservableOperator<? extends R, ? super T> operator) {
36 super(source);
37 this.operator = operator;
38 }
39
40 @Override
41 public void subscribeActual(Observer<? super R> observer) {
42 Observer<? super T> liftedObserver;
43 try {
44 liftedObserver = Objects.requireNonNull(operator.apply(observer), "Operator " + operator + " returned a null Observer");
45 } catch (NullPointerException e) { // NOPMD
46 throw e;
47 } catch (Throwable e) {
48 Exceptions.throwIfFatal(e);
49 // can't call onError because no way to know if a Disposable has been set or not
50 // can't call onSubscribe because the call might have set a Disposable already
51 RxJavaPlugins.onError(e);
52
53 NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
54 npe.initCause(e);
55 throw npe;
56 }
57
58 source.subscribe(liftedObserver);
59 }
60 }