本文整理匯總了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));
}
示例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));
}
示例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();
});
}
示例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"));
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例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")));
}
示例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);
}
});
}
示例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("");
}
示例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);
}
示例13: FlaxActionObservableBuilder
import io.reactivex.Observable; //導入方法依賴的package包/類
public FlaxActionObservableBuilder() {
actionObservable = Observable.just(new FlaxAction(FlaxAction.NONE));
}
示例14: postContrast
import io.reactivex.Observable; //導入方法依賴的package包/類
private Observable<ColorMatrixColorFilter> postContrast(float value) {
return Observable.just(contrast(value));
}
示例15: getObservable
import io.reactivex.Observable; //導入方法依賴的package包/類
private Observable<String> getObservable() {
return Observable.just("one", "two", "three", "four", "five");
}