當前位置: 首頁>>代碼示例>>Java>>正文


Java BehaviorSubject.createDefault方法代碼示例

本文整理匯總了Java中io.reactivex.subjects.BehaviorSubject.createDefault方法的典型用法代碼示例。如果您正苦於以下問題:Java BehaviorSubject.createDefault方法的具體用法?Java BehaviorSubject.createDefault怎麽用?Java BehaviorSubject.createDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.subjects.BehaviorSubject的用法示例。


在下文中一共展示了BehaviorSubject.createDefault方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testClose_waitForCommands

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Test
public void testClose_waitForCommands() {
    BehaviorSubject<Boolean> idler = BehaviorSubject.createDefault(false);
    when(cmdProcessor.isIdle()).thenReturn(idler);

    RxCmdShell shell = new RxCmdShell(builder);
    shell.open().test().awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().values().get(0);
    shell.isAlive().test().awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().assertValue(true);

    shell.close().test().awaitDone(1, TimeUnit.SECONDS).assertTimeout();

    idler.onNext(true);

    shell.close().test().awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().assertValue(0);

    verify(cmdProcessor).isIdle();
    verify(rxShellSession).close();
}
 
開發者ID:d4rken,項目名稱:RxShell,代碼行數:19,代碼來源:RxCmdShellTest.java

示例2: autoDispose_withProvider_success

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Test public void autoDispose_withProvider_success() {
  RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
  MaybeSubject<Integer> source = MaybeSubject.create();
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
  source.as(AutoDispose.<Integer>autoDisposable(provider))
      .subscribe(o);
  o.takeSubscribe();

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  lifecycle.onNext(1);

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  source.onSuccess(3);
  o.takeSuccess();

  o.assertNoMoreEvents();
  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
}
 
開發者ID:uber,項目名稱:AutoDispose,代碼行數:25,代碼來源:AutoDisposeMaybeObserverTest.java

示例3: autoDispose_withLifecycleProvider_completion

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Test public void autoDispose_withLifecycleProvider_completion() {
  RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
  MaybeSubject<Integer> source = MaybeSubject.create();
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
  source.as(AutoDispose.<Integer>autoDisposable(provider))
      .subscribe(o);
  o.takeSubscribe();

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  lifecycle.onNext(1);

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  source.onComplete();
  o.assertOnComplete();

  o.assertNoMoreEvents();
  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
}
 
開發者ID:uber,項目名稱:AutoDispose,代碼行數:25,代碼來源:AutoDisposeMaybeObserverTest.java

示例4: autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) {
      // Noop
    }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  lifecycle.onNext(1);
  lifecycle.onNext(2);
  lifecycle.onNext(3);
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  MaybeSubject<Integer> source = MaybeSubject.create();
  TestObserver<Integer> o = source
          .as(AutoDispose.<Integer>autoDisposable(provider))
          .test();

  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
  o.assertNoValues();
  o.assertNoErrors();
}
 
開發者ID:uber,項目名稱:AutoDispose,代碼行數:22,代碼來源:AutoDisposeMaybeObserverTest.java

示例5: autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) {
      // Noop
    }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  lifecycle.onNext(1);
  lifecycle.onNext(2);
  lifecycle.onNext(3);
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  CompletableSubject source = CompletableSubject.create();
  TestObserver<Void> o = source
          .as(autoDisposable(provider))
          .test();

  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
  o.assertNoValues();
  o.assertNoErrors();
}
 
開發者ID:uber,項目名稱:AutoDispose,代碼行數:22,代碼來源:AutoDisposeCompletableObserverTest.java

示例6: autoDispose_withProvider_afterLifecycle_shouldFail

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Test public void autoDispose_withProvider_afterLifecycle_shouldFail() {
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  lifecycle.onNext(1);
  lifecycle.onNext(2);
  lifecycle.onNext(3);
  TestSubscriber<Integer> firstSubscriber = new TestSubscriber<>();
  TestSubscriber<Integer> secondSubscriber = new TestSubscriber<>();
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  //noinspection unchecked
  Subscriber<Integer>[] subscribers = new Subscriber[] {firstSubscriber, secondSubscriber};

  Flowable.just(1, 2)
      .parallel(DEFAULT_PARALLELISM)
      .as(AutoDispose.<Integer>autoDisposable(provider))
      .subscribe(subscribers);

  List<Throwable> errors1 = firstSubscriber.errors();
  assertThat(errors1).hasSize(1);
  assertThat(errors1.get(0)).isInstanceOf(LifecycleEndedException.class);

  List<Throwable> errors2 = secondSubscriber.errors();
  assertThat(errors2).hasSize(1);
  assertThat(errors2.get(0)).isInstanceOf(LifecycleEndedException.class);
}
 
開發者ID:uber,項目名稱:AutoDispose,代碼行數:25,代碼來源:AutoDisposeParallelFlowableTest.java

示例7: autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) {
      // Noop
    }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  lifecycle.onNext(1);
  lifecycle.onNext(2);
  lifecycle.onNext(3);
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  PublishSubject<Integer> source = PublishSubject.create();
  TestObserver<Integer> o = source
          .as(AutoDispose.<Integer>autoDisposable(provider))
          .test();

  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
  o.assertNoValues();
  o.assertNoErrors();
}
 
開發者ID:uber,項目名稱:AutoDispose,代碼行數:22,代碼來源:AutoDisposeObserverTest.java

示例8: autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) {
      // Noop
    }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  lifecycle.onNext(1);
  lifecycle.onNext(2);
  lifecycle.onNext(3);
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  PublishProcessor<Integer> source = PublishProcessor.create();
  TestSubscriber<Integer> o = source
          .as(AutoDispose.<Integer>autoDisposable(provider))
          .test();

  assertThat(source.hasSubscribers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
  o.assertNoValues();
  o.assertNoErrors();
}
 
開發者ID:uber,項目名稱:AutoDispose,代碼行數:22,代碼來源:AutoDisposeSubscriberTest.java

示例9: MviBasePresenter

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
/**
 * Creaes a new Presenter with the initial view state
 *
 * @param initialViewState initial view state (must be not null)
 */
public MviBasePresenter(@NonNull VS initialViewState) {
  if (initialViewState == null) {
    throw new NullPointerException("Initial ViewState == null");
  }

  viewStateBehaviorSubject = BehaviorSubject.createDefault(initialViewState);
  reset();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:MviBasePresenter.java

示例10: InputProcess

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
public InputProcess(@Input("file") ImageInput file) {
    if (file == null) {
        this.image = BehaviorSubject.createDefault(ImageFactory.buildEmptyImage());
        return;
    } 
    try {
        this.image = file.getImageObservable();
    } catch(Throwable e) {
        e.printStackTrace();
    }
}
 
開發者ID:VISNode,項目名稱:VISNode,代碼行數:12,代碼來源:InputProcess.java

示例11: getImageObservable

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<Image> getImageObservable() {
    try {
        return BehaviorSubject.createDefault(new InputReader().read(getFile()));
    } catch (Exception e) {
        ExceptionHandler.get().handle(e);
        return null;
    }
}
 
開發者ID:VISNode,項目名稱:VISNode,代碼行數:10,代碼來源:MultiFileInput.java

示例12: valueObservable

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<String> valueObservable() {
    Subject<String> subject = BehaviorSubject.createDefault(value());
    swingComponent().addPropertyChangeListener("value", (evt) -> {
        subject.onNext((String)evt.getNewValue());
    });
    return subject;
}
 
開發者ID:VISNode,項目名稱:VISNode,代碼行數:9,代碼來源:DefaultTextInputSupport.java

示例13: textObservable

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<String> textObservable() {
    Subject<String> subject = BehaviorSubject.createDefault(text());
    swingComponent().addPropertyChangeListener("text", (evt) -> {
        subject.onNext((String)evt.getNewValue());
    });
    return subject;
}
 
開發者ID:VISNode,項目名稱:VISNode,代碼行數:9,代碼來源:DefaultLabelSupport.java

示例14: iconObservable

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<Icon> iconObservable() {
    Subject<Icon> subject = BehaviorSubject.createDefault(icon());
    swingComponent().addPropertyChangeListener("icon", (evt) -> {
        subject.onNext((Icon)evt.getNewValue());
    });
    return subject;
}
 
開發者ID:VISNode,項目名稱:VISNode,代碼行數:9,代碼來源:DefaultLabelSupport.java

示例15: preferredSizeObservable

import io.reactivex.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<Dimension> preferredSizeObservable() {
    Subject<Dimension> subject = BehaviorSubject.createDefault(preferredSize());
    swingComponent().addPropertyChangeListener("preferredSize", (evt) -> {
        subject.onNext((Dimension)evt.getNewValue());
    });
    return subject;
}
 
開發者ID:VISNode,項目名稱:VISNode,代碼行數:9,代碼來源:DefaultComponentSupport.java


注:本文中的io.reactivex.subjects.BehaviorSubject.createDefault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。