本文整理汇总了Java中io.reactivex.Observable.map方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.map方法的具体用法?Java Observable.map怎么用?Java Observable.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Observable
的用法示例。
在下文中一共展示了Observable.map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkWechatResult
import io.reactivex.Observable; //导入方法依赖的package包/类
public static ObservableTransformer<WxPayResult, WxPayResult> checkWechatResult() {
return new ObservableTransformer<WxPayResult, WxPayResult>() {
@Override
public ObservableSource<WxPayResult> apply(Observable<WxPayResult> payResultObservable) {
return payResultObservable.map(new Function<WxPayResult, WxPayResult>() {
@Override
public WxPayResult apply(WxPayResult wxPayResult) {
if (!wxPayResult.isSucceed()) {
throw new PayFailedException(wxPayResult.getErrInfo());
}
return wxPayResult;
}
});
}
};
}
示例2: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<String> source = Observable.create(emitter -> {
try {
emitter.onNext("Alpha");
emitter.onNext("Beta");
emitter.onNext("Gamma");
emitter.onNext("Delta");
emitter.onNext("Epsilon");
emitter.onComplete();
} catch (Throwable e) {
emitter.onError(e);
}
});
Observable<Integer> lengths = source.map(String::length);
Observable<Integer> filtered = lengths.filter(i -> i >= 5);
filtered.subscribe(s -> System.out.println("RECEIVED: " +
s));
}
示例3: checkAliPayResult
import io.reactivex.Observable; //导入方法依赖的package包/类
public static ObservableTransformer<PayResult, PayResult> checkAliPayResult() {
return new ObservableTransformer<PayResult, PayResult>() {
@Override
public ObservableSource<PayResult> apply(Observable<PayResult> upstream) {
return upstream.map(new Function<PayResult, PayResult>() {
@Override
public PayResult apply(PayResult payResult) throws Exception {
if (!payResult.isSucceed()) {
throw new PayFailedException(payResult.getErrInfo());
}
return payResult;
}
});
}
};
}
示例4: processStock
import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<Tuple2<String, Double>> processStock(List<String> stocks, Function<String, String> f) {
Observable<String> stockNames = Observable.fromIterable(stocks);
Observable<String> urls = stockNames.map(s -> "https://finance.google.com/finance/historical?output=csv&q=" + s);
Observable<Optional<String>> optionalObservable = urls
.subscribeOn(Schedulers.from(executorService))
.flatMap(s -> {
try {
return Observable.just(Optional.of(f.apply(s)));
} catch (Throwable t) {
return Observable.just(Optional.<String>empty());
}
})
.observeOn(Schedulers.computation())
.map(opt -> opt.map(doc -> doc.split("\n")[1].split(",")[4]))
.doOnNext(x -> System.out.println(">>>>" + x));
return Observable.zip(stockNames, optionalObservable, (name, price) ->
new Tuple2<>(name, Double.parseDouble(price.orElse("0.0"))));
}
示例5: testStockPriceSchedulerWithErrorHandling
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void testStockPriceSchedulerWithErrorHandling() throws IOException, InterruptedException {
Observable<String> stockNames = Observable.just("M", "MSFT", "BTC", "T", "ORCL");
Observable<String> urls = stockNames.map(s -> "https://finance.google.com/finance/historical?output=csv&q=" + s);
Observable<Optional<String>> optionalObservable = urls
.subscribeOn(Schedulers.from(executorService))
.flatMap(s -> {
try {
return Observable.just(Optional.of(this.getInfoFromURL(s)));
} catch (Throwable t) {
return Observable.just(Optional.<String>empty());
}
})
.observeOn(Schedulers.computation())
.map(opt -> opt.map(doc -> doc.split("\n")[1].split(",")[4]));
// .doOnNext(x -> System.out.println(">>>" + x));
Observable.zip(stockNames, optionalObservable, (name, price) ->
new Tuple2<>(name, Double.parseDouble(price.orElse("0.0"))))
.subscribe(System.out::println, Throwable::printStackTrace);
Thread.sleep(10000);
}
示例6: getRemoteFlow
import io.reactivex.Observable; //导入方法依赖的package包/类
/**
* build remote data flow(origin,action,map...)
*
* @return remote flow
*/
private Observable<V> getRemoteFlow() {
if (remoteObservableOrigin == null)
return null;
Observable result = remoteObservableOrigin;
if (cacheAction != null) {
result = remoteObservableOrigin.doOnNext(cacheAction);
}
if (netDataMapFunc != null) {
result = result.map(netDataMapFunc);
}
return result;
}
示例7: loadRemote
import io.reactivex.Observable; //导入方法依赖的package包/类
<T> Observable<CacheResult<T>> loadRemote(final ApiCache apiCache, final String key, Observable<T> source) {
return source.map(new Function<T, CacheResult<T>>() {
@Override
public CacheResult<T> apply(T t) throws Exception {
ViseLog.i("loadRemote result=" + t);
apiCache.put(key, t).subscribeOn(Schedulers.io()).subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean status) throws Exception {
ViseLog.i("save status => " + status);
}
});
return new CacheResult<>(false, t);
}
});
}
示例8: apply
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public <T> Observable<CacheResult<T>> apply(@NonNull final Object key, Observable<T> observable, final LruDisk lruDisk, final boolean isInsert) {
return observable.map(new Function<T, CacheResult<T>>() {
@Override
public CacheResult<T> apply(@NonNull T t) throws Exception {
CacheResult<T> tCacheResult = new CacheResult<>(t, key, CacheResult.CacheType.NETWORK);
if (isInsert) {
lruDisk.insert(key, tCacheResult.getResult());
}
return tCacheResult;
}
});
}
示例9: execute
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public <T> Observable<CacheResult<T>> execute(RxCache rxCache, String cacheKey, long cacheTime, Observable<T> source, Type type) {
return source.map(new Function<T, CacheResult<T>>() {
@Override
public CacheResult<T> apply(@NonNull T t) throws Exception {
return new CacheResult<T>(false, t);
}
});
}
示例10: testStockPriceFinderFindTheLatestCloseBug
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void testStockPriceFinderFindTheLatestCloseBug() throws IOException {
Observable<String> stockNames = Observable.just("M", "MSFT", "BTC", "T", "ORCL");
Observable<String> urls = stockNames.map(s -> "https://finance.google.com/finance/historical?output=csv&q=" + s);
Observable<String> contentObservable = urls.flatMap(u -> Observable.fromFuture(createFuture(u)).onErrorResumeNext((Throwable e) -> Observable.empty()));
Observable<String> lineObservable = contentObservable.doOnNext(s -> System.out.println(">>>>" + s)).flatMap(doc ->
Observable.fromArray(doc.split("\n")).skip(1).take(1));
Observable<Tuple2<String, Double>> tupleObservable = stockNames.zipWith(lineObservable.map(s -> s.split(",")[4]).map(Double::parseDouble), Tuple2::new);
tupleObservable.subscribe(System.out::println);
}
示例11: testStockPriceScheduler
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void testStockPriceScheduler() throws IOException, InterruptedException {
Observable<String> stockNames = Observable.just("M", "MSFT", "T", "ORCL");
Observable<String> urls = stockNames.map(s -> "https://finance.google.com/finance/historical?output=csv&q=" + s);
urls.doOnNext(x -> System.out.println("doOnNext-1: " + Thread.currentThread().getName()))
.subscribeOn(Schedulers.from(executorService))
.map(this::getInfoFromURL)
.observeOn(Schedulers.computation())
.doOnNext(x -> System.out.println("doOnNext-2: " + Thread.currentThread().getName()))
.flatMap(doc -> Observable.fromArray(doc.split("\n")).skip(1).take(1)).subscribe(System.out::println);
Thread.sleep(10000);
}
示例12: put
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<StorageResult> put(Observable<Entry> entries) {
return entries.map(entry -> {
try {
FilesystemUtil.addEntry(directory, entry, gzipEnabled);
return new StorageResult(entry);
} catch (final IOException ex) {
return new StorageResult(entry, new IOException("cannot put entry", ex));
}
});
}
示例13: delete
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<StorageResult> delete(Observable<Entry> entries) {
return entries.map(entry -> {
try {
FilesystemUtil.removeEntry(directory, entry);
return new StorageResult(entry);
} catch (final IOException ex) {
return new StorageResult(entry, new IOException("cannot delete entry", ex));
}
});
}
示例14: apply
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override public ObservableSource<Optional<T>> apply(Observable<DataSnapshot> upstream) {
return upstream.map(new Function<DataSnapshot, Optional<T>>() {
@Override public Optional<T> apply(DataSnapshot dataSnapshot) throws Exception {
return Optional.of(dataSnapshot.getValue(typeIndicator));
}
});
}
示例15: apply
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override public ObservableSource<Optional<T>> apply(Observable<DataSnapshot> upstream) {
return upstream.map(new Function<DataSnapshot, Optional<T>>() {
@Override public Optional<T> apply(DataSnapshot dataSnapshot) throws Exception {
return Optional.of(dataSnapshot.getValue(clazz));
}
});
}