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


Java Function类代码示例

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


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

示例1: deleteAll

import io.reactivex.functions.Function; //导入依赖的package包/类
@Override
public Flowable<Integer> deleteAll() {
    if(shouldThrowError){
        shouldThrowError = false; // special case because the StoreService needs to call again getAll()
        return Flowable.error(new Exception("deleteAll.error"));
    }

    return getAll(null, null)
            .delay(1, TimeUnit.SECONDS)
            .flatMap(new Function<Optional<List<TestModel>>, Flowable<Integer>>() {
                @Override
                public Flowable<Integer> apply(Optional<List<TestModel>> ts) throws Exception {
                    return Flowable.just(ts.get().size());
                }
            });
}
 
开发者ID:playmoweb,项目名称:store2store,代码行数:17,代码来源:TestStore.java

示例2: initView

import io.reactivex.functions.Function; //导入依赖的package包/类
@Override public void initView(View view) {
  requestBaseInit(getPageTitle());
  mAdapter = new AllAppInfoAdapter(this, mAppInfos);
  mList.setLayoutManager(new LinearLayoutManager(getActivity()));
  mList.setAdapter(mAdapter);
  Observable.just("2")
      .subscribeOn(Schedulers.io())
      .map(new Function<String, List<AppUtils.AppInfo>>() {
        @Override public List<AppUtils.AppInfo> apply(@NonNull String s) throws Exception {
          return AppUtils.getAppsInfo();
        }
      })
      .observeOn(PausedHandlerScheduler.from(getHandler()))
      .compose(mLifecycleProvider.<List<AppUtils.AppInfo>>bindUntilEvent(FragmentEvent.DESTROY))
      .subscribe(new Consumer<List<AppUtils.AppInfo>>() {
        @Override public void accept(@NonNull List<AppUtils.AppInfo> appInfos) throws Exception {
          mAdapter.resetData(appInfos);
        }
      });
}
 
开发者ID:liuguoquan727,项目名称:android-study,代码行数:21,代码来源:AllAppInfoFragment.java

示例3: applyOperation

import io.reactivex.functions.Function; //导入依赖的package包/类
void applyOperation(final Function<List<T>, Update<T>> operation)
{
    synchronized (_batchingLock) {
        if (_batchedOperations != null) {
            _batchedOperations.add(operation);
            return;
        }
    }

    applyUpdate(new Function<List<T>, Update<T>>() {
        @Override
        public Update<T> apply(List<T> list) throws Exception
        {
            list = new ArrayList<>(list);

            return operation.apply(list);
        }
    });
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:20,代码来源:SimpleFlowableList.java

示例4: getAllClients

import io.reactivex.functions.Function; //导入依赖的package包/类
public static Observable<List<Client>> getAllClients() {
    ClientsService service = ServiceGenerator.createService(ClientsService.class);
    return service.getAllClients(UrlManager.getAllClientsURL())
            .flatMap(new Function<JsonElement, Observable<List<Client>>>() {
                @Override
                public Observable<List<Client>> apply(JsonElement jsonElement) throws Exception {
                    if(jsonElement != null) {
                        Log.i("Get All Clients" , "JSON: "+jsonElement.toString());
                        if(jsonElement.isJsonArray()) {
                            List<Client> clients = Client.ClientsListParser.fromJsonArray(jsonElement.getAsJsonArray());
                            return Observable.just(clients);
                        } else {
                            return Observable.error(new Exception("Expected a JSON Array"));
                        }
                    } else {
                        return Observable.just((List<Client>) new ArrayList<Client>());
                    }
                }
            }).observeOn(AndroidSchedulers.mainThread());
}
 
开发者ID:ayounes3333,项目名称:GSB-2017-Android,代码行数:21,代码来源:ClientsNetworkCalls.java

示例5: put

import io.reactivex.functions.Function; //导入依赖的package包/类
@Override
public Observable<StorageResult> put(Observable<Entry> entries) {
  return entries.flatMap((Function<Entry, ObservableSource<StorageResult>>) entry -> {
    final String insert =
        "INSERT OR REPLACE INTO TILES(zoom_level, tile_column, tile_row, tile_data)"
            + " values (?, ?, ?, ?);";

    byte[] compressedMvt;
    try {
      compressedMvt = CompressUtil.getCompressedAsGzip(entry.getVector());
    } catch (final IOException ex) {
      throw Exceptions.propagate(ex);
    }

    Observable<Object> params = Observable.<Object>just(entry.getZoomLevel(), entry.getColumn(),
        flipY(entry.getRow(), entry.getZoomLevel()), compressedMvt);

    return dataSource.update(insert)
        .parameterStream(params.toFlowable(BackpressureStrategy.BUFFER)).counts()
        .map(integer -> new StorageResult(entry))
        .onErrorReturn(throwable -> new StorageResult(entry, new Exception(throwable)))
        .toObservable();
  });
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:25,代码来源:StorageImpl.java

示例6: registerEvent

import io.reactivex.functions.Function; //导入依赖的package包/类
void registerEvent() {
    addSubscribe(RxBus.getDefault().toFlowable(NightModeEvent.class)
            .compose(RxUtil.<NightModeEvent>rxSchedulerHelper())
            .map(new Function<NightModeEvent, Boolean>() {
                @Override
                public Boolean apply(NightModeEvent nightModeEvent) {
                    return nightModeEvent.getNightMode();
                }
            })
            .subscribeWith(new CommonSubscriber<Boolean>(mView, "切换模式失败ヽ(≧Д≦)ノ") {
                @Override
                public void onNext(Boolean aBoolean) {
                    mView.useNightMode(aBoolean);
                }
            })
    );
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:MainPresenter.java

示例7: onScheduleCrashes

import io.reactivex.functions.Function; //导入依赖的package包/类
@Test
public void onScheduleCrashes() {
    RxSwingPlugins.setOnSchedule(new Function<Runnable, Runnable>() {
        @Override
        public Runnable apply(Runnable r) throws Exception {
            throw new IllegalStateException("Failure");
        }
    });

    try {
        RxSwingPlugins.onSchedule(Functions.EMPTY_RUNNABLE);
        Assert.fail("Should have thrown!");
    } catch (IllegalStateException ex) {
        Assert.assertEquals("Failure", ex.getMessage());
    }

    RxSwingPlugins.reset();

    Assert.assertSame(Functions.EMPTY_RUNNABLE, RxSwingPlugins.onSchedule(Functions.EMPTY_RUNNABLE));
}
 
开发者ID:akarnokd,项目名称:RxJava2Swing,代码行数:21,代码来源:RxSwingPluginsTest.java

示例8: news

import io.reactivex.functions.Function; //导入依赖的package包/类
/**
 * Informations sur une personne
 */
private Single<News> news(String idNews, String profile) {

    final String params = ServiceSecurity.construireParams(false,
            AllocineService.CODE, idNews,
            AllocineService.PROFILE, profile
    );

    final String sed = ServiceSecurity.getSED();
    final String sig = ServiceSecurity.getSIG(params, sed);

    return allocineService.news(idNews, profile, sed, sig)
            .map(new Function<AllocineResponse, News>() {
                @Override
                public News apply(AllocineResponse allocineResponse) throws Exception {
                    return null;
                }
            });
}
 
开发者ID:florent37,项目名称:Android-Allocine-Api,代码行数:22,代码来源:AllocineApi.java

示例9: getById

import io.reactivex.functions.Function; //导入依赖的package包/类
@Override
public Flowable<Optional<T>> getById(final int id) {
    List<Flowable<Optional<T>>> flowables = new ArrayList<>();
    Flowable<Optional<T>> flowStorage = dao.getById(id);

    if(hasSyncedStore()) {
        flowStorage = flowStorage
                .flatMap(new Function<Optional<T>, Flowable<Optional<T>>>() {
                    @Override
                    public Flowable<Optional<T>> apply(final Optional<T> item) throws Exception {
                        return syncedStore.insertOrUpdate(item.get());
                    }
                });

        flowables.add(syncedStore.getById(id));
    }

    flowables.add(flowStorage);
    return Flowable.concat(flowables);
}
 
开发者ID:playmoweb,项目名称:store2store,代码行数:21,代码来源:StoreService.java

示例10: execute

import io.reactivex.functions.Function; //导入依赖的package包/类
@Override
public <T> Observable<CacheResult<T>> execute(ApiCache apiCache, String cacheKey, Observable<T> source, Type type) {
    Observable<CacheResult<T>> cache = loadCache(apiCache, cacheKey, type);
    cache.onErrorReturn(new Function<Throwable, CacheResult<T>>() {
        @Override
        public CacheResult<T> apply(Throwable throwable) throws Exception {
            return null;
        }
    });
    Observable<CacheResult<T>> remote = loadRemote(apiCache, cacheKey, source);
    return Observable.concat(remote, cache).filter(new Predicate<CacheResult<T>>() {
        @Override
        public boolean test(CacheResult<T> tCacheResult) throws Exception {
            return tCacheResult != null && tCacheResult.getCacheData() != null;
        }
    }).firstElement().toObservable();
}
 
开发者ID:qiaodashaoye,项目名称:SuperHttp,代码行数:18,代码来源:FirstRemoteStrategy.java

示例11: startRefresh

import io.reactivex.functions.Function; //导入依赖的package包/类
@Override
protected void startRefresh(HandleBase<MultiHeaderEntity> refreshData) {
    Flowable.just(refreshData)
            .onBackpressureDrop()
            .observeOn(Schedulers.computation())
            .map(new Function<HandleBase<MultiHeaderEntity>, DiffUtil.DiffResult>() {
                @Override
                public DiffUtil.DiffResult apply(@NonNull HandleBase<MultiHeaderEntity> handleBase) throws Exception {
                    return handleRefresh(handleBase.getNewData(), handleBase.getNewHeader(), handleBase.getNewFooter(), handleBase.getType(), handleBase.getRefreshType());
                }
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<DiffUtil.DiffResult>() {
                @Override
                public void accept(@NonNull DiffUtil.DiffResult diffResult) throws Exception {
                    handleResult(diffResult);
                }
            });
}
 
开发者ID:crazysunj,项目名称:MultiTypeRecyclerViewAdapter,代码行数:20,代码来源:RxAdapterHelper.java

示例12: seedDatabaseQuestions

import io.reactivex.functions.Function; //导入依赖的package包/类
@Override
public Observable<Boolean> seedDatabaseQuestions() {

    GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
    final Gson gson = builder.create();

    return mDbHelper.isQuestionEmpty()
            .concatMap(new Function<Boolean, ObservableSource<? extends Boolean>>() {
                @Override
                public ObservableSource<? extends Boolean> apply(Boolean isEmpty)
                        throws Exception {
                    if (isEmpty) {
                        Type type = $Gson$Types
                                .newParameterizedTypeWithOwner(null, List.class,
                                        Question.class);
                        List<Question> questionList = gson.fromJson(
                                CommonUtils.loadJSONFromAsset(mContext,
                                        AppConstants.SEED_DATABASE_QUESTIONS),
                                type);

                        return saveQuestionList(questionList);
                    }
                    return Observable.just(false);
                }
            });
}
 
开发者ID:MindorksOpenSource,项目名称:android-mvp-architecture,代码行数:27,代码来源:AppDataManager.java

示例13: initView

import io.reactivex.functions.Function; //导入依赖的package包/类
@Override protected void initView(View parent) {
  requestBaseInit(getPageTitle());

  Observable.just("123")
      .subscribeOn(Schedulers.io())
      .map(new Function<String, Bitmap>() {
        @Override public Bitmap apply(@NonNull String s) throws Exception {
          return BitmapFactory.decodeResource(getResources(), R.drawable.test1);
        }
      })
      .observeOn(PausedHandlerScheduler.from(getHandler()))
      .compose(mLifecycleProvider.<Bitmap>bindUntilEvent(FragmentEvent.DESTROY))
      .subscribe(new Consumer<Bitmap>() {
        @Override public void accept(@NonNull Bitmap bitmap) throws Exception {
          mBitmap = bitmap;
          mImage.setImageBitmap(mBitmap);
        }
      });
}
 
开发者ID:liuguoquan727,项目名称:android-study,代码行数:20,代码来源:PixelEffectFragment.java

示例14: mainThreadCallsThroughToHook

import io.reactivex.functions.Function; //导入依赖的package包/类
@Test
public void mainThreadCallsThroughToHook() {
    final AtomicInteger called = new AtomicInteger();
    final Scheduler newScheduler = new EmptyScheduler();
    RxAndroidPlugins.setMainThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {
        @Override public Scheduler apply(Scheduler scheduler) {
            called.getAndIncrement();
            return newScheduler;
        }
    });

    assertSame(newScheduler, AndroidSchedulers.mainThread());
    assertEquals(1, called.get());

    assertSame(newScheduler, AndroidSchedulers.mainThread());
    assertEquals(2, called.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:AndroidSchedulersTest.java

示例15: directScheduleOnceUsesHook

import io.reactivex.functions.Function; //导入依赖的package包/类
@Test
public void directScheduleOnceUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    CountingRunnable counter = new CountingRunnable();
    scheduler.scheduleDirect(counter);

    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());

    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:HandlerSchedulerTest.java


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