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


Java Observable.fromIterable方法代码示例

本文整理汇总了Java中io.reactivex.Observable.fromIterable方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.fromIterable方法的具体用法?Java Observable.fromIterable怎么用?Java Observable.fromIterable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Observable的用法示例。


在下文中一共展示了Observable.fromIterable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReactive

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
    public void testReactive() {
        Observable.just("Hello", "World")
                .subscribe(System.out::println);
        List<String> words = Arrays.asList(
                "the",
                "quick",
                "brown",
                "fox",
                "jumps",
                "over",
                "the",
                "lazy",
                "dog"
        );

        Observable<String> wordsObs = Observable.fromIterable(words);
        wordsObs.subscribe(System.out::println);

        Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
//        range.subscribe(System.out::println);

        wordsObs.zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
                .subscribe(System.out::println);

        wordsObs.flatMap(word -> Observable.fromArray(word.split("")))
                .sorted()
                .distinct()
                .zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
                .subscribe(System.out::println);
    }
 
开发者ID:vgrazi,项目名称:reactive-demo,代码行数:32,代码来源:reactive.java

示例2: fromIterableShouldCreateAnObservableThatEmitsEachElementFromAnIterable

import io.reactivex.Observable; //导入方法依赖的package包/类
/**
 * Observable.fromIterable() is another way to create an Observable. It's
 * different than .just() - it is specifically designed to work with
 * Collections. When just is given a collection, it converts it into an
 * Observable that emits each item from the list. Let's understand how the
 * two are different more clearly.
 */
@Test
public void fromIterableShouldCreateAnObservableThatEmitsEachElementFromAnIterable() {
	
	List<String> sandwichIngredients = Arrays.asList("bread (one)", "bread (two)", "cheese", "mayo", "turkey",
			"lettuce", "pickles", "jalapenos", "Sriracha sauce");
	Observable<String> favoriteFoodsObservable = Observable.fromIterable(sandwichIngredients);
	TestObserver<String> testObserverIteratable = null; // TODO create new TestObserver and subscribe to favoriteFoodsObservable

	assertThat(testObserverIteratable.values()).hasSize(____);
	assertThat(testObserverIteratable.values()).containsAll(null);


	TestObserver<List<String>> testObserverForJust = new TestObserver<>();
	// TODO create obseverable for sandwichIngredients with just operator and subscribe testObserverForJust to it
	assertThat(testObserverForJust.values()).hasSize(1);
	assertThat(testObserverForJust.values()).contains(sandwichIngredients);
	/**
	 * ^^ As you can see here, fromIterable() & just() do very different things!
	 */
}
 
开发者ID:vogellacompany,项目名称:code-examples-android-expert,代码行数:28,代码来源:lessonA_CreatingObservableStreams.java

示例3: 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

示例4: main

import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
    List<String> items =
            Arrays.asList("Alpha", "Beta", "Gamma", "Delta", "Epsilon");
    Observable<String> source = Observable.fromIterable(items);
    source.map(String::length).filter(i -> i >= 5)
            .subscribe(s -> System.out.println("RECEIVED: " + s));
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:8,代码来源:Ch2_6.java

示例5: executeSelect

import io.reactivex.Observable; //导入方法依赖的package包/类
public <T> Observable<T> executeSelect(String query, Map<String, Object> arguments, Class<T> returnType) {
    // Add in limit and offset arguments by default. The limit is increased by 1 so that we can see if there is
    // more data for the client to paginate
    //
    // There should be a RequestContext in almost all cases. An exception would be a database call made prior
    // to the request being built like the one made to authenticated the API Token
    if (arguments.get(LIMIT) == null && RequestContextAccessor.get() != null) {
        arguments.put(LIMIT, RequestContextAccessor.get().getLimit() + 1);
    }

    if (arguments.get(OFFSET) == null && RequestContextAccessor.get() != null) {
        arguments.put(OFFSET, RequestContextAccessor.get().getOffset());
    }

    LOG.debug("Running query [{}] with values [{}]", query, arguments);

    List<T> results = namedParameterJdbcTemplate.query(query, arguments, new NestedFieldRowMapper(returnType, beanMapper));

    // If the results filled the limit + 1, there are more results to paginate through.
    if (results.size() == RequestContextAccessor.get().getLimit() + 1) {
        results.remove(results.size() - 1);

        if (RequestContextAccessor.get() != null) {
            RequestContextAccessor.get().setHasAnotherDbPage(Boolean.TRUE);
        }
    }

    return Observable.fromIterable(results);
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:30,代码来源:DbExecutor.java

示例6: createEntries

import io.reactivex.Observable; //导入方法依赖的package包/类
private static Observable<Entry> createEntries(int count) {
  List<Entry> entries = new ArrayList<>();
  for (int i = 0; i < count; i++) {
    entries.add(new Entry(22, i, i, "".getBytes()));
  }
  return Observable.fromIterable(entries);
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:8,代码来源:StorageImplTest.java

示例7: getDirectoryFiles

import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<PFile> getDirectoryFiles(PFile directory) {
    List<PFile> PFiles = getFilesFromCache(directory);
    if (PFiles == null) {
        return listFiles(directory);
    }
    return Observable.fromIterable(PFiles);
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:8,代码来源:StorageFileProvider.java

示例8: toObservableFromIterable

import io.reactivex.Observable; //导入方法依赖的package包/类
private Function<Collection<T>, Observable<T>> toObservableFromIterable() {
    return new Function<Collection<T>, Observable<T>>() {
        @Override
        public Observable<T> apply(Collection<T> source) {
            return Observable.fromIterable(source);
        }
    };
}
 
开发者ID:Ahmed-Adel-Ismail,项目名称:J-Chain,代码行数:9,代码来源:InOperator.java

示例9: main

import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {

        List<Beer> beers = loadCellar();  // populate the beer collection

        System.out.println("== Observable creation from an Iterable");

        Observable<Beer> observableBeer = Observable.fromIterable(beers);

        observableBeer.subscribe(
                beer -> System.out.println(beer),
                error -> System.err.println(error),
                () -> System.out.println("Streaming is over")
        );
    }
 
开发者ID:yfain,项目名称:rxjava2,代码行数:15,代码来源:ObservableErrorComplete.java

示例10: readMyDeviceLocalHistory

import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<IdentityProviderUsage> readMyDeviceLocalHistory(RoutingContext routingContext) {
    LOG.debug("Received create IdentityProvider request");

    String globalId = RequestReader.getCookieValue(routingContext, RequestReader.DEVICE_ID);
    Device device = deviceFacade.read(new DeviceQuery().setGlobalId(globalId)).blockingGet();

    return Observable.fromIterable(identityProviderUsageFacade.buildRecentHistory(device));
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:9,代码来源:IdentityProviderUsageRouting.java

示例11: main

import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {

        List<Beer> beers = loadCellar();  // populate the beer collection

        // === Java 8 Stream
        System.out.println("\n== Iterating over Java 8 Stream");

        beers.stream()
                .skip(1)
                .limit(3)
                .filter(b -> "USA".equals(b.country))
                .map(b -> b.name + ": $" + b.price)
                .forEach(beer -> System.out.println(beer));

        // === RxJava Observable

        Observable<Beer> observableBeer = null;

        System.out.println("\n== Subscribing to Observable ");

        observableBeer = Observable.fromIterable(beers);

        observableBeer
                .skip(1)
                .take(3)
                .filter(b -> "USA".equals(b.country))
                .map(b -> b.name + ": $" + b.price)
                .subscribe(
                        beer -> System.out.println(beer),
                        err ->  System.out.println(err),
                        () ->   System.out.println("Streaming is complete"),
                        disposable -> System.out.println( " !!! Someone just subscribed to the beer stream!!! ")
        );
    }
 
开发者ID:yfain,项目名称:rxjava2,代码行数:35,代码来源:StreamVsObservable.java

示例12: countStreamForTickFetch

import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<Long> countStreamForTickFetch(final long endTime) {
    final LongStream counter = LongStream
        .iterate(1, i -> i + 1)
        .map(count -> endTime - count * tickFetchMillis + 1);
    return Observable.fromIterable(counter::iterator);
}
 
开发者ID:juxeii,项目名称:dztools,代码行数:7,代码来源:HistoryFetchDate.java

示例13: filter

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<DeviceAccess> filter(DeviceAccessQuery query) {
    return Observable.fromIterable(deviceAccessList);
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:5,代码来源:DeviceAccessFacadeMockImpl.java

示例14: getDeptsRx

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<Department> getDeptsRx() {
	Observable<Department> depts= Observable.fromIterable(departmentDaoImpl.getDepartments());
	return depts;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:6,代码来源:DepartmentServiceImpl.java

示例15: getEmployeesRx

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<Employee> getEmployeesRx() {
	Observable<Employee> publishedEmployees= Observable.fromIterable(employeeDaoImpl.getEmployees());
	return publishedEmployees;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:6,代码来源:EmployeeRxJavaServiceImpl.java


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