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


Java Observable.map方法代码示例

本文整理汇总了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;
                }
            });
        }
    };
}
 
开发者ID:simplezhli,项目名称:RxPay,代码行数:17,代码来源:RxPayUtils.java

示例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));
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:19,代码来源:Ch2_3.java

示例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;
                }
            });
        }
    };
}
 
开发者ID:simplezhli,项目名称:RxPay,代码行数:17,代码来源:RxPayUtils.java

示例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"))));
}
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:20,代码来源:ObservableTestingTest.java

示例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);
    }
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:24,代码来源:StockFinderTest.java

示例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;
}
 
开发者ID:killnono,项目名称:Dalaran,代码行数:18,代码来源:RequestStrategy.java

示例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);
        }
    });
}
 
开发者ID:xiaoyaoyou1212,项目名称:XSnow,代码行数:16,代码来源:CacheStrategy.java

示例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;
        }
    });
}
 
开发者ID:7449,项目名称:RxNetWork,代码行数:14,代码来源:ApplyImpl.java

示例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);
        }
    });
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:10,代码来源:NoStrategy.java

示例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);
}
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:11,代码来源:StockFinderTest.java

示例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);
}
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:13,代码来源:StockFinderTest.java

示例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));
    }
  });
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:12,代码来源:StorageImpl.java

示例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));
    }
  });
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:12,代码来源:StorageImpl.java

示例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));
    }
  });
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:8,代码来源:ObsTransformerOfGenericTypeIndicator.java

示例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));
    }
  });
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:8,代码来源:ObsTransformerOfClazz.java


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