@Override public Observable<Boolean> call(Observable<T> source) { return updateBuilder.dependsOn(source).count().exists(IS_NON_ZERO); } };
/** * Commits or rolls back a transaction depending on the <code>commit</code> * parameter and resets the current query context so that further queries * will use the asynchronous version by default. All Observable dependencies * must be complete before commit/rollback is called. * * @param commit * @param depends * @return */ private Observable<Boolean> commitOrRollback(boolean commit, Observable<?>... depends) { QueryUpdate.Builder u = createCommitOrRollbackQuery(commit); for (Observable<?> dep : depends) u = u.dependsOn(dep); Observable<Boolean> result = u.count().exists(IS_NON_ZERO); lastTransactionResult.set(result); return result; }
/** * Returns an Observable that emits a Boolean that indicates whether the source Observable emitted a * specified item. * <p> * <img width="640" height="320" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/contains.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code contains} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param element * the item to search for in the emissions from the source Observable * @return an Observable that emits {@code true} if the specified item is emitted by the source Observable, * or {@code false} if the source Observable completes without emitting that item * @see <a href="https://github.com/Netflix/RxJava/wiki/Conditional-and-Boolean-Operators#contains">RxJava wiki: contains</a> * @see <a href="http://msdn.microsoft.com/en-us/library/hh228965.aspx">MSDN: Observable.Contains</a> */ public final Observable<Boolean> contains(final Object element) { return exists(new Func1<T, Boolean>() { public final Boolean call(T t1) { return element == null ? t1 == null : element.equals(t1); } }); }
@Override public void run() { Observable.just(1, 2, 3).exists(new Func1<Integer, Boolean>() { @Override public Boolean call(Integer integer) { return integer > 3; } }).subscribe(new Action1<Boolean>() { @Override public void call(Boolean aBoolean) { log(aBoolean); } }); } });
@Test public void sample_550() throws Exception { Observable<Integer> numbers = Observable.range(1, 5); numbers.all(x -> x != 4); // [false] numbers.exists(x -> x == 4); // [true] numbers.contains(4); // [true] }