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

hu.akarnokd.rxjava3.joins.JoinObservable 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.joins;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;

/**
 * Represents an observable that supports join operations.
 *
 * @param  the value type joined
 */
public final class JoinObservable {

    private final Observable o;

    private JoinObservable(Observable o) {
        this.o = o;
    }

    /**
     * Creates a JoinObservable from a regular Observable.
     * @param  the value type
     * @param o the observable to wrap
     * @return the created JoinObservable instance
     */
    public static  JoinObservable from(Observable o) {
        return new JoinObservable(RxJavaPlugins.onAssembly(o));
    }

    /**
     * Returns a Pattern that matches when both Observables emit an item.
     * 

* * * @param the value type of the right Observable * @param right * an Observable to match with the source Observable * @return a Pattern object that matches when both Observables emit an item * @throws NullPointerException * if {@code right} is null * @see RxJava Wiki: and() * @see MSDN: Observable.And */ public Pattern2 and(Observable right) { return JoinPatterns.and(o, right); } /** * Joins together the results from several patterns via their plans. *

* * * @param the result type * @param plans * a series of plans created by use of the {@link #then} Observer on patterns * @return an Observable that emits the results from matching several patterns * @throws NullPointerException * if {@code plans} is null * @see RxJava Wiki: when() * @see MSDN: Observable.When */ public static JoinObservable when(Iterable> plans) { if (plans == null) { throw new NullPointerException("plans"); } return from(JoinPatterns.when(plans)); } /** * Joins together the results from several patterns via their plans. *

* * * @param the result type * @param plans * a series of plans created by use of the {@link #then} Observer on patterns * @return an Observable that emits the results from matching several patterns * @throws NullPointerException * if {@code plans} is null * @see RxJava Wiki: when() * @see MSDN: Observable.When */ public static JoinObservable when(Plan... plans) { return from(JoinPatterns.when(plans)); } /** * Joins the results from a pattern via its plan. *

* * * @param the result type * @param p1 * the plan to join, created by use of the {@link #then} Observer on a pattern * @return an Observable that emits the results from matching a pattern * @see RxJava Wiki: when() * @see MSDN: Observable.When */ @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1) { return from(JoinPatterns.when(p1)); } /** * Joins together the results from two patterns via their plans. *

* * * @param the result type * @param p1 * a plan, created by use of the {@link #then} Observer on a pattern * @param p2 * a plan, created by use of the {@link #then} Observer on a pattern * @return an Observable that emits the results from matching two patterns * @see RxJava Wiki: when() * @see MSDN: Observable.When */ @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2) { return from(JoinPatterns.when(p1, p2)); } /** * Joins together the results from three patterns via their plans. *

* * * @param the result type * @param p1 * a plan, created by use of the {@link #then} Observer on a pattern * @param p2 * a plan, created by use of the {@link #then} Observer on a pattern * @param p3 * a plan, created by use of the {@link #then} Observer on a pattern * @return an Observable that emits the results from matching three patterns * @see RxJava Wiki: when() * @see MSDN: Observable.When */ @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3) { return from(JoinPatterns.when(p1, p2, p3)); } /** * Joins together the results from four patterns via their plans. *

* * * @param the result type * @param p1 * a plan, created by use of the {@link #then} Observer on a pattern * @param p2 * a plan, created by use of the {@link #then} Observer on a pattern * @param p3 * a plan, created by use of the {@link #then} Observer on a pattern * @param p4 * a plan, created by use of the {@link #then} Observer on a pattern * @return an Observable that emits the results from matching four patterns * @see RxJava Wiki: when() * @see MSDN: Observable.When */ @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4) { return from(JoinPatterns.when(p1, p2, p3, p4)); } /** * Joins together the results from five patterns via their plans. *

* * * @param the result type * @param p1 * a plan, created by use of the {@link #then} Observer on a pattern * @param p2 * a plan, created by use of the {@link #then} Observer on a pattern * @param p3 * a plan, created by use of the {@link #then} Observer on a pattern * @param p4 * a plan, created by use of the {@link #then} Observer on a pattern * @param p5 * a plan, created by use of the {@link #then} Observer on a pattern * @return an Observable that emits the results from matching five patterns * @see RxJava Wiki: when() * @see MSDN: Observable.When */ @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5) { return from(JoinPatterns.when(p1, p2, p3, p4, p5)); } /** * Joins together the results from six patterns via their plans. *

* * * @param the result type * @param p1 * a plan, created by use of the {@link #then} Observer on a pattern * @param p2 * a plan, created by use of the {@link #then} Observer on a pattern * @param p3 * a plan, created by use of the {@link #then} Observer on a pattern * @param p4 * a plan, created by use of the {@link #then} Observer on a pattern * @param p5 * a plan, created by use of the {@link #then} Observer on a pattern * @param p6 * a plan, created by use of the {@link #then} Observer on a pattern * @return an Observable that emits the results from matching six patterns * @see RxJava Wiki: when() * @see MSDN: Observable.When */ @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5, Plan p6) { return from(JoinPatterns.when(p1, p2, p3, p4, p5, p6)); } /** * Joins together the results from seven patterns via their plans. *

* * * @param the result type * @param p1 * a plan, created by use of the {@link #then} Observer on a pattern * @param p2 * a plan, created by use of the {@link #then} Observer on a pattern * @param p3 * a plan, created by use of the {@link #then} Observer on a pattern * @param p4 * a plan, created by use of the {@link #then} Observer on a pattern * @param p5 * a plan, created by use of the {@link #then} Observer on a pattern * @param p6 * a plan, created by use of the {@link #then} Observer on a pattern * @param p7 * a plan, created by use of the {@link #then} Observer on a pattern * @return an Observable that emits the results from matching seven patterns * @see RxJava Wiki: when() * @see MSDN: Observable.When */ @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5, Plan p6, Plan p7) { return from(JoinPatterns.when(p1, p2, p3, p4, p5, p6, p7)); } /** * Joins together the results from eight patterns via their plans. *

* * * @param the result type * @param p1 * a plan, created by use of the {@link #then} Observer on a pattern * @param p2 * a plan, created by use of the {@link #then} Observer on a pattern * @param p3 * a plan, created by use of the {@link #then} Observer on a pattern * @param p4 * a plan, created by use of the {@link #then} Observer on a pattern * @param p5 * a plan, created by use of the {@link #then} Observer on a pattern * @param p6 * a plan, created by use of the {@link #then} Observer on a pattern * @param p7 * a plan, created by use of the {@link #then} Observer on a pattern * @param p8 * a plan, created by use of the {@link #then} Observer on a pattern * @return an Observable that emits the results from matching eight patterns * @see RxJava Wiki: when() * @see MSDN: Observable.When */ @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5, Plan p6, Plan p7, Plan p8) { return from(JoinPatterns.when(p1, p2, p3, p4, p5, p6, p7, p8)); } /** * Joins together the results from nine patterns via their plans. *

* * * @param the result type * @param p1 * a plan, created by use of the {@link #then} Observer on a pattern * @param p2 * a plan, created by use of the {@link #then} Observer on a pattern * @param p3 * a plan, created by use of the {@link #then} Observer on a pattern * @param p4 * a plan, created by use of the {@link #then} Observer on a pattern * @param p5 * a plan, created by use of the {@link #then} Observer on a pattern * @param p6 * a plan, created by use of the {@link #then} Observer on a pattern * @param p7 * a plan, created by use of the {@link #then} Observer on a pattern * @param p8 * a plan, created by use of the {@link #then} Observer on a pattern * @param p9 * a plan, created by use of the {@link #then} Observer on a pattern * @return an Observable that emits the results from matching nine patterns * @see RxJava Wiki: when() * @see MSDN: Observable.When */ @SuppressWarnings("unchecked") public static JoinObservable when(Plan p1, Plan p2, Plan p3, Plan p4, Plan p5, Plan p6, Plan p7, Plan p8, Plan p9) { return from(JoinPatterns.when(p1, p2, p3, p4, p5, p6, p7, p8, p9)); } /** * Matches when the Observable has an available item and projects the item by invoking the selector * function. *

* * * @param the result type * @param selector * selector that will be invoked for items emitted by the source Observable * @return a {@link Plan} that produces the projected results, to be fed (with other Plans) to the {@link #when} Observer * @throws NullPointerException * if {@code selector} is null * @see RxJava Wiki: then() * @see MSDN: Observable.Then */ public Plan then(Function selector) { return JoinPatterns.then(o, selector); } public Observable toObservable() { return o; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy