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

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

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

Observable.limit介绍

[英]Returns an Observable that emits only the first num items emitted by the source Observable.

Alias of #take(int) to match Java 8 Stream API naming convention.

This method returns an Observable that will invoke a subscribing Observer's Observer#onNext function a maximum of num times before invoking Observer#onCompleted. Scheduler: limit does not operate by default on a particular Scheduler.
[中]返回仅发射源可观测项发射的前num项的可观测项。
#take(int)的别名,以匹配Java 8流API命名约定。
此方法返回一个Observable,在调用Observator#onCompleted之前,该Observable将调用订阅观察器的Observator#onNext函数最多num次。调度程序:默认情况下,限制不会在特定调度程序上运行。

代码示例

代码示例来源:origin: apache/usergrid

countObservable = countObservable.limit(limit);

代码示例来源:origin: com.netflix.spinnaker.orca/orca-redis

@Override
public
@Nonnull Observable<Execution> retrieve(
 @Nonnull ExecutionType type,
 @Nonnull ExecutionCriteria criteria
) {
 List<Observable<Execution>> observables = allRedisDelegates()
  .stream()
  .map(d -> {
    Observable<Execution> observable = all(type, d);
    if (!criteria.getStatuses().isEmpty()) {
     observable = observable.filter(execution -> criteria.getStatuses().contains(execution.getStatus()));
    }
    if (criteria.getPageSize() > 0) {
     observable = observable.limit(criteria.getPageSize());
    }
    return observable;
   }
  )
  .collect(Collectors.toList());
 return Observable.merge(observables);
}

代码示例来源:origin: hawkular/hawkular-metrics

@Override
public Observable<DataPoint<AvailabilityType>> findAvailabilityData(MetricId<AvailabilityType> id, long start,
    long end, boolean distinct, int limit, Order order) {
  checkArgument(isValidTimeRange(start, end), "Invalid time range");
  if (distinct) {
    Observable<DataPoint<AvailabilityType>> availabilityData = findDataPoints(id, start, end, 0, order)
        .distinctUntilChanged(DataPoint::getValue);
    if (limit <= 0) {
      return availabilityData;
    } else {
      return availabilityData.limit(limit);
    }
  } else {
    return findDataPoints(id, start, end, limit, order);
  }
}

代码示例来源:origin: org.hawkular.metrics/hawkular-metrics-core-service

@Override
public Observable<DataPoint<AvailabilityType>> findAvailabilityData(MetricId<AvailabilityType> id, long start,
    long end, boolean distinct, int limit, Order order) {
  checkArgument(isValidTimeRange(start, end), "Invalid time range");
  if (distinct) {
    Observable<DataPoint<AvailabilityType>> availabilityData = findDataPoints(id, start, end, 0, order)
        .distinctUntilChanged(DataPoint::getValue);
    if (limit <= 0) {
      return availabilityData;
    } else {
      return availabilityData.limit(limit);
    }
  } else {
    return findDataPoints(id, start, end, limit, order);
  }
}

代码示例来源:origin: DingMouRen/DingDingMusic

@Override
public void initData() {
  long count = MyApplication.getDaoSession().getMusicBeanDao() .queryBuilder()
      .whereOr(MusicBeanDao.Properties.Type.eq(Integer.valueOf(Constant.MUSIC_WEST)),
          MusicBeanDao.Properties.Type.eq(Integer.valueOf(Constant.MUSIC_INLAND)),
          MusicBeanDao.Properties.Type.eq(Integer.valueOf(Constant.MUSIC_HONGKANG)),
          MusicBeanDao.Properties.Type.eq(Integer.valueOf(Constant.MUSIC_KOREA)),
          MusicBeanDao.Properties.Type.eq(Integer.valueOf(Constant.MUSIC_JAPAN)),
          MusicBeanDao.Properties.Type.eq(Integer.valueOf(Constant.MUSIC_VOLKSLIED)),
          MusicBeanDao.Properties.Type.eq(Integer.valueOf(Constant.MUSIC_ROCK)),
          MusicBeanDao.Properties.Type.eq(Integer.valueOf(Constant.MUSIC_SALES)),
          MusicBeanDao.Properties.Type.eq(Integer.valueOf(Constant.MUSIC_HOT))).count();
  JLog.e(TAG,"count:" + count);
    mRequestMusicUtil = new RequestMusicUtil();
    Observable.interval(1000, 1500, TimeUnit.MILLISECONDS).limit(9)
        .subscribe(aLong -> mRequestMusicUtil.requestMusic(topics[aLong.intValue()]));
}

相关文章

Observable类方法