All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hu.akarnokd.rxjava3.expr.StatementSingle Maven / Gradle / Ivy

Go to download

RxJava 3.x extra sources, operators and components and ports of many 1.x companion libraries.

There is a newer version: 3.1.1
Show newest version
/*
 * Copyright 2016-2019 David Karnok
 *
 * 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 hu.akarnokd.rxjava3.expr;

import java.util.Map;

import io.reactivex.rxjava3.core.*;
import io.reactivex.rxjava3.functions.*;
import io.reactivex.rxjava3.internal.functions.ObjectHelper;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;

/**
 * Imperative statements expressed as Single operators.
 */
public final class StatementSingle {

    /** Factory class. */
    private StatementSingle() { throw new IllegalStateException("No instances!"); }

    /**
     * Return a particular one of several possible Singles based on a case
     * selector, or a default Single if the case selector does not map to
     * a particular one.
     * 

* * * @param * the case key type * @param * the result value type * @param caseSelector * the function that produces a case key when an * SingleObserver subscribes * @param mapOfCases * a map that maps a case key to a Single * @param defaultCase * the default Single if the {@code mapOfCases} doesn't contain a value for the key returned by the {@code caseSelector} * @return a particular Single chosen by key from the map of * Singles, or the default case if no Single matches the key */ public static Single switchCase(Supplier caseSelector, Map> mapOfCases, SingleSource defaultCase) { ObjectHelper.requireNonNull(caseSelector, "caseSelector is null"); ObjectHelper.requireNonNull(mapOfCases, "mapOfCases is null"); ObjectHelper.requireNonNull(defaultCase, "defaultCase is null"); return RxJavaPlugins.onAssembly(new SingleSwitchCase(caseSelector, mapOfCases, defaultCase)); } /** * Return a Single that emits the emissions from one specified * Single if a condition evaluates to true, or from another specified * Single otherwise. *

* * * @param * the result value type * @param condition * the condition that decides which Single to emit the * emissions from * @param then * the Single sequence to emit to if {@code condition} is {@code true} * @param orElse * the Single sequence to emit to if {@code condition} is {@code false} * @return a Single that mimics either the {@code then} or {@code orElse} Singles depending on a condition function */ public static Single ifThen(BooleanSupplier condition, SingleSource then, Single orElse) { ObjectHelper.requireNonNull(condition, "condition is null"); ObjectHelper.requireNonNull(then, "then is null"); ObjectHelper.requireNonNull(orElse, "orElse is null"); return RxJavaPlugins.onAssembly(new SingleIfThen(condition, then, orElse)); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy