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

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

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

Observable.toMultimap介绍

[英]Returns an Observable that emits a single HashMap that contains an ArrayList of items emitted by the source Observable keyed by a specified keySelector function.

Backpressure Support: This operator does not support backpressure as by intent it is requesting and buffering everything. Scheduler: toMultiMap does not operate by default on a particular Scheduler.
[中]返回一个Observable,该Observable发出一个HashMap,该HashMap包含由指定keySelector函数键控的源Observable发出的项的ArrayList。
背压支持:该操作员无意支持背压,因为它正在请求和缓冲所有内容。调度器:默认情况下,toMultiMap不会在特定的调度器上运行。

代码示例

代码示例来源:origin: spencergibb/myfeed

@RequestMapping("/init/all")
public Single<Map<String, Collection<FeedItem>>> initAll() {
  return userService.getUsers()
      .map(Resource::getContent)
      .map(User::getUsername)
      .flatMap(this::initUser)
      .toMultimap(ufi -> ufi.username, ufi -> ufi.feedItem).toSingle();
}

代码示例来源:origin: io.wcm.caravan/io.wcm.caravan.io.http

@Override
public Map<String, String[]> getParameterMap() {
 try {
  List<NameValuePair> pairs = URLEncodedUtils.parse(new URI(request.getUrl()), Charsets.UTF_8.toString());
  Map<String, Collection<String>> multiMap = Observable.from(pairs).toMultimap(NameValuePair::getName, NameValuePair::getValue).toBlocking().single();
  Builder<String, String[]> builder = ImmutableMap.builder();
  multiMap.entrySet().stream().forEach(entry -> {
   String[] arrayValue = entry.getValue().toArray(new String[entry.getValue().size()]);
   builder.put(entry.getKey(), arrayValue);
  });
  return builder.build();
 }
 catch (URISyntaxException ex) {
  ex.printStackTrace();
 }
 return null;
}

相关文章

Observable类方法