本文整理了Java中io.reactivex.Observable.all()
方法的一些代码示例,展示了Observable.all()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.all()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:all
[英]Returns a Single that emits a Boolean that indicates whether all of the items emitted by the source ObservableSource satisfy a condition.
Scheduler: all does not operate by default on a particular Scheduler.
[中]返回一个单一值,该值发出一个布尔值,指示源ObservableSource发出的所有项是否满足某个条件。
调度器:默认情况下,all不会在特定的调度器上运行。
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void allPredicateNull() {
just1.all(null);
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns a Single that emits {@code true} if the source ObservableSource is empty, otherwise {@code false}.
* <p>
* In Rx.Net this is negated as the {@code any} Observer but we renamed this in RxJava to better match Java
* naming idioms.
* <p>
* <img width="640" height="320" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/isEmpty.2.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code isEmpty} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @return a Single that emits a Boolean
* @see <a href="http://reactivex.io/documentation/operators/contains.html">ReactiveX operators documentation: Contains</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<Boolean> isEmpty() {
return all(Functions.alwaysFalse());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testNotAll() {
Observable<String> obs = Observable.just("one", "two", "three", "six");
SingleObserver <Boolean> observer = TestHelper.mockSingleObserver();
obs.all(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.length() == 3;
}
})
.subscribe(observer);
verify(observer).onSubscribe((Disposable)any());
verify(observer).onSuccess(false);
verifyNoMoreInteractions(observer);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testAll() {
Observable<String> obs = Observable.just("one", "two", "six");
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
obs.all(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.length() == 3;
}
})
.subscribe(observer);
verify(observer).onSubscribe((Disposable)any());
verify(observer).onSuccess(true);
verifyNoMoreInteractions(observer);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void testIssue1935NoUnsubscribeDownstream() {
Observable<Integer> source = Observable.just(1)
.all(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return false;
}
})
.flatMapObservable(new Function<Boolean, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Boolean t1) {
return Observable.just(2).delay(500, TimeUnit.MILLISECONDS);
}
});
assertEquals((Object)2, source.blockingFirst());
}
代码示例来源:origin: redisson/redisson
/**
* Returns a Single that emits {@code true} if the source ObservableSource is empty, otherwise {@code false}.
* <p>
* In Rx.Net this is negated as the {@code any} Observer but we renamed this in RxJava to better match Java
* naming idioms.
* <p>
* <img width="640" height="320" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/isEmpty.2.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code isEmpty} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @return a Single that emits a Boolean
* @see <a href="http://reactivex.io/documentation/operators/contains.html">ReactiveX operators documentation: Contains</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<Boolean> isEmpty() {
return all(Functions.alwaysFalse());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Observable.just(1).all(Functions.alwaysTrue()).toObservable());
TestHelper.checkDisposed(Observable.just(1).all(Functions.alwaysTrue()));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testError() {
Throwable error = new Throwable();
Observable<String> obs = Observable.error(error);
SingleObserver <Boolean> observer = TestHelper.mockSingleObserver();
obs.all(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.length() == 3;
}
})
.subscribe(observer);
verify(observer).onSubscribe((Disposable)any());
verify(observer).onError(error);
verifyNoMoreInteractions(observer);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testEmpty() {
Observable<String> obs = Observable.empty();
SingleObserver <Boolean> observer = TestHelper.mockSingleObserver();
obs.all(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.length() == 3;
}
})
.subscribe(observer);
verify(observer).onSubscribe((Disposable)any());
verify(observer).onSuccess(true);
verifyNoMoreInteractions(observer);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testAllObservable() {
Observable<String> obs = Observable.just("one", "two", "six");
Observer <Boolean> observer = TestHelper.mockObserver();
obs.all(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.length() == 3;
}
}).toObservable()
.subscribe(observer);
verify(observer).onSubscribe((Disposable)any());
verify(observer).onNext(true);
verify(observer).onComplete();
verifyNoMoreInteractions(observer);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testNotAllObservable() {
Observable<String> obs = Observable.just("one", "two", "three", "six");
Observer <Boolean> observer = TestHelper.mockObserver();
obs.all(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.length() == 3;
}
}).toObservable()
.subscribe(observer);
verify(observer).onSubscribe((Disposable)any());
verify(observer).onNext(false);
verify(observer).onComplete();
verifyNoMoreInteractions(observer);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testErrorObservable() {
Throwable error = new Throwable();
Observable<String> obs = Observable.error(error);
Observer <Boolean> observer = TestHelper.mockObserver();
obs.all(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.length() == 3;
}
}).toObservable()
.subscribe(observer);
verify(observer).onSubscribe((Disposable)any());
verify(observer).onError(error);
verifyNoMoreInteractions(observer);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void testIssue1935NoUnsubscribeDownstreamObservable() {
Observable<Integer> source = Observable.just(1)
.all(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return false;
}
}).toObservable()
.flatMap(new Function<Boolean, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Boolean t1) {
return Observable.just(2).delay(500, TimeUnit.MILLISECONDS);
}
});
assertEquals((Object)2, source.blockingFirst());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testEmptyObservable() {
Observable<String> obs = Observable.empty();
Observer <Boolean> observer = TestHelper.mockObserver();
obs.all(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.length() == 3;
}
}).toObservable()
.subscribe(observer);
verify(observer).onSubscribe((Disposable)any());
verify(observer).onNext(true);
verify(observer).onComplete();
verifyNoMoreInteractions(observer);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testPredicateThrowsExceptionAndValueInCauseMessageObservable() {
TestObserver<Boolean> to = new TestObserver<Boolean>();
final IllegalArgumentException ex = new IllegalArgumentException();
Observable.just("Boo!").all(new Predicate<String>() {
@Override
public boolean test(String v) {
throw ex;
}
})
.subscribe(to);
to.assertTerminated();
to.assertNoValues();
to.assertNotComplete();
to.assertError(ex);
// FIXME need to decide about adding the value that probably caused the crash in some way
// assertTrue(ex.getCause().getMessage().contains("Boo!"));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testPredicateThrowsExceptionAndValueInCauseMessage() {
TestObserver<Boolean> to = new TestObserver<Boolean>();
final IllegalArgumentException ex = new IllegalArgumentException();
Observable.just("Boo!").all(new Predicate<String>() {
@Override
public boolean test(String v) {
throw ex;
}
})
.subscribe(to);
to.assertTerminated();
to.assertNoValues();
to.assertNotComplete();
to.assertError(ex);
// FIXME need to decide about adding the value that probably caused the crash in some way
// assertTrue(ex.getCause().getMessage().contains("Boo!"));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFollowingFirst() {
Observable<Integer> o = Observable.fromArray(1, 3, 5, 6);
Single<Boolean> allOdd = o.all(new Predicate<Integer>() {
@Override
public boolean test(Integer i) {
return i % 2 == 1;
}
});
assertFalse(allOdd.blockingGet());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFollowingFirstObservable() {
Observable<Integer> o = Observable.fromArray(1, 3, 5, 6);
Observable<Boolean> allOdd = o.all(new Predicate<Integer>() {
@Override
public boolean test(Integer i) {
return i % 2 == 1;
}
}).toObservable();
assertFalse(allOdd.blockingFirst());
}
内容来源于网络,如有侵权,请联系作者删除!