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


Java Observable.just方法代码示例

本文整理汇总了Java中io.reactivex.Observable.just方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.just方法的具体用法?Java Observable.just怎么用?Java Observable.just使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Observable的用法示例。


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

示例1: search

import io.reactivex.Observable; //导入方法依赖的package包/类
/**
 * Search for items
 */
public Observable<SearchViewState> search(String searchString) {
  // Empty String, so no search
  if (searchString.isEmpty()) {
    return Observable.just(new SearchViewState.SearchNotStartedYet());
  }

  // search for product
  return searchEngine.searchFor(searchString)
      .map(products -> {
        if (products.isEmpty()) {
          return new SearchViewState.EmptyResult(searchString);
        } else {
          return new SearchViewState.SearchResult(searchString, products);
        }
      })
      .startWith(new SearchViewState.Loading())
      .onErrorReturn(error -> new SearchViewState.Error(searchString, error));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:SearchInteractor.java

示例2: main

import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
    Observable<String> source1 =
            Observable.just("Alpha", "Beta", "Gamma", "Delta",
                    "Epsilon");
    Observable<String> source2 =
            Observable.just("Zeta", "Eta", "Theta");
    Observable.concat(source1, source2)
            .subscribe(i -> System.out.println("RECEIVED: " + i));
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:10,代码来源:Ch4_9.java

示例3: onSaveClicked

import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<Boolean> onSaveClicked() {
    // can't use cleverness like !PostUtils.isDirty(mLastSavedPost, mPost) here
    // consider: edit published post => hit back to auto-save => open again and hit "Save"
    // in this case we will end up not asking for confirmation! here again, we're conflating 2
    // kinds of "dirtiness": (1) dirty relative to auto-saved post, and, (2) dirty relative to
    // post on server TODO fix this behaviour!
    if (mPost.isDraft()) {
        return Observable.just(saveToServerExplicitly());
    }
    return Observables.getDialog(emitter -> {
        // confirm save for scheduled and published posts
        return new AlertDialog.Builder(mActivity)
                .setMessage(getString(R.string.alert_save_msg))
                .setPositiveButton(R.string.alert_save_yes, (dialog, which) -> {
                    emitter.onNext(saveToServerExplicitly());
                    emitter.onComplete();
                })
                .setNegativeButton(R.string.alert_save_no, (dialog, which) -> {
                    dialog.dismiss();
                    emitter.onNext(false);
                    emitter.onComplete();
                })
                .create();
    });
}
 
开发者ID:TryGhost,项目名称:Ghost-Android,代码行数:26,代码来源:PostEditFragment.java

示例4: returnAValue

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void returnAValue(){
    result = "";
    Observable<String> observer = Observable.just("Hello"); // provides datea
    observer.subscribe(s -> result=s); // Callable as subscriber
    assertTrue(result.equals("Hello"));
}
 
开发者ID:vogellacompany,项目名称:code-examples-android-expert,代码行数:8,代码来源:RxJavaUnitTest.java

示例5: applyCacheNetWork

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public <T> Observable<CacheResult<T>> applyCacheNetWork(@NonNull final Object key, Observable<T> observable, final LruDisk lruDisk, TypeToken<T> typeToken, boolean network) {
    final T query = lruDisk.query(key, typeToken);
    return (query == null || network) ?
            apply(key, observable, lruDisk, true)
            :
            Observable.just(new CacheResult<>(query, key, CacheResult.CacheType.CACHE));
}
 
开发者ID:7449,项目名称:RxNetWork,代码行数:9,代码来源:ApplyImpl.java

示例6: getSearchData

import io.reactivex.Observable; //导入方法依赖的package包/类
public static Observable<ArrayList<String>> getSearchData(String key) {
    ArrayList<String> data = getStudentList();
    ArrayList<String> result = new ArrayList<String>();
    for (int i = 0; i < data.size(); i++) {
        if (data.get(i).toUpperCase().contains(key.toUpperCase())) {
            result.add(data.get(i));
        }
    }
    Observable<ArrayList<String>> observable = Observable.just(result);
    return observable;
}
 
开发者ID:shuza,项目名称:RxAndroid-Examples,代码行数:12,代码来源:DataSource.java

示例7: main

import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
    Observable<String> source =
            Observable.just("Alpha", "Beta", "Gamma", "Delta",
                    "Epsilon");
    source.flatMap(s -> Observable.fromArray(s.split("")))
            .subscribe(System.out::println);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:8,代码来源:Ch4_5.java

示例8: getModules

import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<List<Module>> getModules(Context context) {
    if (mModules != null)
        return Observable.just(mModules);
    return Observable.fromCallable(() -> loadModulesFrom(context.getAssets().open(MODULES_JSON_PATH)))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnNext(modules -> mModules = modules);
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:9,代码来源:Modules.java

示例9: testSingle

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void testSingle() {
    Observable<String> source =
            Observable.just("Alpha", "Beta", "Gamma", "Delta",
                    "Zeta");
    List<String> allWithLengthFour = source.filter(s ->
            s.length() == 4)
            .toList()
            .blockingGet();
    assertTrue(allWithLengthFour.equals(Arrays.asList("Beta","Zeta")));
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:12,代码来源:Ch10_5.java

示例10: main

import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable source1=	Observable.range(1,5);
	Observable source2=Observable.just(10,20,30);
	Observable.concat(source1,source2).subscribe(new Consumer<Integer>() {

		@Override
		public void accept(Integer value) throws Exception {
			// TODO Auto-generated method stub
			System.out.println(value);
			
		}
	});

}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:16,代码来源:Demo_concat.java

示例11: getCallableObservable

import io.reactivex.Observable; //导入方法依赖的package包/类
private static Observable<String> getCallableObservable(final String selects) {
    if(isNetworkAvailable()) {
        Observable<String> observable = Observable.fromCallable(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return getAttrFromNetwork(selects);
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
        return observable;
    } else
        Log.e(TAG, "check your network connection");
    return Observable.just("");
}
 
开发者ID:skydoves,项目名称:SyncMarket,代码行数:16,代码来源:SyncMarket.java

示例12: oneOf

import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<?> oneOf(Observable<?> trigger, Observable<?> pending) {
    if (trigger == null) {
        return Observable.just(new Object());
    }
    return Observable.merge(trigger, pending);
}
 
开发者ID:ChangWeiBa,项目名称:AesExoPlayer,代码行数:7,代码来源:RxPermissions.java

示例13: FlaxActionObservableBuilder

import io.reactivex.Observable; //导入方法依赖的package包/类
public FlaxActionObservableBuilder() {
    actionObservable = Observable.just(new FlaxAction(FlaxAction.NONE));
}
 
开发者ID:CodyEngel,项目名称:Flax,代码行数:4,代码来源:FlaxActionObservableBuilder.java

示例14: postContrast

import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<ColorMatrixColorFilter> postContrast(float value) {
    return Observable.just(contrast(value));
}
 
开发者ID:hoanganhtuan95ptit,项目名称:EditPhoto,代码行数:4,代码来源:ContrastView.java

示例15: getObservable

import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<String> getObservable() {
    return Observable.just("one", "two", "three", "four", "five");
}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:4,代码来源:BufferExampleActivity.java


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