reactor.core.publisher.Flux.collectMultimap()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(264)

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

Flux.collectMultimap介绍

[英]Collect all elements emitted by this Flux into a Map that is emitted by the resulting Mono when this sequence completes. The key is extracted from each element by applying the keyExtractorFunction, and every element mapping to the same key is stored in the Listassociated to said key.
[中]

代码示例

代码示例来源:origin: reactor/reactor-core

/**
 * Collect all elements emitted by this {@link Flux} into a {@link Map multimap} that is
 * emitted by the resulting {@link Mono} when this sequence completes.
 * The key is extracted from each element by applying the {@code keyExtractor}
 * {@link Function}, and every element mapping to the same key is converted by the
 * {@code valueExtractor} Function to a value stored in the {@link List} associated to
 * said key.
 *
 * <p>
 * <img class="marble" src="doc-files/marbles/collectMultiMapWithKeyAndValueExtractors.svg" alt="">
 *
 * @param keyExtractor a {@link Function} to map elements to a key for the {@link Map}
 * @param valueExtractor a {@link Function} to map elements to a value for the {@link Map}
 *
 * @param <K> the type of the key extracted from each source element
 * @param <V> the type of the value extracted from each source element
 *
 * @return a {@link Mono} of a {@link Map} of key-List(values) pairs
 */
public final <K, V> Mono<Map<K, Collection<V>>> collectMultimap(Function<? super T, ? extends K> keyExtractor,
    Function<? super T, ? extends V> valueExtractor) {
  return collectMultimap(keyExtractor, valueExtractor, () -> new HashMap<>());
}

代码示例来源:origin: reactor/reactor-core

/**
 * Collect all elements emitted by this {@link Flux} into a {@link Map multimap} that is
 * emitted by the resulting {@link Mono} when this sequence completes.
 * The key is extracted from each element by applying the {@code keyExtractor}
 * {@link Function}, and every element mapping to the same key is stored in the {@link List}
 * associated to said key.
 *
 * <p>
 * <img class="marble" src="doc-files/marbles/collectMultiMapWithKeyExtractor.svg" alt="">
 *
 * @param keyExtractor a {@link Function} to map elements to a key for the {@link Map}
 *
 * @param <K> the type of the key extracted from each source element
 * @return a {@link Mono} of a {@link Map} of key-List(elements) pairs
 */
public final <K> Mono<Map<K, Collection<T>>> collectMultimap(Function<? super T, ? extends K> keyExtractor) {
  return collectMultimap(keyExtractor, identityFunction());
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Mono<MultiValueMap<String, Part>> readMono(ResolvableType elementType,
    ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
  Map<String, Object> allHints = Hints.merge(hints, Hints.SUPPRESS_LOGGING_HINT, true);
  return this.partReader.read(elementType, inputMessage, allHints)
      .collectMultimap(Part::name)
      .doOnNext(map -> {
        LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Parsed " +
            (isEnableLoggingRequestDetails() ?
                LogFormatUtils.formatValue(map, !traceOn) :
                "parts " + map.keySet() + " (content masked)"));
      })
      .map(this::toMultiValueMap);
}

代码示例来源:origin: org.springframework/spring-web

@Override
public Mono<MultiValueMap<String, Part>> readMono(ResolvableType elementType,
    ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
  Map<String, Object> allHints = Hints.merge(hints, Hints.SUPPRESS_LOGGING_HINT, true);
  return this.partReader.read(elementType, inputMessage, allHints)
      .collectMultimap(Part::name)
      .doOnNext(map -> {
        LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Parsed " +
            (isEnableLoggingRequestDetails() ?
                LogFormatUtils.formatValue(map, !traceOn) :
                "parts " + map.keySet() + " (content masked)"));
      })
      .map(this::toMultiValueMap);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void collectMultiMapEmpty() {
  StepVerifier.create(Flux.<Pojo>empty().collectMultimap(p -> p.id))
        .assertNext(d -> assertThat(d).isEmpty())
        .verifyComplete();
}

代码示例来源:origin: reactor/reactor-core

@Test
  public void collectMultiMapCallable() {
    StepVerifier.create(Mono.fromCallable(() -> new Pojo("test", 1L))
                .flux()
                .collectMultimap(p -> p.id))
          .assertNext(p -> assertThat(p).containsOnlyKeys(1L)
                         .containsValues(Arrays.asList(new Pojo(
                             "test",
                             1L))))
          .verifyComplete();

  }
}

代码示例来源:origin: reactor/reactor-core

@Test
public void collectMultiMap() {
  StepVerifier.create(Flux.just(new Pojo("test", 1L),
      new Pojo("test", 2L),
      new Pojo("test2", 3L))
              .collectMultimap(p -> p.name))
        .assertNext(d -> assertThat(d).containsKeys("test", "test2")
                       .containsValues(Arrays.asList(new Pojo(
                               "test",
                               1L), new Pojo("test", 2L)),
                           Arrays.asList(new Pojo("test2",
                               3L))))
        .verifyComplete();
}

代码示例来源:origin: com.aol.cyclops/cyclops-reactor

/**
 * @param keyExtractor
 * @param valueExtractor
 * @return
 * @see reactor.core.publisher.Flux#collectMultimap(java.util.function.Function, java.util.function.Function)
 */
public final <K, V> Mono<Map<K, Collection<V>>> collectMultimap(Function<? super T, ? extends K> keyExtractor,
    Function<? super T, ? extends V> valueExtractor) {
  return boxed.collectMultimap(keyExtractor, valueExtractor);
}
/**

代码示例来源:origin: com.aol.cyclops/cyclops-reactor

/**
 * @param keyExtractor
 * @return
 * @see reactor.core.publisher.Flux#collectMultimap(java.util.function.Function)
 */
public final <K> Mono<Map<K, Collection<T>>> collectMultimap(Function<? super T, ? extends K> keyExtractor) {
  return boxed.collectMultimap(keyExtractor);
}
/**

代码示例来源:origin: com.aol.cyclops/cyclops-reactor

/**
 * @param keyExtractor
 * @param valueExtractor
 * @param mapSupplier
 * @return
 * @see reactor.core.publisher.Flux#collectMultimap(java.util.function.Function, java.util.function.Function, java.util.function.Supplier)
 */
public final <K, V> Mono<Map<K, Collection<V>>> collectMultimap(Function<? super T, ? extends K> keyExtractor,
    Function<? super T, ? extends V> valueExtractor, Supplier<Map<K, Collection<V>>> mapSupplier) {
  return boxed.collectMultimap(keyExtractor, valueExtractor, mapSupplier);
}
/**

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

/**
 * Collect all elements emitted by this {@link Flux} into a {@link Map multimap} that is
 * emitted by the resulting {@link Mono} when this sequence completes.
 * The key is extracted from each element by applying the {@code keyExtractor}
 * {@link Function}, and every element mapping to the same key is converted by the
 * {@code valueExtractor} Function to a value stored in the {@link List} associated to
 * said key.
 *
 * <p>
 * <img class="marble" src="doc-files/marbles/collectMultiMapWithKeyAndValueExtractors.svg" alt="">
 *
 * @param keyExtractor a {@link Function} to map elements to a key for the {@link Map}
 * @param valueExtractor a {@link Function} to map elements to a value for the {@link Map}
 *
 * @param <K> the type of the key extracted from each source element
 * @param <V> the type of the value extracted from each source element
 *
 * @return a {@link Mono} of a {@link Map} of key-List(values) pairs
 */
public final <K, V> Mono<Map<K, Collection<V>>> collectMultimap(Function<? super T, ? extends K> keyExtractor,
    Function<? super T, ? extends V> valueExtractor) {
  return collectMultimap(keyExtractor, valueExtractor, () -> new HashMap<>());
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Mono<MultiValueMap<String, Part>> readMono(ResolvableType elementType,
    ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
  return this.partReader.read(elementType, inputMessage, hints)
      .collectMultimap(Part::name).map(this::toMultiValueMap);
}

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

/**
 * Collect all elements emitted by this {@link Flux} into a {@link Map multimap} that is
 * emitted by the resulting {@link Mono} when this sequence completes.
 * The key is extracted from each element by applying the {@code keyExtractor}
 * {@link Function}, and every element mapping to the same key is stored in the {@link List}
 * associated to said key.
 *
 * <p>
 * <img class="marble" src="doc-files/marbles/collectMultiMapWithKeyExtractor.svg" alt="">
 *
 * @param keyExtractor a {@link Function} to map elements to a key for the {@link Map}
 *
 * @param <K> the type of the key extracted from each source element
 * @return a {@link Mono} of a {@link Map} of key-List(elements) pairs
 */
public final <K> Mono<Map<K, Collection<T>>> collectMultimap(Function<? super T, ? extends K> keyExtractor) {
  return collectMultimap(keyExtractor, identityFunction());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

@Override
public Mono<MultiValueMap<String, Part>> readMono(ResolvableType elementType,
    ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
  Map<String, Object> allHints = Hints.merge(hints, Hints.SUPPRESS_LOGGING_HINT, true);
  return this.partReader.read(elementType, inputMessage, allHints)
      .collectMultimap(Part::name)
      .doOnNext(map -> {
        LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Parsed " +
            (isEnableLoggingRequestDetails() ?
                LogFormatUtils.formatValue(map, !traceOn) :
                "parts " + map.keySet() + " (content masked)"));
      })
      .map(this::toMultiValueMap);
}

相关文章

Flux类方法