当前位置: 首页>>代码示例>>Java>>正文


Java Collectors.toMap方法代码示例

本文整理汇总了Java中java.util.stream.Collectors.toMap方法的典型用法代码示例。如果您正苦于以下问题:Java Collectors.toMap方法的具体用法?Java Collectors.toMap怎么用?Java Collectors.toMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.stream.Collectors的用法示例。


在下文中一共展示了Collectors.toMap方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildTreeMapCollector

import java.util.stream.Collectors; //导入方法依赖的package包/类
/**
 * Return a Collector that collects to a TreeMap using the supplied key and value mappers. Duplicate keys will
 * result in a {@link RuntimeException}. Useful for creating sorted maps to go into HealthCheck detail values
 */
static <T, K, U> Collector<T, ?, TreeMap<K, U>> buildTreeMapCollector(
        Function<? super T, ? extends K> keyMapper,
        Function<? super T, ? extends U> valueMapper) {

    return Collectors.toMap(
            keyMapper,
            valueMapper,
            (v1, v2) -> {
                throw new RuntimeException(String.format("Duplicate key for values %s and %s", v1, v2));
            },
            TreeMap::new);
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:17,代码来源:HasHealthCheck.java

示例2: collectToBiMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
public static <T, K, U> Collector<T, ?, BiMap<K, U>> collectToBiMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) {
    Collector<T, ?, BiMap<K, U>> x = Collectors.toMap(
            keyMapper, valueMapper,
            (u, v) -> {
                throw new RuntimeException("should not hapen: " + u + " --- map: " + v);
            },
            HashBiMap::create);
    return x;
}
 
开发者ID:SmartDataAnalytics,项目名称:SubgraphIsomorphismIndex,代码行数:10,代码来源:SubgraphIsomorphismIndexImpl.java

示例3: toMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
public static <K, U, M extends Map<K, U>> Collector<Map.Entry<K, U>, ?, M> toMap(Supplier<M> mapSupplier) {
    return Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, throwingMerger(), mapSupplier);
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:4,代码来源:CollectionUtil.java

示例4: toLinkedMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
public static <T, K, U> Collector<T, ?, Map<K, U>> toLinkedMap(Function<? super T, ? extends K> keyMapper,
                                                               Function<? super T, ? extends U> valueMapper) {
    return Collectors.toMap(keyMapper, valueMapper, (u, v) -> {
        throw new IllegalStateException(String.format("Duplicate key %s", u));
    }, LinkedHashMap::new);
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:7,代码来源:SCollectors.java

示例5: entriesToMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
public static <K, U> Collector<Map.Entry<K, U>, ?, Map<K, U>> entriesToMap() {
    return Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue);
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:4,代码来源:Maps.java

示例6: pairsToMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
public static <A,B> Collector<Pair<A,B>,?,Map<A,B>> pairsToMap(){
	return Collectors.toMap(Pair::getLeft, Pair::getRight);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:4,代码来源:StreamTool.java

示例7: entriesToMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
public static <A,B> Collector<Entry<A,B>,?,Map<A,B>> entriesToMap(){
	return Collectors.toMap(Entry::getKey, Entry::getValue);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:4,代码来源:StreamTool.java

示例8: entriesToMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
public static <K, U> Collector<Map.Entry<K, U>, ?, Map<K, U>> entriesToMap() {
    return Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue());
}
 
开发者ID:ohpauleez,项目名称:dais,代码行数:4,代码来源:Maps.java

示例9: map

import java.util.stream.Collectors; //导入方法依赖的package包/类
/**
 * Returns a {@code Collector} that accumulates the input elements into a new {@code LinkedHashMap}.
 *
 * @param keyTransformation   the transformation function used to derive a resulting entry key from each item
 * @param valueTransformation the transformation function used to derive a resulting entry value from each item
 * @param <T>                 the type of the input elements
 * @param <K>                 the type of the output map keys
 * @param <V>                 the type of the output map values
 * @return a new collector that accumulates the input elements into a new {@code LinkedHashMap}
 * @see #map()
 */
public static <T, K, V> Collector<T, ?, Map<K, V>> map(Function<? super T, ? extends K> keyTransformation,
                                                       Function<? super T, ? extends V> valueTransformation) {

	BinaryOperator<V> merger = throwingMerger();

	return Collectors.toMap(keyTransformation, valueTransformation, merger, New::map);
}
 
开发者ID:essentials4j,项目名称:essentials4j,代码行数:19,代码来源:To.java

示例10: toMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
/**
 * Collects a stream of pairs into a map
 * @param <K> the left type of the pair, interpreted as the key type
 * @param <V> the right type of the pair, interpreted as the value type
 * @return a Collector which collects a Stream of Pairs into a Map
 */
static <K, V> Collector<Pair<K, V>, ?, Map<K, V>> toMap() {
    return Collectors.toMap(Pair::left, Pair::right);
}
 
开发者ID:unruly,项目名称:control,代码行数:10,代码来源:Maps.java

示例11: entriesToMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
/**
 * Converts entries to map.
 *
 * @param <K> Key type
 * @param <V> Value type
 * @return a collector
 */
public static <K, V> Collector<Entry<K, V>, ?, Map<K, V>> entriesToMap() {
  return Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue());
}
 
开发者ID:springuni,项目名称:springuni-particles,代码行数:11,代码来源:Maps.java

示例12: toMap

import java.util.stream.Collectors; //导入方法依赖的package包/类
/**
 * Collect a stream of {@link Map.Entry} to a {@link Map} with the same key/value types
 * @param <K> the key type
 * @param <V> the value type
 * @return a map
 */
public static <K, V> Collector<Map.Entry<K, V>, ?, Map<K, V>> toMap() {
    return Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:10,代码来源:CollectionUtils.java


注:本文中的java.util.stream.Collectors.toMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。