本文整理汇总了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"));
}
}
});
}
};
}
示例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"));
}
}
});
}
};
}
示例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"));
}
}
});
}
};
}
示例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"));
}
}
});
}
};
}
示例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()));
}
}
});
}
};
}
示例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()));
}
}
});
}
};
}
示例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;
};
}
示例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);
}
}
});
}
};
}
示例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;
}
示例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();
}
});
}
};
}
示例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);
}
});
}
示例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);
}
};
}
示例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));
}
}
};
}
示例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();
}
示例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();
}