rx.Observable.exists()方法的使用及代码示例

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

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

Observable.exists介绍

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

In Rx.Net this is the any Observer but we renamed it in RxJava to better match Java naming idioms. Scheduler: exists does not operate by default on a particular Scheduler.
[中]如果源可观测项发出的任何项满足指定条件,则返回发出true的可观测项,否则返回false*注:*如果源可观测值为空,则该值始终为假。
在Rx。Net这是any Observer,但我们在RxJava中对其进行了重命名,以更好地匹配Java命名习惯用法。调度程序:默认情况下,exists不会在特定调度程序上运行。

代码示例

代码示例来源:origin: davidmoten/rxjava-jdbc

@Override
  public Observable<Boolean> call(Observable<T> source) {
    return updateBuilder.dependsOn(source).count().exists(IS_NON_ZERO);
  }
};

代码示例来源:origin: davidmoten/rxjava-jdbc

/**
 * 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;
}

代码示例来源:origin: com.netflix.rxjava/rxjava-core

/**
 * 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);
    }
  });
}

代码示例来源:origin: leeowenowen/rxjava-examples

@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);
   }
  });
 }
});

代码示例来源:origin: nurkiewicz/rxjava-book-examples

@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]
}

相关文章

Observable类方法