本文整理了Java中io.reactivex.Observable.any()
方法的一些代码示例,展示了Observable.any()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.any()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:any
[英]Returns a Single that emits true if any item emitted by the source ObservableSource satisfies a specified condition, otherwise false. Note: this always emits false if the source ObservableSource is empty.
In Rx.Net this is the any Observer but we renamed it in RxJava to better match Java naming idioms. Scheduler: any does not operate by default on a particular Scheduler.
[中]如果源ObservableSource发出的任何项满足指定的条件,则返回一个单一值,否则返回false*注:*如果源ObservableSource为空,则该选项始终发出false。
在Rx。Net这是any Observer,但我们在RxJava中对其进行了重命名,以更好地匹配Java命名习惯用法。调度程序:默认情况下,任何调度程序都不会在特定的调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void anyPredicateNull() {
just1.any(null);
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public SingleSource<Boolean> apply(Observable<Object> o) throws Exception {
return o.any(Functions.alwaysTrue());
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testExists1() {
Observable<Integer> w = Observable.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 testAnyWithPredicate2() {
Observable<Integer> w = Observable.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 testAnyWithTwoItems() {
Observable<Integer> w = Observable.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 testAnyWithOneItem() {
Observable<Integer> w = Observable.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
@Override
public ObservableSource<Boolean> apply(Observable<Object> o) throws Exception {
return o.any(Functions.alwaysTrue()).toObservable();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testAnyWithPredicate1() {
Observable<Integer> w = Observable.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 testAnyWithPredicate1Observable() {
Observable<Integer> w = Observable.just(1, 2, 3);
Observable<Boolean> observable = w.any(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 < 2;
}
}).toObservable();
Observer<Boolean> observer = TestHelper.mockObserver();
observable.subscribe(observer);
verify(observer, never()).onNext(false);
verify(observer, times(1)).onNext(true);
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testAnyWithEmpty() {
Observable<Integer> w = Observable.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 testAnyWithOneItemObservable() {
Observable<Integer> w = Observable.just(1);
Observable<Boolean> observable = w.any(new Predicate<Integer>() {
@Override
public boolean test(Integer v) {
return true;
}
}).toObservable();
Observer<Boolean> observer = TestHelper.mockObserver();
observable.subscribe(observer);
verify(observer, never()).onNext(false);
verify(observer, times(1)).onNext(true);
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testAnyWithTwoItemsObservable() {
Observable<Integer> w = Observable.just(1, 2);
Observable<Boolean> observable = w.any(new Predicate<Integer>() {
@Override
public boolean test(Integer v) {
return true;
}
}).toObservable();
Observer<Boolean> observer = TestHelper.mockObserver();
observable.subscribe(observer);
verify(observer, never()).onNext(false);
verify(observer, times(1)).onNext(true);
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testExists1Observable() {
Observable<Integer> w = Observable.just(1, 2, 3);
Observable<Boolean> observable = w.any(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 < 2;
}
}).toObservable();
Observer<Boolean> observer = TestHelper.mockObserver();
observable.subscribe(observer);
verify(observer, never()).onNext(false);
verify(observer, times(1)).onNext(true);
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testAnyWithPredicate2Observable() {
Observable<Integer> w = Observable.just(1, 2, 3);
Observable<Boolean> observable = w.any(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 < 1;
}
}).toObservable();
Observer<Boolean> observer = TestHelper.mockObserver();
observable.subscribe(observer);
verify(observer, times(1)).onNext(false);
verify(observer, never()).onNext(true);
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Observable.just(1).any(Functions.alwaysTrue()).toObservable());
TestHelper.checkDisposed(Observable.just(1).any(Functions.alwaysTrue()));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testAnyWithEmptyAndPredicate() {
// If the source is empty, always output false.
Observable<Integer> w = Observable.empty();
Single<Boolean> single = w.any(new Predicate<Integer>() {
@Override
public boolean test(Integer t) {
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 testAnyWithEmptyObservable() {
Observable<Integer> w = Observable.empty();
Observable<Boolean> observable = w.any(new Predicate<Integer>() {
@Override
public boolean test(Integer v) {
return true;
}
}).toObservable();
Observer<Boolean> observer = TestHelper.mockObserver();
observable.subscribe(observer);
verify(observer, times(1)).onNext(false);
verify(observer, never()).onNext(true);
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testPredicateThrowsExceptionAndValueInCauseMessage() {
TestObserver<Boolean> to = new TestObserver<Boolean>();
final IllegalArgumentException ex = new IllegalArgumentException();
Observable.just("Boo!").any(new Predicate<String>() {
@Override
public boolean test(String v) {
throw ex;
}
}).subscribe(to);
to.assertTerminated();
to.assertNoValues();
to.assertNotComplete();
to.assertError(ex);
// FIXME value as last cause?
// assertTrue(ex.getCause().getMessage().contains("Boo!"));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testWithFollowingFirst() {
Observable<Integer> o = Observable.fromArray(1, 3, 5, 6);
Single<Boolean> anyEven = o.any(new Predicate<Integer>() {
@Override
public boolean test(Integer i) {
return i % 2 == 0;
}
});
assertTrue(anyEven.blockingGet());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testWithFollowingFirstObservable() {
Observable<Integer> o = Observable.fromArray(1, 3, 5, 6);
Observable<Boolean> anyEven = o.any(new Predicate<Integer>() {
@Override
public boolean test(Integer i) {
return i % 2 == 0;
}
}).toObservable();
assertTrue(anyEven.blockingFirst());
}
内容来源于网络,如有侵权,请联系作者删除!