hu.akarnokd.rxjava3.joins.JoinPatterns Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava3-extensions Show documentation
Show all versions of rxjava3-extensions Show documentation
RxJava 3.x extra sources, operators and components and ports of many 1.x companion libraries.
/*
* 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 java.util.*;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.*;
import io.reactivex.rxjava3.functions.*;
import io.reactivex.rxjava3.observers.SafeObserver;
/**
* Join patterns And, Then and When.
*/
final class JoinPatterns {
private JoinPatterns() { throw new IllegalStateException("No instances!"); }
/**
* Creates a pattern that matches when both observable sequences have an available element.
* @param left the left source
* @param right the right source
* @param the left value type
* @param the right value type
* @return the pattern with two sources 'and'-ed
*/
public static Pattern2 and(/* this */Observable left, Observable right) {
if (left == null) {
throw new NullPointerException("left");
}
if (right == null) {
throw new NullPointerException("right");
}
return new Pattern2(left, right);
}
/**
* Matches when the observable sequence has an available element and projects the element by invoking the selector function.
* @param source the source Observable
* @param selector the selector to map the source values into result values
* @param the source value type
* @param the result value type
* @return the new Plan0 representing the mapping
*/
public static Plan then(/* this */Observable source, Function super T1, ? extends R> selector) {
if (source == null) {
throw new NullPointerException("source");
}
if (selector == null) {
throw new NullPointerException("selector");
}
return new Pattern1(source).then(selector);
}
/**
* Joins together the results from several patterns.
* @param plans the array of plans with the common result type
* @param the result type
* @return the Observable coining the plans
*/
public static Observable when(Plan... plans) {
if (plans == null) {
throw new NullPointerException("plans");
}
return when(Arrays.asList(plans));
}
/**
* Joins together the results from several patterns.
* @param plans the iterable sequence of plans
* @param the common result type
* @return the Observable joining the plans
*/
public static Observable when(final Iterable extends Plan> plans) {
if (plans == null) {
throw new NullPointerException("plans");
}
return new Observable() {
@Override
protected void subscribeActual(final Observer super R> t1) {
final Map