当前位置: 首页>>代码示例>>Java>>正文


Java FlowableTransformer类代码示例

本文整理汇总了Java中io.reactivex.FlowableTransformer的典型用法代码示例。如果您正苦于以下问题:Java FlowableTransformer类的具体用法?Java FlowableTransformer怎么用?Java FlowableTransformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FlowableTransformer类属于io.reactivex包,在下文中一共展示了FlowableTransformer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleResult

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
/**
 * 统一返回结果处理
 * @param <T>
 * @return
 */
public static <T> FlowableTransformer<GankHttpResponse<T>, T> handleResult() {   //compose判断结果
    return new FlowableTransformer<GankHttpResponse<T>, T>() {
        @Override
        public Flowable<T> apply(Flowable<GankHttpResponse<T>> httpResponseFlowable) {
            return httpResponseFlowable.flatMap(new Function<GankHttpResponse<T>, Flowable<T>>() {
                @Override
                public Flowable<T> apply(GankHttpResponse<T> tGankHttpResponse) {
                    if(!tGankHttpResponse.getError()) {
                        return createData(tGankHttpResponse.getResults());
                    } else {
                        return Flowable.error(new ApiException("服务器返回error"));
                    }
                }
            });
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RxUtil.java

示例2: handleWXResult

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
/**
 * 统一返回结果处理
 * @param <T>
 * @return
 */
public static <T> FlowableTransformer<WXHttpResponse<T>, T> handleWXResult() {   //compose判断结果
    return new FlowableTransformer<WXHttpResponse<T>, T>() {
        @Override
        public Flowable<T> apply(Flowable<WXHttpResponse<T>> httpResponseFlowable) {
            return httpResponseFlowable.flatMap(new Function<WXHttpResponse<T>, Flowable<T>>() {
                @Override
                public Flowable<T> apply(WXHttpResponse<T> tWXHttpResponse) {
                    if(tWXHttpResponse.getCode() == 200) {
                        return createData(tWXHttpResponse.getNewslist());
                    } else {
                        return Flowable.error(new ApiException("服务器返回error"));
                    }
                }
            });
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RxUtil.java

示例3: handleMyResult

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
/**
 * 统一返回结果处理
 * @param <T>
 * @return
 */
public static <T> FlowableTransformer<MyHttpResponse<T>, T> handleMyResult() {   //compose判断结果
    return new FlowableTransformer<MyHttpResponse<T>, T>() {
        @Override
        public Flowable<T> apply(Flowable<MyHttpResponse<T>> httpResponseFlowable) {
            return httpResponseFlowable.flatMap(new Function<MyHttpResponse<T>, Flowable<T>>() {
                @Override
                public Flowable<T> apply(MyHttpResponse<T> tMyHttpResponse) {
                    if(tMyHttpResponse.getCode() == 200) {
                        return createData(tMyHttpResponse.getData());
                    } else {
                        return Flowable.error(new ApiException("服务器返回error"));
                    }
                }
            });
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RxUtil.java

示例4: handleGoldResult

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
/**
 * 统一返回结果处理
 * @param <T>
 * @return
 */
public static <T> FlowableTransformer<GoldHttpResponse<T>, T> handleGoldResult() {   //compose判断结果
    return new FlowableTransformer<GoldHttpResponse<T>, T>() {
        @Override
        public Flowable<T> apply(Flowable<GoldHttpResponse<T>> httpResponseFlowable) {
            return httpResponseFlowable.flatMap(new Function<GoldHttpResponse<T>, Flowable<T>>() {
                @Override
                public Flowable<T> apply(GoldHttpResponse<T> tGoldHttpResponse) {
                    if(tGoldHttpResponse.getResults() != null) {
                        return createData(tGoldHttpResponse.getResults());
                    } else {
                        return Flowable.error(new ApiException("服务器返回error"));
                    }
                }
            });
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RxUtil.java

示例5: handleWXResult

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
/**
 * 统一返回结果处理
 * @param <T>
 * @return
 */
public static <T> FlowableTransformer<WXHttpResponse<T>, T> handleWXResult() {   //compose判断结果
    return new FlowableTransformer<WXHttpResponse<T>, T>() {
        @Override
        public Flowable<T> apply(Flowable<WXHttpResponse<T>> httpResponseFlowable) {
            return httpResponseFlowable.flatMap(new Function<WXHttpResponse<T>, Flowable<T>>() {
                @Override
                public Flowable<T> apply(WXHttpResponse<T> tWXHttpResponse) {
                    if(tWXHttpResponse.getCode() == 200) {
                        return createData(tWXHttpResponse.getNewslist());
                    } else {
                        return Flowable.error(new ApiException(tWXHttpResponse.getMsg(), tWXHttpResponse.getCode()));
                    }
                }
            });
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RxUtil.java

示例6: handleMyResult

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
/**
 * 统一返回结果处理
 * @param <T>
 * @return
 */
public static <T> FlowableTransformer<MyHttpResponse<T>, T> handleMyResult() {   //compose判断结果
    return new FlowableTransformer<MyHttpResponse<T>, T>() {
        @Override
        public Flowable<T> apply(Flowable<MyHttpResponse<T>> httpResponseFlowable) {
            return httpResponseFlowable.flatMap(new Function<MyHttpResponse<T>, Flowable<T>>() {
                @Override
                public Flowable<T> apply(MyHttpResponse<T> tMyHttpResponse) {
                    if(tMyHttpResponse.getCode() == 200) {
                        return createData(tMyHttpResponse.getData());
                    } else {
                        return Flowable.error(new ApiException(tMyHttpResponse.getMessage(), tMyHttpResponse.getCode()));
                    }
                }
            });
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RxUtil.java

示例7: logFlowable

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
/**
 * Creates transform operator, which logs defined events in observable's lifecycle
 * @param msg     message
 * @param bitMask bitmask of events which you want to log
 * @param <T>     type
 * @return transformer
 */
public static <T> FlowableTransformer<T, T> logFlowable(final String msg, final int bitMask) {
    return upstream -> {
        if ((bitMask & LOG_SUBSCRIBE) > 0) {
            upstream = upstream.compose(fLogSubscribe(msg));
        }
        if ((bitMask & LOG_TERMINATE) > 0) {
            upstream = upstream.compose(fLogTerminate(msg));
        }
        if ((bitMask & LOG_ERROR) > 0) {
            upstream = upstream.compose(fLogError(msg));
        }
        if ((bitMask & LOG_COMPLETE) > 0) {
            upstream = upstream.compose(fLogComplete(msg));
        }
        if ((bitMask & LOG_NEXT_DATA) > 0) {
            upstream = upstream.compose(fLogNext(msg));
        } else if ((bitMask & LOG_NEXT_EVENT) > 0) {
            upstream = upstream.compose(fLogNextEvent(msg));
        }
        return upstream;
    };
}
 
开发者ID:Team-SOFTsk,项目名称:RxLog,代码行数:30,代码来源:RxLog.java

示例8: getApiTransformer

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
/**
 * 异常处理变换
 *
 * @return
 */
public static <T extends IModel> FlowableTransformer<T, T> getApiTransformer() {

    return new FlowableTransformer<T, T>() {
        @Override
        public Publisher<T> apply(Flowable<T> upstream) {
            return upstream.flatMap(new Function<T, Publisher<T>>() {
                @Override
                public Publisher<T> apply(T model) throws Exception {

                    if (model == null || model.isNull()) {
                        return Flowable.error(new NetError(model.getErrorMsg(), NetError.NoDataError));
                    } else if (model.isAuthError()) {
                        return Flowable.error(new NetError(model.getErrorMsg(), NetError.AuthError));
                    } else if (model.isBizError()) {
                        return Flowable.error(new NetError(model.getErrorMsg(), NetError.BusinessError));
                    } else {
                        return Flowable.just(model);
                    }
                }
            });
        }
    };
}
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:29,代码来源:XApi.java

示例9: subscribe

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
public <R> Disposable subscribe(Consumer<R> onNext, Consumer<Throwable> onError, Action onCompleted, FlowableTransformer<T, R> transformer)
{
    Flowable flowable = build(false);
    if (transformer != null)
        flowable = flowable.compose(transformer);

    if (onNext == null)
        onNext = data -> {};
    if (onError == null)
        onError = error -> { throw new OnErrorNotImplementedException(error); };
    if (onCompleted == null)
        onCompleted = () -> {};

    Consumer<R> actualOnNext = onNext;
    if (mQueuer != null && mQueueSubscriptionSafetyCheckEnabled)
        actualOnNext = RxBusUtil.wrapQueueConsumer(onNext, mQueuer);

    flowable = applySchedular(flowable);
    Disposable disposable = flowable.subscribe(actualOnNext, onError, onCompleted);
    if (mBoundObject != null)
        RxDisposableManager.addDisposable(mBoundObject, disposable);
    return disposable;
}
 
开发者ID:MFlisar,项目名称:RxBus2,代码行数:24,代码来源:RxBusBuilder.java

示例10: applySchedules

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
public static <T> FlowableTransformer<T, T> applySchedules(final IView view) {
    return new FlowableTransformer<T, T>() {
        @Override
        public Publisher<T> apply(Flowable<T> upstream) {
            return upstream.subscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Subscription>() {
                        @Override
                        public void accept(Subscription subscription) throws Exception {
                            view.showLoading();
                        }
                    })
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doOnTerminate(new Action() {
                        @Override
                        public void run() throws Exception {
                            view.hideLoading();
                        }
                    });
        }
    };
}
 
开发者ID:harrylefit,项目名称:EazyBaseMVP,代码行数:23,代码来源:RxUtils.java

示例11: forFlowable

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
public static <R extends Result> FlowableTransformer<R, R> forFlowable() {
    return upstream -> upstream.onErrorResumeNext(throwable -> {
        if(throwable instanceof StatusException) {
            StatusException statusException = (StatusException) throwable;

            if(statusException.getStatus().hasResolution()) {
                return Flowable.just((R) statusException.getResult());
            } else {
                return Flowable.error(throwable);
            }

        } else {
            return Flowable.error(throwable);
        }
    });
}
 
开发者ID:florent37,项目名称:RxGps,代码行数:17,代码来源:StatusExceptionResumeNextTransformer.java

示例12: collectStats

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
public static <T, R extends Number> FlowableTransformer<T, Pair<T, Statistics>> collectStats(
        final Function<? super T, ? extends R> function) {
    return new FlowableTransformer<T, Pair<T, Statistics>>() {

        @Override
        public Flowable<Pair<T, Statistics>> apply(Flowable<T> source) {
            return source.scan(Pair.create((T) null, Statistics.create()),
                    new BiFunction<Pair<T, Statistics>, T, Pair<T, Statistics>>() {
                        @Override
                        public Pair<T, Statistics> apply(Pair<T, Statistics> pair, T t) throws Exception {
                            return Pair.create(t, pair.b().add(function.apply(t)));
                        }
                    }).skip(1);
        }
    };
}
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:17,代码来源:Transformers.java

示例13: rebatchRequests

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
public static <T> FlowableTransformer<T, T> rebatchRequests(final int minRequest, final long maxRequest,
        final boolean constrainFirstRequestMin) {
    Preconditions.checkArgument(minRequest <= maxRequest, "minRequest cannot be greater than maxRequest");
    return new FlowableTransformer<T, T>() {

        @Override
        public Publisher<T> apply(Flowable<T> source) {
            if (minRequest == maxRequest && constrainFirstRequestMin) {
                return source.rebatchRequests(minRequest);
            } else {
                return source
                        .compose(Transformers.<T>minRequest(constrainFirstRequestMin ? minRequest : 1, minRequest))
                        .compose(Transformers.<T>maxRequest(maxRequest));
            }
        }
    };
}
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:18,代码来源:Transformers.java

示例14: testPassThroughWithCustomCompletion

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
@Test
public void testPassThroughWithCustomCompletion() {
    FlowableTransformer<Integer, Integer> sm = StateMachine2.builder() //
            .initialState("") //
            .transition(PASS_THROUGH_TRANSITION) //
            .completion(new Completion2<String, Integer>() {
                @Override
                public void accept(String state, Emitter<Integer> emitter) {
                    emitter.onComplete_();
                }
            }) //
            .requestBatchSize(1) //
            .build();
    Flowable.just(1, 2, 3, 4, 5, 6) //
            .compose(sm) //
            .test() //
            .assertValues(1, 2, 3, 4, 5, 6) //
            .assertComplete();
}
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:20,代码来源:FlowableStateMachineTest.java

示例15: testPassThroughEmitterCompletesTwice

import io.reactivex.FlowableTransformer; //导入依赖的package包/类
@Test
public void testPassThroughEmitterCompletesTwice() {
    FlowableTransformer<Integer, Integer> sm = StateMachine2.builder() //
            .initialState("") //
            .transition(PASS_THROUGH_TRANSITION) //
            .completion(new Completion2<String, Integer>() {
                @Override
                public void accept(String state, Emitter<Integer> emitter) {
                    emitter.onComplete_();
                    emitter.onComplete_();
                }
            }) //
            .requestBatchSize(1) //
            .build();
    Flowable.just(1, 2, 3, 4, 5, 6) //
            .compose(sm) //
            .test() //
            .assertValues(1, 2, 3, 4, 5, 6) //
            .assertComplete();
}
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:21,代码来源:FlowableStateMachineTest.java


注:本文中的io.reactivex.FlowableTransformer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。