mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
MapUtil增加根据entry分组
This commit is contained in:
parent
3965535a2d
commit
508c139b22
@ -23,6 +23,7 @@
|
|||||||
* 【extra 】 resource.loader等过期参数替换(issue#2571@Github)
|
* 【extra 】 resource.loader等过期参数替换(issue#2571@Github)
|
||||||
* 【core 】 添加ObjectUtil的别名工具类ObjUtil
|
* 【core 】 添加ObjectUtil的别名工具类ObjUtil
|
||||||
* 【core 】 扩展LocalDateTimeUtil.isIn方法使用场景(pr#2589@Github)
|
* 【core 】 扩展LocalDateTimeUtil.isIn方法使用场景(pr#2589@Github)
|
||||||
|
* 【core 】 MapUtil增加根据entry分组(pr#2591@Github)
|
||||||
*
|
*
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【http 】 修复https下可能的Patch、Get请求失效问题(issue#I3Z3DH@Gitee)
|
* 【http 】 修复https下可能的Patch、Get请求失效问题(issue#I3Z3DH@Gitee)
|
||||||
|
@ -107,7 +107,7 @@ public class MapUtil {
|
|||||||
* @since 3.0.4
|
* @since 3.0.4
|
||||||
*/
|
*/
|
||||||
public static <K, V> HashMap<K, V> newHashMap(int size, boolean isLinked) {
|
public static <K, V> HashMap<K, V> newHashMap(int size, boolean isLinked) {
|
||||||
int initialCapacity = (int) (size / DEFAULT_LOAD_FACTOR) + 1;
|
final int initialCapacity = (int) (size / DEFAULT_LOAD_FACTOR) + 1;
|
||||||
return isLinked ? new LinkedHashMap<>(initialCapacity) : new HashMap<>(initialCapacity);
|
return isLinked ? new LinkedHashMap<>(initialCapacity) : new HashMap<>(initialCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,19 +504,19 @@ public class MapUtil {
|
|||||||
* @return entries
|
* @return entries
|
||||||
*/
|
*/
|
||||||
public static <K, V> Map<K, List<V>> grouping(Iterable<Map.Entry<K, V>> entries) {
|
public static <K, V> Map<K, List<V>> grouping(Iterable<Map.Entry<K, V>> entries) {
|
||||||
final Map<K, List<V>> map = new HashMap<>(DEFAULT_INITIAL_CAPACITY);
|
final Map<K, List<V>> map = new HashMap<>();
|
||||||
if (CollUtil.isEmpty(entries)) {
|
if (CollUtil.isEmpty(entries)) {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
for (Map.Entry<K, V> pair : entries) {
|
for (final Map.Entry<K, V> pair : entries) {
|
||||||
|
final List<V> values;
|
||||||
if (map.containsKey(pair.getKey())) {
|
if (map.containsKey(pair.getKey())) {
|
||||||
List<V> values = map.get(pair.getKey());
|
values = map.get(pair.getKey());
|
||||||
values.add(pair.getValue());
|
|
||||||
} else {
|
} else {
|
||||||
List<V> values = CollUtil.<V>newArrayList();
|
values = new ArrayList<>();
|
||||||
values.add(pair.getValue());
|
|
||||||
map.put(pair.getKey(), values);
|
map.put(pair.getKey(), values);
|
||||||
}
|
}
|
||||||
|
values.add(pair.getValue());
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user