本文整理汇总了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");
}