Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/observable/ObservableSkipWhile.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.disposables.Disposable;
18 import io.reactivex.rxjava3.exceptions.Exceptions;
19 import io.reactivex.rxjava3.functions.Predicate;
20 import io.reactivex.rxjava3.internal.disposables.DisposableHelper;
21
22 public final class ObservableSkipWhile<T> extends AbstractObservableWithUpstream<T, T> {
23 final Predicate<? super T> predicate;
24 public ObservableSkipWhile(ObservableSource<T> source, Predicate<? super T> predicate) {
25 super(source);
26 this.predicate = predicate;
27 }
28
29 @Override
30 public void subscribeActual(Observer<? super T> observer) {
31 source.subscribe(new SkipWhileObserver<>(observer, predicate));
32 }
33
34 static final class SkipWhileObserver<T> implements Observer<T>, Disposable {
35 final Observer<? super T> downstream;
36 final Predicate<? super T> predicate;
37 Disposable upstream;
38 boolean notSkipping;
39 SkipWhileObserver(Observer<? super T> actual, Predicate<? super T> predicate) {
40 this.downstream = actual;
41 this.predicate = predicate;
42 }
43
44 @Override
45 public void onSubscribe(Disposable d) {
46 if (DisposableHelper.validate(this.upstream, d)) {
47 this.upstream = d;
48 downstream.onSubscribe(this);
49 }
50 }
51
52 @Override
53 public void dispose() {
54 upstream.dispose();
55 }
56
57 @Override
58 public boolean isDisposed() {
59 return upstream.isDisposed();
60 }
61
62 @Override
63 public void onNext(T t) {
64 if (notSkipping) {
65 downstream.onNext(t);
66 } else {
67 boolean b;
68 try {
69 b = predicate.test(t);
70 } catch (Throwable e) {
71 Exceptions.throwIfFatal(e);
72 upstream.dispose();
73 downstream.onError(e);
74 return;
75 }
76 if (!b) {
77 notSkipping = true;
78 downstream.onNext(t);
79 }
80 }
81 }
82
83 @Override
84 public void onError(Throwable t) {
85 downstream.onError(t);
86 }
87
88 @Override
89 public void onComplete() {
90 downstream.onComplete();
91 }
92 }
93 }