Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableMapNotification.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.flowable;
15
16 import org.reactivestreams.Subscriber;
17
18 import io.reactivex.rxjava3.core.Flowable;
19 import io.reactivex.rxjava3.exceptions.*;
20 import io.reactivex.rxjava3.functions.*;
21 import io.reactivex.rxjava3.internal.subscribers.SinglePostCompleteSubscriber;
22
23 import java.util.Objects;
24
25 public final class FlowableMapNotification<T, R> extends AbstractFlowableWithUpstream<T, R> {
26
27 final Function<? super T, ? extends R> onNextMapper;
28 final Function<? super Throwable, ? extends R> onErrorMapper;
29 final Supplier<? extends R> onCompleteSupplier;
30
31 public FlowableMapNotification(
32 Flowable<T> source,
33 Function<? super T, ? extends R> onNextMapper,
34 Function<? super Throwable, ? extends R> onErrorMapper,
35 Supplier<? extends R> onCompleteSupplier) {
36 super(source);
37 this.onNextMapper = onNextMapper;
38 this.onErrorMapper = onErrorMapper;
39 this.onCompleteSupplier = onCompleteSupplier;
40 }
41
42 @Override
43 protected void subscribeActual(Subscriber<? super R> s) {
44 source.subscribe(new MapNotificationSubscriber<>(s, onNextMapper, onErrorMapper, onCompleteSupplier));
45 }
46
47 static final class MapNotificationSubscriber<T, R>
48 extends SinglePostCompleteSubscriber<T, R> {
49
50 private static final long serialVersionUID = 2757120512858778108L;
51 final Function<? super T, ? extends R> onNextMapper;
52 final Function<? super Throwable, ? extends R> onErrorMapper;
53 final Supplier<? extends R> onCompleteSupplier;
54
55 MapNotificationSubscriber(Subscriber<? super R> actual,
56 Function<? super T, ? extends R> onNextMapper,
57 Function<? super Throwable, ? extends R> onErrorMapper,
58 Supplier<? extends R> onCompleteSupplier) {
59 super(actual);
60 this.onNextMapper = onNextMapper;
61 this.onErrorMapper = onErrorMapper;
62 this.onCompleteSupplier = onCompleteSupplier;
63 }
64
65 @Override
66 public void onNext(T t) {
67 R p;
68
69 try {
70 p = Objects.requireNonNull(onNextMapper.apply(t), "The onNext publisher returned is null");
71 } catch (Throwable e) {
72 Exceptions.throwIfFatal(e);
73 downstream.onError(e);
74 return;
75 }
76
77 produced++;
78 downstream.onNext(p);
79 }
80
81 @Override
82 public void onError(Throwable t) {
83 R p;
84
85 try {
86 p = Objects.requireNonNull(onErrorMapper.apply(t), "The onError publisher returned is null");
87 } catch (Throwable e) {
88 Exceptions.throwIfFatal(e);
89 downstream.onError(new CompositeException(t, e));
90 return;
91 }
92
93 complete(p);
94 }
95
96 @Override
97 public void onComplete() {
98 R p;
99
100 try {
101 p = Objects.requireNonNull(onCompleteSupplier.get(), "The onComplete publisher returned is null");
102 } catch (Throwable e) {
103 Exceptions.throwIfFatal(e);
104 downstream.onError(e);
105 return;
106 }
107
108 complete(p);
109 }
110 }
111 }