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