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

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

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

Observable.forEach介绍

[英]Subscribes to the Observable and receives notifications for each element.

Alias to #subscribe(Action1) Scheduler: forEach does not operate by default on a particular Scheduler.
[中]订阅Observable并接收每个元素的通知。
#订阅(Action1)调度程序别名:forEach默认情况下不会在特定调度程序上运行。

代码示例

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

private List<UUID> getAllVersions( final EntityCollectionManager ecm,
                  final Id entityId ) {
  final List<UUID> versions = new ArrayList<>();
  ecm.getVersionsFromMaxToMin(entityId, UUIDUtils.newTimeUUID())
    .forEach( mvccLogEntry -> {
      versions.add(mvccLogEntry.getVersion());
    });
  return versions;
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

/**
 * 设置轮播banners
 */
private void convertBanner() {
  Observable.from(recommendBanners)
      .compose(bindToLifecycle())
      .forEach(dataBean -> banners.add(new BannerEntity(dataBean.getValue(),
          dataBean.getTitle(), dataBean.getImage())));
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void setBanner() {
  Observable.from(banners)
      .compose(bindToLifecycle())
      .forEach(topBean -> bannerEntities.add(new BannerEntity(
          topBean.getUri(), topBean.getTitle(), topBean.getImage())));
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void setBanner() {
  Observable.from(banners)
      .compose(bindToLifecycle())
      .forEach(topBean -> bannerEntities.add(new BannerEntity(topBean.getUri(),
          topBean.getTitle(), topBean.getImage())));
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

public void setLiveInfo(LiveAppIndexInfo liveAppIndexInfo) {
  this.mLiveAppIndexInfo = liveAppIndexInfo;
  entranceSize = 4;
  liveSizes.clear();
  bannerEntitys.clear();
  int tempSize = 0;
  int partitionSize = mLiveAppIndexInfo.getData().getPartitions().size();
  List<LiveAppIndexInfo.DataBean.BannerBean> banner = mLiveAppIndexInfo.getData().getBanner();
  Observable.from(banner)
      .forEach(bannerBean -> bannerEntitys.add(new BannerEntity(
          bannerBean.getLink(), bannerBean.getTitle(), bannerBean.getImg())));
  for (int i = 0; i < partitionSize; i++) {
    liveSizes.add(tempSize);
    tempSize += mLiveAppIndexInfo.getData().getPartitions().get(i).getLives().size();
  }
}

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

private List<UUID> getVersionsOlderThanMarked(final EntityCollectionManager ecm, final Id entityId,
                       final UUID markedVersion ){
  final List<UUID> versions = new ArrayList<>();
  // only take last 100 versions to avoid eating memory. a tool can be built for massive cleanups for old usergrid
  // clusters that do not have this in-line cleanup
  ecm.getVersionsFromMaxToMin( entityId, markedVersion)
    .take(100)
    .forEach( mvccLogEntry -> {
      if ( mvccLogEntry.getVersion().timestamp() < markedVersion.timestamp() ) {
        versions.add(mvccLogEntry.getVersion());
      }
    });
  return versions;
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void finishTask() {
  Observable.from(results)
      .compose(bindToLifecycle())
      .forEach(resultBean -> mSectionedRecyclerViewAdapter.addSection(
          new SeasonNewBangumiSection(SeasonNewBangumiActivity.this,
              resultBean.getSeason(), resultBean.getYear(), resultBean.getList())));
  mSectionedRecyclerViewAdapter.notifyDataSetChanged();
  hideProgressBar();
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void finishTask() {
  Observable.from(bangumiSchedules)
      .compose(bindToLifecycle())
      .forEach(this::accordingWeekGroup);
  mSectionedAdapter.addSection(new BangumiScheduleSection(BangumiScheduleActivity.this, sundayBangumis, ConstantUtil.SUNDAY_TYPE,
      saturdayBangumis.size() > 0 ? WeekDayUtil.formatDate(sundayBangumis.get(0).getPub_date()) : ""));
  mSectionedAdapter.addSection(new BangumiScheduleSection(BangumiScheduleActivity.this, mondayBangumis, ConstantUtil.MONDAY_TYPE,
      mondayBangumis.size() > 0 ? WeekDayUtil.formatDate(mondayBangumis.get(0).getPub_date()) : ""));
  mSectionedAdapter.addSection(new BangumiScheduleSection(BangumiScheduleActivity.this, tuesdayBangumis, ConstantUtil.TUESDAY_TYPE,
      tuesdayBangumis.size() > 0 ? WeekDayUtil.formatDate(tuesdayBangumis.get(0).getPub_date()) : ""));
  mSectionedAdapter.addSection(new BangumiScheduleSection(BangumiScheduleActivity.this, wednesdayBangumis, ConstantUtil.WEDNESDAY_TYPE,
      wednesdayBangumis.size() > 0 ? WeekDayUtil.formatDate(wednesdayBangumis.get(0).getPub_date()) : ""));
  mSectionedAdapter.addSection(new BangumiScheduleSection(BangumiScheduleActivity.this, thursdayBangumis, ConstantUtil.THURSDAY_TYPE,
      thursdayBangumis.size() > 0 ? WeekDayUtil.formatDate(thursdayBangumis.get(0).getPub_date()) : ""));
  mSectionedAdapter.addSection(new BangumiScheduleSection(BangumiScheduleActivity.this, fridayBangumis, ConstantUtil.FRIDAY_TYEP,
      fridayBangumis.size() > 0 ? WeekDayUtil.formatDate(fridayBangumis.get(0).getPub_date()) : ""));
  mSectionedAdapter.addSection(new BangumiScheduleSection(BangumiScheduleActivity.this, saturdayBangumis, ConstantUtil.SATURDAY_TYPE,
      saturdayBangumis.size() > 0 ? WeekDayUtil.formatDate(saturdayBangumis.get(0).getPub_date()) : ""));
  mSectionedAdapter.notifyDataSetChanged();
  hideProgressBar();
}

代码示例来源:origin: Netflix/conductor

@Test
public void test() {
  List<Message> messages = new LinkedList<>();
  Observable.range(0, 10).forEach((Integer x) -> messages.add(new Message("" + x, "payload: " + x, null)));
  assertEquals(10, messages.size());
  SQSObservableQueue queue = mock(SQSObservableQueue.class);
  when(queue.getOrCreateQueue()).thenReturn("junit_queue_url");
  Answer<?> answer = (Answer<List<Message>>) invocation -> Collections.emptyList();
  when(queue.receiveMessages()).thenReturn(messages).thenAnswer(answer);
  when(queue.getOnSubscribe()).thenCallRealMethod();
  when(queue.observe()).thenCallRealMethod();
  List<Message> found = new LinkedList<>();
  Observable<Message> observable = queue.observe();
  assertNotNull(observable);
  observable.subscribe(found::add);
  Uninterruptibles.sleepUninterruptibly(1000, TimeUnit.MILLISECONDS);
  assertEquals(messages.size(), found.size());
  assertEquals(messages, found);
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
protected void finishTask() {
  mSwipeRefreshLayout.setRefreshing(false);
  mIsRefreshing = false;
  hideEmptyView();
  Observable.from(banners)
      .compose(bindToLifecycle())
      .forEach(bannersBean -> bannerList.add(new BannerEntity(
          bannersBean.getLink(), bannersBean.getTitle(), bannersBean.getImg())));
  mSectionedRecyclerViewAdapter.addSection(new HomeBangumiBannerSection(bannerList));
  mSectionedRecyclerViewAdapter.addSection(new HomeBangumiItemSection(getActivity()));
  mSectionedRecyclerViewAdapter.addSection(new HomeBangumiNewSerialSection(getActivity(), newBangumiSerials));
  if (!bangumibobys.isEmpty()) {
    mSectionedRecyclerViewAdapter.addSection(new HomeBangumiBobySection(getActivity(), bangumibobys));
  }
  mSectionedRecyclerViewAdapter.addSection(new HomeBangumiSeasonNewSection(getActivity(), season, seasonNewBangumis));
  mSectionedRecyclerViewAdapter.addSection(new HomeBangumiRecommendSection(getActivity(), bangumiRecommends));
  mSectionedRecyclerViewAdapter.notifyDataSetChanged();
}

代码示例来源:origin: jhusain/learnrxjava

public static void main(String... args) {
    Observable.range(0, 10).reduce(new ArrayList<>(), (list, i) -> {
      list.add(i);
      return list;
    }).forEach(System.out::println);

    System.out.println("... vs ...");

    Observable.range(0, 10).scan(new ArrayList<>(), (list, i) -> {
      list.add(i);
      return list;
    }).forEach(System.out::println);
  }
}

代码示例来源:origin: jhusain/learnrxjava

.flatMap(g -> {
  return g.toList();
}).forEach(System.out::println);
.flatMap(g -> {
  return g.take(10).toList();
}).forEach(System.out::println);
.flatMap(g -> {
  return g.filter(i -> i <= 20).toList();
}).forEach(System.out::println);
.flatMap(g -> {
  return g.take(20).toList();
}).take(2).forEach(System.out::println);
.flatMap(g -> {
  return g.takeWhile(i -> i < 30).toList();
}).filter(l -> !l.isEmpty()).forEach(System.out::println);
.flatMap(g -> {
  return g.take(3).reduce((s, s2) -> s + s2);
}).forEach(System.out::println);

代码示例来源:origin: io.macgyver/macgyver-core

protected Map<String, JsonNode> loadScheduledScriptTasks() {
  Map<String, JsonNode> m = Maps.newConcurrentMap();
  String cypher = "match (s:ScheduledTask) where length(s.script)>0 return s";
  neo4j.execCypher(cypher).forEach(it -> {
    String name = it.path(SCHEDULED_BY_SCRIPT).asText();
    if (!Strings.isNullOrEmpty(name)) {
      m.put(name, it);
    }
  });
  return m;
}

代码示例来源:origin: io.macgyver/macgyver-core

@PreAuthorize("hasAnyRole('ROLE_MACGYVER_USER', 'ROLE_MACGYVER_ADMIN')")
@RequestMapping(value="/api/core/tasks/active",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public JsonNode apiActiveTasks() {

  ObjectNode result = mapper.createObjectNode();
  ArrayNode arr = mapper.createArrayNode();
  neo4j.execCypher("match (t:TaskState) where t.state='STARTED' return t order by t.startTs").forEach(it-> {
    arr.add(it);
  });
  result.set("results", arr);
  
  return result;
}

代码示例来源:origin: HotBitmapGG/LeisureRead

private void finishTask() {
 mSwipeRefreshLayout.setRefreshing(false);
 Observable.from(top_stories)
   .forEach(topDailys -> banners.add(new BannerEntity(topDailys.getId(),
     topDailys.getTitle(), topDailys.getImage())));
 mBannerView.delayTime(5).build(banners);
 mRecyclerView.setAdapter(mHeaderViewRecyclerAdapter);
 mAdapter.notifyDataSetChanged();
}

代码示例来源:origin: au.gov.amsa.risky/ais

public static void main(String[] args) {
    Streams.nmeaFromGzip(new File("/media/an/nmea/2015/NMEA_ITU_20150521.gz"))
        .compose(o -> Streams.extract(o)).takeLast(10000).forEach(System.out::println);

  }
}

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

@Test
public void sample_345() throws Exception {
  Observable.combineLatest(
      interval(17, MILLISECONDS).map(x -> "S" + x),
      interval(10, MILLISECONDS).map(x -> "F" + x),
      (s, f) -> f + ":" + s
  ).forEach(System.out::println);
  Sleeper.sleep(Duration.ofSeconds(2));
}

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

@Test
public void sample_618() throws Exception {
  //[A, B, C, D, E...]
  Observable<Character> alphabet =
      Observable
          .range(0, 'Z' - 'A' + 1)
          .map(c -> (char) ('A' + c));
  //[A, C, E, G, I...]
  alphabet
      .compose(odd())
      .forEach(System.out::println);
}

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

@Test
public void sample_355() throws Exception {
  Observable<String> fast = interval(10, MILLISECONDS)
      .map(x -> "F" + x)
      .delay(100, MILLISECONDS)
      .startWith("FX");
  Observable<String> slow = interval(17, MILLISECONDS).map(x -> "S" + x);
  slow
      .withLatestFrom(fast, (s, f) -> s + ":" + f)
      .forEach(System.out::println);
}

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

@Test
public void sample_332() throws Exception {
  Observable<Long> red = interval(10, TimeUnit.MILLISECONDS);
  Observable<Long> green = interval(10, TimeUnit.MILLISECONDS);
  Observable.zip(
      red.timestamp(),
      green.timestamp(),
      (r, g) -> r.getTimestampMillis() - g.getTimestampMillis()
  ).forEach(System.out::println);
}

相关文章

Observable类方法