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


Java Flowable.just方法代码示例

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


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

示例1: insertOrUpdate

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * Insert or update all
 * @param items
 * @return List of item copied from realm
 */
@Override
public Flowable<Optional<List<T>>> insertOrUpdate(List<T> items) {
    final Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    items = realm.copyToRealmOrUpdate(items);
    realm.commitTransaction();
    List<T> copies = realm.copyFromRealm(items);
    realm.close();

    return Flowable.just(Optional.wrap(copies));
}
 
开发者ID:playmoweb,项目名称:store2realm,代码行数:17,代码来源:RealmDao.java

示例2: shouldPresent_AvailableData_IntoView

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test public void shouldPresent_AvailableData_IntoView() throws Exception {

        Flowable<FactAboutNumber> data = Flowable.just(
                FactAboutNumber.of("1", "1 is the first"),
                FactAboutNumber.of("2", "2 is the second")
        );

        when(usecase.fetchTrivia()).thenReturn(data);

        presenter.fetchRandomFacts();

        BehavioursRobot.with(view)
                .showLoadingFirstHideLoadingAfter()
                .disableRefreshFirstAndEnableAfter()
                .shouldNotShowEmptyState()
                .shouldNotShowErrorState()
                .shouldNotReportNetworkingError();

        DataFlowWatcher.with(onNext, onError, onCompleted).shouldReceiveItems(2);

        verify(strategist, oneTimeOnly()).applyStrategy(any());
    }
 
开发者ID:ubiratansoares,项目名称:reactive-architectures-playground,代码行数:23,代码来源:FactsPresenterTests.java

示例3: delete

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Override
public Flowable<Integer> delete(final List<TestModel> items) {
    List<TestModel> output = new ArrayList<>();

    int found = 0;
    for (TestModel tm : models) {
        boolean foundInDeleteList = false;
        for(TestModel model : items) {
            if(tm.getId() == model.getId()) {
                foundInDeleteList = true;
                found++;
                break;
            }
        }

        if(!foundInDeleteList){
            output.add(tm);
        }
    }

    models.clear();
    models.addAll(output);
    return Flowable.just(found);
}
 
开发者ID:playmoweb,项目名称:store2store,代码行数:25,代码来源:MemoryDao.java

示例4: cartesian

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 *
 * @author [email protected]
 * @param sources
 * @return
 */
public static Flowable<int[]> cartesian(List<Flowable<Integer>> sources) {
  if (sources.size() == 0) {
    return Flowable.empty();
  }
  Flowable<int[]> main = Flowable.just(new int[0]);
  for (int i = 0; i < sources.size(); i++) {
    int j = i;
    Flowable<Integer> o = sources.get(i).cache();
    main = main.<int[]> flatMap(v -> o.map(w -> {
      int[] arr = Arrays.copyOf(v, j + 1);
      arr[j] = w;
      return arr;
    }));
  }

  return main;
}
 
开发者ID:XDean,项目名称:Java-EX,代码行数:24,代码来源:CartesianProduct.java

示例5: delete

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * Remove only these items
 * @param items
 * @return List of item copied from realm
 */
@Override
public Flowable<Integer> delete(List<T> items) {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();

    for(T obj : items) {
        if(obj.isManaged()) {
            obj.deleteFromRealm(); // potentially slow
        } else {
            T managedObject = realm.copyToRealmOrUpdate(obj);
            managedObject.deleteFromRealm();
        }
    }

    realm.commitTransaction();
    realm.close();

    return Flowable.just(items.size());
}
 
开发者ID:playmoweb,项目名称:store2realm,代码行数:25,代码来源:RealmDao.java

示例6: and

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * Creates a Flowable which is true iff all bools provided to the call are also true.
 * This method short circuits and only evaluates until the first false value.
 * @param bools
 * @return A Flowable which emits true iff all bools are true
 */
@SafeVarargs
public static Flowable<Boolean> and(Flowable<Boolean>... bools)
{
    Flowable<Boolean> previousBool = null;

    for (Flowable<Boolean> bool : bools) {
        if (previousBool == null) {
            previousBool = bool;
            continue;
        }

        previousBool = previousBool.switchMap(new AndSwitchMap(bool));
    }

    if (previousBool == null) {
        return Flowable.just(false);
    }

    return previousBool.distinctUntilChanged();
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:27,代码来源:BooleanFlowables.java

示例7: testCreateStream

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void testCreateStream() {
    Publisher<Iterable<Integer>> sourceStream = Flowable.just(VALUES_WITHOUT_NULL);
    doReturn(sourceStream).when(discoveryService).discover(sourceStreamId);
    StreamId<Integer> flattenedStreamId = FlattenedStreamId.flatten(sourceStreamId);
    ErrorStreamPair<Integer> errorStreamPair = flattenedStreamFactory.create(flattenedStreamId, discoveryService);

    errorStreamPair.data().subscribe(testValuesSubscriber);
    errorStreamPair.error().subscribe(testErrorsSubscriber);
    testValuesSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);

    testValuesSubscriber.assertComplete();
    testValuesSubscriber.assertValueCount(VALUES_WITHOUT_NULL.size());
    testValuesSubscriber.assertValues(VALUES_WITHOUT_NULL.toArray(new Integer[VALUES_WITHOUT_NULL.size()]));
    testErrorsSubscriber.assertNoValues();
    testErrorsSubscriber.assertNotTerminated();
}
 
开发者ID:streamingpool,项目名称:streamingpool-core,代码行数:18,代码来源:FlattenedStreamFactoryTest.java

示例8: test_just_Flowable

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void test_just_Flowable() {

	Flowable<String> observable = Flowable.just("mango", "papaya", "guava");
	TestSubscriber<String> testSubscriber = new TestSubscriber<>();

	observable.subscribe(testSubscriber);

	List<String> items = testSubscriber.values();
	testSubscriber.assertComplete();
	testSubscriber.assertSubscribed();
	testSubscriber.assertNoErrors();
	testSubscriber.assertValueCount(3);
	testSubscriber.assertValues("mango", "papaya", "guava");

}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:17,代码来源:Modern_Testing.java

示例9: or

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * Creates a Flowable which is true iff at least one bool provided to the call is true.
 * This method short circuits and only evaluates until the first true value.
 * @param bools
 * @return A Flowable which emits true iff at least one bools is true
 */
@SafeVarargs
public static Flowable<Boolean> or(Flowable<Boolean>... bools)
{
    Flowable<Boolean> previousBool = null;

    for (Flowable<Boolean> bool : bools) {
        if (previousBool == null) {
            previousBool = bool;
            continue;
        }

        previousBool = previousBool.switchMap(new OrSwitchMap(bool));
    }

    if (previousBool == null) {
        return Flowable.just(false);
    }

    return previousBool.distinctUntilChanged();
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:27,代码来源:BooleanFlowables.java

示例10: apply

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Override
public Publisher<Boolean> apply(Boolean aBoolean) throws Exception {
    if (!aBoolean) {
        return _bool2;
    }
    return Flowable.just(aBoolean);
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:8,代码来源:BooleanFlowables.java

示例11: getTask

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * Gets tasks from local data source (sqlite) unless the table is new or empty. In that case it
 * uses the network data source. This is done to simplify the sample.
 */
@Override
public Flowable<Optional<Task>> getTask(@NonNull final String taskId) {
    checkNotNull(taskId);

    final Task cachedTask = getTaskWithId(taskId);

    // Respond immediately with cache if available
    if (cachedTask != null) {
        return Flowable.just(Optional.of(cachedTask));
    }

    // Load from server/persisted if needed.

    // Do in memory cache update to keep the app UI up to date
    if (mCachedTasks == null) {
        mCachedTasks = new LinkedHashMap<>();
    }

    // Is the task in the local data source? If not, query the network.
    Flowable<Optional<Task>> localTask = getTaskWithIdFromLocalRepository(taskId);
    Flowable<Optional<Task>> remoteTask = mTasksRemoteDataSource
            .getTask(taskId)
            .doOnNext(taskOptional -> {
                if (taskOptional.isPresent()) {
                    Task task = taskOptional.get();
                    mTasksLocalDataSource.saveTask(task);
                    mCachedTasks.put(task.getId(), task);
                }
            });

    return Flowable.concat(localTask, remoteTask)
            .firstElement()
            .toFlowable();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:TasksRepository.java

示例12: testStockPriceSchedulerWithFlowable

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void testStockPriceSchedulerWithFlowable() throws IOException, InterruptedException {
    Flowable<String> stockNames = Flowable.just("M", "MSFT", "T", "ORCL");
    Flowable<String> urls = stockNames.map(s -> "https://finance.google.com/finance/historical?output=csv&q=" + s);
    urls.parallel(4).runOn(Schedulers.from(executorService)).map(this::getInfoFromURL).flatMap(doc ->
            Flowable.fromArray(doc.split("\n")).skip(1).take(1)).sequential().subscribe(System.out::println);
    Thread.sleep(10000);
}
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:9,代码来源:StockFinderTest.java

示例13: manyToMany

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void manyToMany() {
    RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
    Flowable<HelloRequest> req = Flowable.just(HelloRequest.getDefaultInstance());
    Flowable<HelloResponse> resp = stub.sayHelloBothStream(req);
    TestSubscriber<HelloResponse> test = resp.test();

    test.awaitTerminalEvent(3, TimeUnit.SECONDS);
    test.assertError(t -> t instanceof StatusRuntimeException);
    test.assertError(t -> ((StatusRuntimeException)t).getStatus().getCode() == Status.Code.CANCELLED);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:12,代码来源:UnexpectedServerErrorIntegrationTest.java

示例14: manyToOne

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void manyToOne() {
    RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
    Flowable<String> rxRequest = Flowable.just("A", "B", "C");
    Single<String> rxResponse = stub.sayHelloReqStream(rxRequest.map(this::toRequest)).map(this::fromResponse);

    TestObserver<String> test = rxResponse.test();
    test.awaitTerminalEvent(1, TimeUnit.SECONDS);

    test.assertNoErrors();
    test.assertValue("Hello A and B and C");
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:13,代码来源:ReactiveClientStandardServerInteropTest.java

示例15: manyToOne

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void manyToOne() throws Exception {
    RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
    Flowable<HelloRequest> req = Flowable.just(
            HelloRequest.newBuilder().setName("a").build(),
            HelloRequest.newBuilder().setName("b").build(),
            HelloRequest.newBuilder().setName("c").build());

    Single<HelloResponse> resp = stub.sayHelloReqStream(req);

    TestObserver<String> testObserver = resp.map(HelloResponse::getMessage).test();
    testObserver.awaitTerminalEvent(3, TimeUnit.SECONDS);
    testObserver.assertValue("Hello a and b and c");
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:15,代码来源:EndToEndIntegrationTest.java


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