1
0
mirror of https://gitee.com/dromara/hutool.git synced 2025-04-05 17:37:59 +08:00

MapUtil增加根据entry分组

This commit is contained in:
Looly 2022-09-04 22:09:01 +08:00
parent 3965535a2d
commit 508c139b22
2 changed files with 8 additions and 7 deletions
CHANGELOG.md
hutool-core/src/main/java/cn/hutool/core/map

View File

@ -23,6 +23,7 @@
* 【extra 】 resource.loader等过期参数替换issue#2571@Github
* 【core 】 添加ObjectUtil的别名工具类ObjUtil
* 【core 】 扩展LocalDateTimeUtil.isIn方法使用场景pr#2589@Github
* 【core 】 MapUtil增加根据entry分组pr#2591@Github
*
### 🐞Bug修复
* 【http 】 修复https下可能的Patch、Get请求失效问题issue#I3Z3DH@Gitee

View File

@ -107,7 +107,7 @@ public class MapUtil {
* @since 3.0.4
*/
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);
}
@ -504,19 +504,19 @@ public class MapUtil {
* @return 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)) {
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())) {
List<V> values = map.get(pair.getKey());
values.add(pair.getValue());
values = map.get(pair.getKey());
} else {
List<V> values = CollUtil.<V>newArrayList();
values.add(pair.getValue());
values = new ArrayList<>();
map.put(pair.getKey(), values);
}
values.add(pair.getValue());
}
return map;
}