io.reactivex.observable.internal.operators.ObservableInternalHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava3-observable Show documentation
Show all versions of rxjava3-observable Show documentation
rxjava3-observable developed by David Karnok
The newest version!
/**
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/
package io.reactivex.observable.internal.operators;
import java.util.List;
import java.util.concurrent.*;
import io.reactivex.common.*;
import io.reactivex.common.functions.*;
import io.reactivex.common.internal.functions.*;
import io.reactivex.observable.*;
/**
* Helper utility class to support Observable with inner classes.
*/
public final class ObservableInternalHelper {
private ObservableInternalHelper() {
throw new IllegalStateException("No instances!");
}
static final class SimpleGenerator implements BiFunction, S> {
final Consumer> consumer;
SimpleGenerator(Consumer> consumer) {
this.consumer = consumer;
}
@Override
public S apply(S t1, Emitter t2) throws Exception {
consumer.accept(t2);
return t1;
}
}
public static BiFunction, S> simpleGenerator(Consumer> consumer) {
return new SimpleGenerator(consumer);
}
static final class SimpleBiGenerator implements BiFunction, S> {
final BiConsumer> consumer;
SimpleBiGenerator(BiConsumer> consumer) {
this.consumer = consumer;
}
@Override
public S apply(S t1, Emitter t2) throws Exception {
consumer.accept(t1, t2);
return t1;
}
}
public static BiFunction, S> simpleBiGenerator(BiConsumer> consumer) {
return new SimpleBiGenerator(consumer);
}
static final class ItemDelayFunction implements Function> {
final Function super T, ? extends ObservableSource> itemDelay;
ItemDelayFunction(Function super T, ? extends ObservableSource> itemDelay) {
this.itemDelay = itemDelay;
}
@Override
public ObservableSource apply(final T v) throws Exception {
return new ObservableTake(itemDelay.apply(v), 1).map(Functions.justFunction(v)).defaultIfEmpty(v);
}
}
public static Function> itemDelay(final Function super T, ? extends ObservableSource> itemDelay) {
return new ItemDelayFunction(itemDelay);
}
static final class ObserverOnNext implements Consumer {
final Observer observer;
ObserverOnNext(Observer observer) {
this.observer = observer;
}
@Override
public void accept(T v) throws Exception {
observer.onNext(v);
}
}
static final class ObserverOnError implements Consumer {
final Observer observer;
ObserverOnError(Observer observer) {
this.observer = observer;
}
@Override
public void accept(Throwable v) throws Exception {
observer.onError(v);
}
}
static final class ObserverOnComplete implements Action {
final Observer observer;
ObserverOnComplete(Observer observer) {
this.observer = observer;
}
@Override
public void run() throws Exception {
observer.onComplete();
}
}
public static Consumer observerOnNext(Observer observer) {
return new ObserverOnNext(observer);
}
public static Consumer observerOnError(Observer observer) {
return new ObserverOnError(observer);
}
public static Action observerOnComplete(Observer observer) {
return new ObserverOnComplete(observer);
}
static final class FlatMapWithCombinerInner implements Function {
private final BiFunction super T, ? super U, ? extends R> combiner;
private final T t;
FlatMapWithCombinerInner(BiFunction super T, ? super U, ? extends R> combiner, T t) {
this.combiner = combiner;
this.t = t;
}
@Override
public R apply(U w) throws Exception {
return combiner.apply(t, w);
}
}
static final class FlatMapWithCombinerOuter implements Function> {
private final BiFunction super T, ? super U, ? extends R> combiner;
private final Function super T, ? extends ObservableSource extends U>> mapper;
FlatMapWithCombinerOuter(BiFunction super T, ? super U, ? extends R> combiner,
Function super T, ? extends ObservableSource extends U>> mapper) {
this.combiner = combiner;
this.mapper = mapper;
}
@Override
public ObservableSource apply(final T t) throws Exception {
@SuppressWarnings("unchecked")
ObservableSource u = (ObservableSource)mapper.apply(t);
return new ObservableMap(u, new FlatMapWithCombinerInner(combiner, t));
}
}
public static Function> flatMapWithCombiner(
final Function super T, ? extends ObservableSource extends U>> mapper,
final BiFunction super T, ? super U, ? extends R> combiner) {
return new FlatMapWithCombinerOuter(combiner, mapper);
}
static final class FlatMapIntoIterable implements Function> {
private final Function super T, ? extends Iterable extends U>> mapper;
FlatMapIntoIterable(Function super T, ? extends Iterable extends U>> mapper) {
this.mapper = mapper;
}
@Override
public ObservableSource apply(T t) throws Exception {
return new ObservableFromIterable(mapper.apply(t));
}
}
public static Function> flatMapIntoIterable(final Function super T, ? extends Iterable extends U>> mapper) {
return new FlatMapIntoIterable(mapper);
}
enum MapToInt implements Function