當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。