io.reactivex.rxjava3.internal.operators.observable.ObservableInternalHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redisson-all Show documentation
Show all versions of redisson-all Show documentation
Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC
/**
* 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.rxjava3.internal.operators.observable;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.rxjava3.core.*;
import io.reactivex.rxjava3.functions.*;
import io.reactivex.rxjava3.internal.functions.*;
import io.reactivex.rxjava3.observables.ConnectableObservable;
/**
* 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 Throwable {
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 Throwable {
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 Throwable {
ObservableSource o = Objects.requireNonNull(itemDelay.apply(v), "The itemDelay returned a null ObservableSource");
return new ObservableTake<>(o, 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) {
observer.onNext(v);
}
}
static final class ObserverOnError implements Consumer {
final Observer observer;
ObserverOnError(Observer observer) {
this.observer = observer;
}
@Override
public void accept(Throwable v) {
observer.onError(v);
}
}
static final class ObserverOnComplete implements Action {
final Observer observer;
ObserverOnComplete(Observer observer) {
this.observer = observer;
}
@Override
public void run() {
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 Throwable {
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 Throwable {
@SuppressWarnings("unchecked")
ObservableSource u = (ObservableSource)Objects.requireNonNull(mapper.apply(t), "The mapper returned a null ObservableSource");
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 Throwable {
return new ObservableFromIterable<>(Objects.requireNonNull(mapper.apply(t), "The mapper returned a null Iterable"));
}
}
public static Function> flatMapIntoIterable(final Function super T, ? extends Iterable extends U>> mapper) {
return new FlatMapIntoIterable<>(mapper);
}
enum MapToInt implements Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy