本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}