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