本文整理匯總了Java中rx.functions.Func2類的典型用法代碼示例。如果您正苦於以下問題:Java Func2類的具體用法?Java Func2怎麽用?Java Func2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Func2類屬於rx.functions包,在下文中一共展示了Func2類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setMockMode
import rx.functions.Func2; //導入依賴的package包/類
private void setMockMode(boolean toggle) {
if (toggle) {
mockLocationSubscription =
Observable.zip(locationProvider.mockLocation(mockLocationObservable),
mockLocationObservable, new Func2<Status, Location, String>() {
int count = 0;
@Override
public String call(Status result, Location location) {
return new LocationToStringFunc().call(location) + " " + count++;
}
})
.subscribe(new DisplayTextOnViewAction(mockLocationView), new ErrorHandler());
} else {
mockLocationSubscription.unsubscribe();
}
}
示例2: call
import rx.functions.Func2; //導入依賴的package包/類
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
return observable
.zipWith(Observable.range(1, count + 1), new Func2<Throwable, Integer, Wrapper>() {
@Override
public Wrapper call(Throwable throwable, Integer integer) {
//壓縮規則 合並後的結果是一個Observable<Wrapper>
return new Wrapper(throwable, integer);
}
}).flatMap(new Func1<Wrapper, Observable<?>>() {
@Override
public Observable<?> call(Wrapper wrapper) {
//轉換規則
if ((wrapper.throwable instanceof ConnectException
|| wrapper.throwable instanceof SocketTimeoutException
|| wrapper.throwable instanceof TimeoutException)
&& wrapper.index < count + 1) { //如果超出重試次數也拋出錯誤,否則默認是會進入onCompleted
return Observable.timer(delay + (wrapper.index - 1) * increaseDelay, TimeUnit.MILLISECONDS);
}
return Observable.error(wrapper.throwable);
}
});
}
示例3: call
import rx.functions.Func2; //導入依賴的package包/類
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
return observable
.zipWith(Observable.range(1, count + 1), new Func2<Throwable, Integer, Wrapper>() {
@Override
public Wrapper call(Throwable throwable, Integer integer) {
return new Wrapper(throwable, integer);
}
}).flatMap(new Func1<Wrapper, Observable<?>>() {
@Override
public Observable<?> call(Wrapper wrapper) {
if ((wrapper.throwable instanceof ConnectException
|| wrapper.throwable instanceof SocketTimeoutException
|| wrapper.throwable instanceof TimeoutException)
&& wrapper.index < count + 1) { //如果超出重試次數也拋出錯誤,否則默認是會進入onCompleted
return Observable.timer(delay + (wrapper.index - 1) * increaseDelay, TimeUnit.MILLISECONDS);
}
return Observable.error(wrapper.throwable);
}
});
}
示例4: call
import rx.functions.Func2; //導入依賴的package包/類
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
return observable.zipWith(Observable.range(1, retryCount + 1), new Func2<Throwable, Integer, ExceptionWrapper>() {
@Override
public ExceptionWrapper call(Throwable throwable, Integer integer) {
return new ExceptionWrapper(integer, throwable);
}
}).flatMap(new Func1<ExceptionWrapper, Observable<?>>() {
@Override
public Observable<?> call(ExceptionWrapper exceptionWrapper) {
if ((exceptionWrapper.throwable instanceof ConnectException ||
exceptionWrapper.throwable instanceof SocketException ||
exceptionWrapper.throwable instanceof TimeoutException) && exceptionWrapper.index < retryCount + 1) {
return Observable.timer(delayTime + (exceptionWrapper.index - 1) * delayTime, java.util.concurrent.TimeUnit.MILLISECONDS);
}
return Observable.error(exceptionWrapper.throwable);
}
});
}
示例5: getAppSettingsAsync
import rx.functions.Func2; //導入依賴的package包/類
@Override
public Observable<Map<String, AppSetting>> getAppSettingsAsync() {
return Observable.zip(listAppSettings(), listSlotConfigurations(), new Func2<StringDictionaryInner, SlotConfigNamesResourceInner, Map<String, AppSetting>>() {
@Override
public Map<String, AppSetting> call(final StringDictionaryInner appSettingsInner, final SlotConfigNamesResourceInner slotConfigs) {
if (appSettingsInner == null || appSettingsInner.properties() == null) {
return null;
}
return Maps.asMap(appSettingsInner.properties().keySet(), new Function<String, AppSetting>() {
@Override
public AppSetting apply(String input) {
return new AppSettingImpl(input, appSettingsInner.properties().get(input),
slotConfigs != null && slotConfigs.appSettingNames() != null && slotConfigs.appSettingNames().contains(input));
}
});
}
});
}
示例6: getConnectionStringsAsync
import rx.functions.Func2; //導入依賴的package包/類
@Override
public Observable<Map<String, ConnectionString>> getConnectionStringsAsync() {
return Observable.zip(listConnectionStrings(), listSlotConfigurations(), new Func2<ConnectionStringDictionaryInner, SlotConfigNamesResourceInner, Map<String, ConnectionString>>() {
@Override
public Map<String, ConnectionString> call(final ConnectionStringDictionaryInner connectionStringsInner, final SlotConfigNamesResourceInner slotConfigs) {
if (connectionStringsInner == null || connectionStringsInner.properties() == null) {
return null;
}
return Maps.asMap(connectionStringsInner.properties().keySet(), new Function<String, ConnectionString>() {
@Override
public ConnectionString apply(String input) {
return new ConnectionStringImpl(input, connectionStringsInner.properties().get(input),
slotConfigs != null && slotConfigs.connectionStringNames() != null && slotConfigs.connectionStringNames().contains(input));
}
});
}
});
}
示例7: getSortingFunction
import rx.functions.Func2; //導入依賴的package包/類
public Func2<AppReport, AppReport, Integer> getSortingFunction(SortBy sortBy) {
switch (sortBy) {
case NAME:
return new SortByName();
case LIBRARY_COUNT:
return new SortByLibraryCount();
case ANALYZED_AT:
return new SortByAnalyzedAt();
case PERMISSION_COUNT:
return new SortByPermissionCount();
default:
throw new IllegalArgumentException("no sorting function for %s " + sortBy);
}
}
示例8: setupHooks
import rx.functions.Func2; //導入依賴的package包/類
private void setupHooks() {
RxJavaHooks.setOnObservableStart(new Func2<Observable, OnSubscribe, OnSubscribe>() {
@Override
public OnSubscribe call(Observable observable, OnSubscribe onSubscribe) {
incrementActiveSubscriptionsCount();
return onSubscribe;
}
});
RxJavaHooks.setOnObservableSubscribeError(new Func1<Throwable, Throwable>() {
@Override
public Throwable call(Throwable throwable) {
decrementActiveSubscriptionsCount();
return throwable;
}
});
RxJavaHooks.setOnObservableReturn(new Func1<Subscription, Subscription>() {
@Override
public Subscription call(Subscription subscription) {
decrementActiveSubscriptionsCount();
return subscription;
}
});
}
示例9: sequenceEqual
import rx.functions.Func2; //導入依賴的package包/類
public static <T> Observable<Boolean> sequenceEqual(Observable<? extends T> first, Observable<? extends T> second, final Func2<? super T, ? super T, Boolean> equality) {
return Observable.zip(materializeLite(first), materializeLite(second), new Func2<Object, Object, Boolean>() {
public Boolean call(Object t1, Object t2) {
boolean c1;
if (t1 == OperatorSequenceEqual.LOCAL_ONCOMPLETED) {
c1 = true;
} else {
c1 = false;
}
boolean c2;
if (t2 == OperatorSequenceEqual.LOCAL_ONCOMPLETED) {
c2 = true;
} else {
c2 = false;
}
if (c1 && c2) {
return Boolean.valueOf(true);
}
if (c1 || c2) {
return Boolean.valueOf(false);
}
return (Boolean) equality.call(t1, t2);
}
}).all(UtilityFunctions.identity());
}
示例10: hideThreads
import rx.functions.Func2; //導入依賴的package包/類
private Func2<ChanCatalog, List<HiddenThread>, ChanCatalog> hideThreads() {
return new Func2<ChanCatalog, List<HiddenThread>, ChanCatalog>() {
@Override
public ChanCatalog call(ChanCatalog chanCatalog, List<HiddenThread> hiddenThreads) {
if (chanCatalog != null) {
List<ChanPost> posts = new ArrayList<>();
for (ChanPost post : chanCatalog.getPosts()) {
boolean found = false;
for (HiddenThread hiddenThread : hiddenThreads) {
if (hiddenThread.threadId == post.getNo()) {
found = true;
}
}
if (!found) {
posts.add(post);
}
}
chanCatalog.setPosts(posts);
}
return chanCatalog;
}
};
}
示例11: call
import rx.functions.Func2; //導入依賴的package包/類
@Override public Observable<Long> call(Observable<? extends Throwable> errorObservable) {
return errorObservable.zipWith(Observable.range(INITIAL, maxConnectCount),
new Func2<Throwable, Integer, InnerThrowable>() {
@Override public InnerThrowable call(Throwable throwable, Integer i) {
if (throwable instanceof IOException) return new InnerThrowable(throwable, i);
return new InnerThrowable(throwable, i);
}
}).concatMap(new Func1<InnerThrowable, Observable<Long>>() {
@Override public Observable<Long> call(InnerThrowable innerThrowable) {
Integer currentCount = innerThrowable.getCurrentRetryCount();
if (RetryWhenFunc.this.maxConnectCount.equals(currentCount)) {
return Observable.error(innerThrowable.getThrowable());
}
/*use Schedulers#immediate() to keep on same thread */
return Observable.timer((long) Math.pow(2, currentCount), TimeUnit.SECONDS,
Schedulers.immediate());
}
});
}
示例12: fetchDataByNetWork
import rx.functions.Func2; //導入依賴的package包/類
@Override
public void fetchDataByNetWork(final int newsID) {
Observable<Comments> short_comments_service = RetrofitSingleton.getApiService((Activity) mCommentView).shortComment(newsID);
Observable<Comments> long_comments_service = RetrofitSingleton.getApiService((Activity) mCommentView).longComment(newsID);
Observable.zip(short_comments_service, long_comments_service, new Func2<Comments, Comments, Comments1>(){
@Override
public Comments1 call(Comments comments, Comments comments2) {
Comments1 comments1 = new Comments1();
comments1.long_comments = comments.comments;
comments1.short_comments = comments2.comments;
return comments1;
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(observer);
}
示例13: getObservable
import rx.functions.Func2; //導入依賴的package包/類
@Override
public Observable<List<Gank>> getObservable() {
if (resId == -1) return null;
return getDataSupports().getGankData(type, mCurrentPage, PAGE_SIZE)
.map(new Func1<GankData, List<Gank>>() {
@Override
public List<Gank> call(GankData gankData) {
return gankData.getResults();
}
})
.flatMap(new Func1<List<Gank>, Observable<Gank>>() {
@Override
public Observable<Gank> call(List<Gank> ganks) {
return Observable.from(ganks);
}
})
.toSortedList(new Func2<Gank, Gank, Integer>() {
@Override
public Integer call(Gank gank, Gank gank2) {
return gank2.getPublishedAt().compareTo(gank.getPublishedAt());
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
示例14: getAccountDetails
import rx.functions.Func2; //導入依賴的package包/類
public Single<AccountData> getAccountDetails() {
return getAccounts()
.flatMap(new Func1<AccountsResponse, Single<? extends AccountData>>() {
@Override
public Single<? extends AccountData> call(AccountsResponse accountsResponse) {
if (!accountsResponse.accounts.isEmpty()) {
String accountId = accountsResponse.accounts.get(0).id;
return Single.zip(getBalance(accountId), getTransactions(accountId),
new Func2<Balance, List<Transaction>, AccountData>() {
@Override
public AccountData call(Balance balance,
List<Transaction> transactions) {
return new AccountData(balance, transactions);
}
});
}
return Single.just(new AccountData());
}
});
}
示例15: ApiPaginator
import rx.functions.Func2; //導入依賴的package包/類
private ApiPaginator(
final @NonNull Observable<Void> nextPage,
final @NonNull Observable<Params> startOverWith,
final @NonNull Func1<Envelope, List<Data>> envelopeToListOfData,
final @NonNull Func1<Params, Observable<Envelope>> loadWithParams,
final @NonNull Func1<String, Observable<Envelope>> loadWithPaginationPath,
final @NonNull Func1<Envelope, String> envelopeToMoreUrl,
final @NonNull Func1<List<Data>, List<Data>> pageTransformation,
final boolean clearWhenStartingOver,
final @NonNull Func2<List<Data>, List<Data>, List<Data>> concater,
final boolean distinctUntilChanged
) {
this.nextPage = nextPage;
this.startOverWith = startOverWith;
this.envelopeToListOfData = envelopeToListOfData;
this.loadWithParams = loadWithParams;
this.envelopeToMoreUrl = envelopeToMoreUrl;
this.pageTransformation = pageTransformation;
this.loadWithPaginationPath = loadWithPaginationPath;
this.clearWhenStartingOver = clearWhenStartingOver;
this.concater = concater;
this.distinctUntilChanged = distinctUntilChanged;
this.paginatedData = this.startOverWith.switchMap(this::dataWithPagination);
this.loadingPage = this.startOverWith.switchMap(__ -> nextPage.scan(1, (accum, ___) -> accum + 1));
}