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


Java Func2类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:MockLocationsActivity.java

示例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);
                }
            });
}
 
开发者ID:guzhigang001,项目名称:Bailan,代码行数:25,代码来源:RetryWhenNetworkException.java

示例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);
                }
            });
}
 
开发者ID:wzgiceman,项目名称:RxRetrofit-tokean,代码行数:23,代码来源:RetryWhenNetworkException.java

示例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);
                }
        });
}
 
开发者ID:HelloChenJinJun,项目名称:TestChat,代码行数:21,代码来源:RetryWhenNetWorkException.java

示例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));
                }
            });
        }
    });
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:19,代码来源:WebAppBaseImpl.java

示例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));
                }
            });
        }
    });
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:19,代码来源:WebAppBaseImpl.java

示例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);
  }
}
 
开发者ID:philipphager,项目名称:disclosure-android-app,代码行数:15,代码来源:AppService.java

示例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;
        }
    });
}
 
开发者ID:ebridfighter,项目名称:GongXianSheng,代码行数:26,代码来源:RxIdlingResource.java

示例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());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:26,代码来源:OperatorSequenceEqual.java

示例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;
        }
    };
}
 
开发者ID:MimiReader,项目名称:mimi-reader,代码行数:27,代码来源:PostItemsListFragment.java

示例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());
    }
  });
}
 
开发者ID:SmartDengg,项目名称:HttpService,代码行数:23,代码来源:RxJavaCallAdapterFactory.java

示例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);
}
 
开发者ID:liuyiVector,项目名称:zhihudailysoap,代码行数:19,代码来源:CommentPresenter.java

示例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());
}
 
开发者ID:Jay-Y,项目名称:yApp,代码行数:27,代码来源:GankPresenter.java

示例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());
                }
            });
}
 
开发者ID:hitherejoe,项目名称:Mondroid,代码行数:21,代码来源:DataManager.java

示例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));
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:27,代码来源:ApiPaginator.java


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