Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableSkipWhile.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.*;
17
18 import io.reactivex.rxjava3.core.*;
19 import io.reactivex.rxjava3.exceptions.Exceptions;
20 import io.reactivex.rxjava3.functions.Predicate;
21 import io.reactivex.rxjava3.internal.subscriptions.SubscriptionHelper;
22
23 public final class FlowableSkipWhile<T> extends AbstractFlowableWithUpstream<T, T> {
24 final Predicate<? super T> predicate;
25 public FlowableSkipWhile(Flowable<T> source, Predicate<? super T> predicate) {
26 super(source);
27 this.predicate = predicate;
28 }
29
30 @Override
31 protected void subscribeActual(Subscriber<? super T> s) {
32 source.subscribe(new SkipWhileSubscriber<>(s, predicate));
33 }
34
35 static final class SkipWhileSubscriber<T> implements FlowableSubscriber<T>, Subscription {
36 final Subscriber<? super T> downstream;
37 final Predicate<? super T> predicate;
38 Subscription upstream;
39 boolean notSkipping;
40 SkipWhileSubscriber(Subscriber<? super T> actual, Predicate<? super T> predicate) {
41 this.downstream = actual;
42 this.predicate = predicate;
43 }
44
45 @Override
46 public void onSubscribe(Subscription s) {
47 if (SubscriptionHelper.validate(this.upstream, s)) {
48 this.upstream = s;
49 downstream.onSubscribe(this);
50 }
51 }
52
53 @Override
54 public void onNext(T t) {
55 if (notSkipping) {
56 downstream.onNext(t);
57 } else {
58 boolean b;
59 try {
60 b = predicate.test(t);
61 } catch (Throwable e) {
62 Exceptions.throwIfFatal(e);
63 upstream.cancel();
64 downstream.onError(e);
65 return;
66 }
67 if (b) {
68 upstream.request(1);
69 } else {
70 notSkipping = true;
71 downstream.onNext(t);
72 }
73 }
74 }
75
76 @Override
77 public void onError(Throwable t) {
78 downstream.onError(t);
79 }
80
81 @Override
82 public void onComplete() {
83 downstream.onComplete();
84 }
85
86 @Override
87 public void request(long n) {
88 upstream.request(n);
89 }
90
91 @Override
92 public void cancel() {
93 upstream.cancel();
94 }
95
96 }
97 }