io.reactivex.common.Notification.isOnNext()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中io.reactivex.common.Notification.isOnNext()方法的一些代码示例,展示了Notification.isOnNext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Notification.isOnNext()方法的具体详情如下:
包路径:io.reactivex.common.Notification
类名称:Notification
方法名:isOnNext

Notification.isOnNext介绍

[英]Returns true if this notification is an onNext signal and #getValue() returns the contained value.
[中]如果此通知是onNext信号,则返回true,#getValue()返回包含的值。

代码示例

代码示例来源:origin: com.github.akarnokd.rxjava3/rxjava3-observable

@Override
public void onNext(Notification<T> args) {
  if (waiting.getAndSet(0) == 1 || !args.isOnNext()) {
    Notification<T> toOffer = args;
    while (!buf.offer(toOffer)) {
      Notification<T> concurrentItem = buf.poll();
      // in case if we won race condition with onComplete/onError method
      if (concurrentItem != null && !concurrentItem.isOnNext()) {
        toOffer = concurrentItem;
      }
    }
  }
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Override
public void onNext(Notification<T> args) {
  if (waiting.getAndSet(0) == 1 || !args.isOnNext()) {
    Notification<T> toOffer = args;
    while (!buf.offer(toOffer)) {
      Notification<T> concurrentItem = buf.poll();
      // in case if we won race condition with onComplete/onError method
      if (concurrentItem != null && !concurrentItem.isOnNext()) {
        toOffer = concurrentItem;
      }
    }
  }
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Override
public void onNext(Notification<T> args) {
  if (waiting.getAndSet(0) == 1 || !args.isOnNext()) {
    Notification<T> toOffer = args;
    while (!buf.offer(toOffer)) {
      Notification<T> concurrentItem = buf.poll();
      // in case if we won race condition with onComplete/onError method
      if (concurrentItem != null && !concurrentItem.isOnNext()) {
        toOffer = concurrentItem;
      }
    }
  }
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Override
public T next() {
  if (hasNext()) {
    if (iteratorNotification.isOnNext()) {
      T v = iteratorNotification.getValue();
      iteratorNotification = null;
      return v;
    }
  }
  throw new NoSuchElementException();
}

代码示例来源:origin: akarnokd/RxJava3-preview

@SuppressWarnings("rawtypes")
static String kind(Notification notification) {
  if (notification.isOnError()) {
    return "OnError";
  }
  if (notification.isOnNext()) {
    return "OnNext";
  }
  return "OnComplete";
}

代码示例来源:origin: akarnokd/RxJava3-preview

@SuppressWarnings("rawtypes")
static String kind(Notification notification) {
  if (notification.isOnError()) {
    return "OnError";
  }
  if (notification.isOnNext()) {
    return "OnNext";
  }
  return "OnComplete";
}

代码示例来源:origin: akarnokd/RxJava3-preview

@SuppressWarnings("rawtypes")
static String value(Notification notification) {
  if (notification.isOnNext()) {
    return String.valueOf(notification.getValue());
  }
  return "null";
}

代码示例来源:origin: akarnokd/RxJava3-preview

@SuppressWarnings("rawtypes")
static String value(Notification notification) {
  if (notification.isOnNext()) {
    return String.valueOf(notification.getValue());
  }
  return "null";
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Override
public boolean hasNext() {
  if (iteratorNotification != null && iteratorNotification.isOnError()) {
    throw ExceptionHelper.wrapOrThrow(iteratorNotification.getError());
  }
  if (iteratorNotification == null || iteratorNotification.isOnNext()) {
    if (iteratorNotification == null) {
      try {
        BlockingHelper.verifyNonBlocking();
        notify.acquire();
      } catch (InterruptedException ex) {
        dispose();
        iteratorNotification = Notification.createOnError(ex);
        throw ExceptionHelper.wrapOrThrow(ex);
      }
      Notification<T> n = value.getAndSet(null);
      iteratorNotification = n;
      if (n.isOnError()) {
        throw ExceptionHelper.wrapOrThrow(n.getError());
      }
    }
  }
  return iteratorNotification.isOnNext();
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Override
public boolean hasNext() {
  if (iteratorNotification != null && iteratorNotification.isOnError()) {
    throw ExceptionHelper.wrapOrThrow(iteratorNotification.getError());
  }
  if (iteratorNotification == null) {
    try {
      BlockingHelper.verifyNonBlocking();
      notify.acquire();
    } catch (InterruptedException ex) {
      dispose();
      iteratorNotification = Notification.createOnError(ex);
      throw ExceptionHelper.wrapOrThrow(ex);
    }
    Notification<T> n = value.getAndSet(null);
    iteratorNotification = n;
    if (n.isOnError()) {
      throw ExceptionHelper.wrapOrThrow(n.getError());
    }
  }
  return iteratorNotification.isOnNext();
}

代码示例来源:origin: com.github.akarnokd.rxjava3/rxjava3-observable

@Override
public boolean hasNext() {
  if (iteratorNotification != null && iteratorNotification.isOnError()) {
    throw ExceptionHelper.wrapOrThrow(iteratorNotification.getError());
  }
  if (iteratorNotification == null) {
    try {
      BlockingHelper.verifyNonBlocking();
      notify.acquire();
    } catch (InterruptedException ex) {
      dispose();
      iteratorNotification = Notification.createOnError(ex);
      throw ExceptionHelper.wrapOrThrow(ex);
    }
    Notification<T> n = value.getAndSet(null);
    iteratorNotification = n;
    if (n.isOnError()) {
      throw ExceptionHelper.wrapOrThrow(n.getError());
    }
  }
  return iteratorNotification.isOnNext();
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Test
public void testMaterialize2() {
  final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", "three");
  TestNotificationSubscriber subscriber = new TestNotificationSubscriber();
  Flowable<Notification<String>> m = Flowable.unsafeCreate(o1).materialize();
  m.subscribe(subscriber);
  try {
    o1.t.join();
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  assertFalse(subscriber.onError);
  assertTrue(subscriber.onComplete);
  assertEquals(4, subscriber.notifications.size());
  assertTrue(subscriber.notifications.get(0).isOnNext());
  assertEquals("one", subscriber.notifications.get(0).getValue());
  assertTrue(subscriber.notifications.get(1).isOnNext());
  assertEquals("two", subscriber.notifications.get(1).getValue());
  assertTrue(subscriber.notifications.get(2).isOnNext());
  assertEquals("three", subscriber.notifications.get(2).getValue());
  assertTrue(subscriber.notifications.get(3).isOnComplete());
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Test
public void testMaterialize2() {
  final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", "three");
  TestLocalObserver observer = new TestLocalObserver();
  Observable<Notification<String>> m = Observable.unsafeCreate(o1).materialize();
  m.subscribe(observer);
  try {
    o1.t.join();
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  assertFalse(observer.onError);
  assertTrue(observer.onComplete);
  assertEquals(4, observer.notifications.size());
  assertTrue(observer.notifications.get(0).isOnNext());
  assertEquals("one", observer.notifications.get(0).getValue());
  assertTrue(observer.notifications.get(1).isOnNext());
  assertEquals("two", observer.notifications.get(1).getValue());
  assertTrue(observer.notifications.get(2).isOnNext());
  assertEquals("three", observer.notifications.get(2).getValue());
  assertTrue(observer.notifications.get(3).isOnComplete());
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Test
public void testMaterialize1() {
  // null will cause onError to be triggered before "three" can be
  // returned
  final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", null,
      "three");
  TestLocalObserver observer = new TestLocalObserver();
  Observable<Notification<String>> m = Observable.unsafeCreate(o1).materialize();
  m.subscribe(observer);
  try {
    o1.t.join();
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  assertFalse(observer.onError);
  assertTrue(observer.onComplete);
  assertEquals(3, observer.notifications.size());
  assertTrue(observer.notifications.get(0).isOnNext());
  assertEquals("one", observer.notifications.get(0).getValue());
  assertTrue(observer.notifications.get(1).isOnNext());
  assertEquals("two", observer.notifications.get(1).getValue());
  assertTrue(observer.notifications.get(2).isOnError());
  assertEquals(NullPointerException.class, observer.notifications.get(2).getError().getClass());
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Test
public void testMaterialize1() {
  // null will cause onError to be triggered before "three" can be
  // returned
  final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", null,
      "three");
  TestNotificationSubscriber observer = new TestNotificationSubscriber();
  Flowable<Notification<String>> m = Flowable.unsafeCreate(o1).materialize();
  m.subscribe(observer);
  try {
    o1.t.join();
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  assertFalse(observer.onError);
  assertTrue(observer.onComplete);
  assertEquals(3, observer.notifications.size());
  assertTrue(observer.notifications.get(0).isOnNext());
  assertEquals("one", observer.notifications.get(0).getValue());
  assertTrue(observer.notifications.get(1).isOnNext());
  assertEquals("two", observer.notifications.get(1).getValue());
  assertTrue(observer.notifications.get(2).isOnError());
  assertEquals(NullPointerException.class, observer.notifications.get(2).getError().getClass());
}

代码示例来源:origin: akarnokd/RxJava3-preview

if (nextNotification.isOnNext()) {
  isNextConsumed = false;
  next = nextNotification.getValue();

代码示例来源:origin: akarnokd/RxJava3-preview

private boolean moveToNext() {
  if (!started) {
    started = true;
    // if not started, start now
    observer.setWaiting();
    new ObservableMaterialize<T>(items).subscribe(observer);
  }
  Notification<T> nextNotification;
  try {
    nextNotification = observer.takeNext();
  } catch (InterruptedException e) {
    observer.dispose();
    error = e;
    throw ExceptionHelper.wrapOrThrow(e);
  }
  if (nextNotification.isOnNext()) {
    isNextConsumed = false;
    next = nextNotification.getValue();
    return true;
  }
  // If an observable is completed or fails,
  // hasNext() always return false.
  hasNext = false;
  if (nextNotification.isOnComplete()) {
    return false;
  }
  error = nextNotification.getError();
  throw ExceptionHelper.wrapOrThrow(error);
}

代码示例来源:origin: com.github.akarnokd.rxjava3/rxjava3-observable

private boolean moveToNext() {
  if (!started) {
    started = true;
    // if not started, start now
    observer.setWaiting();
    new ObservableMaterialize<T>(items).subscribe(observer);
  }
  Notification<T> nextNotification;
  try {
    nextNotification = observer.takeNext();
  } catch (InterruptedException e) {
    observer.dispose();
    error = e;
    throw ExceptionHelper.wrapOrThrow(e);
  }
  if (nextNotification.isOnNext()) {
    isNextConsumed = false;
    next = nextNotification.getValue();
    return true;
  }
  // If an observable is completed or fails,
  // hasNext() always return false.
  hasNext = false;
  if (nextNotification.isOnComplete()) {
    return false;
  }
  error = nextNotification.getError();
  throw ExceptionHelper.wrapOrThrow(error);
}

代码示例来源:origin: akarnokd/RxJava3-preview

@Test
public void testBackpressureWithEmissionThenError() {
  TestSubscriber<Notification<Integer>> ts = new TestSubscriber<Notification<Integer>>(0L);
  IllegalArgumentException ex = new IllegalArgumentException();
  Flowable.fromIterable(Arrays.asList(1)).concatWith(Flowable.<Integer> error(ex)).materialize()
      .subscribe(ts);
  ts.assertNoValues();
  ts.request(1);
  ts.assertValueCount(1);
  assertTrue(ts.values().get(0).isOnNext());
  ts.request(1);
  ts.assertValueCount(2);
  assertTrue(ts.values().get(1).isOnError());
  assertEquals(ex, ts.values().get(1).getError());
  ts.assertComplete();
}

相关文章