io.reactivex.Flowable.any()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(192)

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

Flowable.any介绍

[英]Returns a Single that emits true if any item emitted by the source Publisher satisfies a specified condition, otherwise false. Note: this always emits false if the source Publisher is empty.

In Rx.Net this is the any operator but we renamed it in RxJava to better match Java naming idioms. Backpressure: The operator honors backpressure from downstream and consumes the source Publisher in an unbounded manner (i.e., no backpressure applied to it). Scheduler: any does not operate by default on a particular Scheduler.
[中]如果源发布服务器发出的任何项满足指定条件,则返回一个值,该值为true,否则为false*注意:*如果源发布服务器为空,则此消息始终发出false。
在Rx。Net这是any操作符,但我们在RxJava中重命名了它,以便更好地匹配Java命名习惯用法。背压:操作员接受来自下游的背压,并以无限制的方式使用源发布服务器(即,不向其施加背压)。调度程序:默认情况下,任何调度程序都不会在特定的调度程序上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

@Test(expected = NullPointerException.class)
public void anyPredicateNull() {
  just1.any(null);
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Single<Boolean> apply(Flowable<Object> f) throws Exception {
    return f.any(Functions.alwaysTrue());
  }
});

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Publisher<Boolean> apply(Flowable<Object> f) throws Exception {
    return f.any(Functions.alwaysTrue()).toFlowable();
  }
});

代码示例来源:origin: ReactiveX/RxJava

@Override
public Publisher<Boolean> createPublisher(final long elements) {
  return
      Flowable.range(1, 1000).any(new Predicate<Integer>() {
        @Override
        public boolean test(Integer e) throws Exception {
          return e == 500;
        }
      }).toFlowable()
    ;
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testAnyWithOneItem() {
  Flowable<Integer> w = Flowable.just(1);
  Single<Boolean> single = w.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) {
      return true;
    }
  });
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, never()).onSuccess(false);
  verify(observer, times(1)).onSuccess(true);
  verify(observer, never()).onError(any(Throwable.class));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testAnyWithPredicate2() {
  Flowable<Integer> w = Flowable.just(1, 2, 3);
  Single<Boolean> single = w.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer t1) {
      return t1 < 1;
    }
  });
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, times(1)).onSuccess(false);
  verify(observer, never()).onSuccess(true);
  verify(observer, never()).onError(any(Throwable.class));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testExists1() {
  Flowable<Integer> w = Flowable.just(1, 2, 3);
  Single<Boolean> single = w.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer t1) {
      return t1 < 2;
    }
  });
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, never()).onSuccess(false);
  verify(observer, times(1)).onSuccess(true);
  verify(observer, never()).onError(any(Throwable.class));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testAnyWithPredicate1() {
  Flowable<Integer> w = Flowable.just(1, 2, 3);
  Single<Boolean> single = w.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer t1) {
      return t1 < 2;
    }
  });
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, never()).onSuccess(false);
  verify(observer, times(1)).onSuccess(true);
  verify(observer, never()).onError(any(Throwable.class));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testAnyWithTwoItems() {
  Flowable<Integer> w = Flowable.just(1, 2);
  Single<Boolean> single = w.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) {
      return true;
    }
  });
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, never()).onSuccess(false);
  verify(observer, times(1)).onSuccess(true);
  verify(observer, never()).onError(any(Throwable.class));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testAnyWithEmpty() {
  Flowable<Integer> w = Flowable.empty();
  Single<Boolean> single = w.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) {
      return true;
    }
  });
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, times(1)).onSuccess(false);
  verify(observer, never()).onSuccess(true);
  verify(observer, never()).onError(any(Throwable.class));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testExists1Flowable() {
  Flowable<Integer> w = Flowable.just(1, 2, 3);
  Flowable<Boolean> flowable = w.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer t1) {
      return t1 < 2;
    }
  }).toFlowable();
  Subscriber<Boolean> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, never()).onNext(false);
  verify(subscriber, times(1)).onNext(true);
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testAnyWithEmptyFlowable() {
  Flowable<Integer> w = Flowable.empty();
  Flowable<Boolean> flowable = w.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) {
      return true;
    }
  }).toFlowable();
  Subscriber<Boolean> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, times(1)).onNext(false);
  verify(subscriber, never()).onNext(true);
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void dispose() {
  TestHelper.checkDisposed(Flowable.just(1).any(Functions.alwaysTrue()).toFlowable());
  TestHelper.checkDisposed(Flowable.just(1).any(Functions.alwaysTrue()));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testWithFollowingFirst() {
  Flowable<Integer> f = Flowable.fromArray(1, 3, 5, 6);
  Single<Boolean> anyEven = f.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer i) {
      return i % 2 == 0;
    }
  });
  assertTrue(anyEven.blockingGet());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testWithFollowingFirstFlowable() {
  Flowable<Integer> f = Flowable.fromArray(1, 3, 5, 6);
  Flowable<Boolean> anyEven = f.any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer i) {
      return i % 2 == 0;
    }
  }).toFlowable();
  assertTrue(anyEven.blockingFirst());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testBackpressureIfOneRequestedOneShouldBeDelivered() {
  TestObserver<Boolean> to = new TestObserver<Boolean>();
  Flowable.just(1).any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) {
      return true;
    }
  }).subscribe(to);
  to.assertTerminated();
  to.assertNoErrors();
  to.assertComplete();
  to.assertValue(true);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
@Ignore("Single doesn't do backpressure")
public void testBackpressureIfNoneRequestedNoneShouldBeDelivered() {
  TestObserver<Boolean> to = new TestObserver<Boolean>();
  Flowable.just(1).any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer t) {
      return true;
    }
  })
  .subscribe(to);
  to.assertNoValues();
  to.assertNoErrors();
  to.assertNotComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
  public void testPredicateThrowsExceptionAndValueInCauseMessageFlowable() {
    TestSubscriber<Boolean> ts = new TestSubscriber<Boolean>();
    final IllegalArgumentException ex = new IllegalArgumentException();

    Flowable.just("Boo!").any(new Predicate<String>() {
      @Override
      public boolean test(String v) {
        throw ex;
      }
    }).toFlowable().subscribe(ts);

    ts.assertTerminated();
    ts.assertNoValues();
    ts.assertNotComplete();
    ts.assertError(ex);
    // FIXME value as last cause?
//        assertTrue(ex.getCause().getMessage().contains("Boo!"));
  }

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testBackpressureIfNoneRequestedNoneShouldBeDeliveredFlowable() {
  TestSubscriber<Boolean> ts = new TestSubscriber<Boolean>(0L);
  Flowable.just(1).any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer t) {
      return true;
    }
  }).toFlowable()
  .subscribe(ts);
  ts.assertNoValues();
  ts.assertNoErrors();
  ts.assertNotComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testBackpressureIfOneRequestedOneShouldBeDeliveredFlowable() {
  TestSubscriber<Boolean> ts = new TestSubscriber<Boolean>(1L);
  Flowable.just(1).any(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) {
      return true;
    }
  }).toFlowable().subscribe(ts);
  ts.assertTerminated();
  ts.assertNoErrors();
  ts.assertComplete();
  ts.assertValue(true);
}

相关文章

Flowable类方法