From a9b08161c3020f3086d34d00aec4c843252e5383 Mon Sep 17 00:00:00 2001 From: Looly Date: Wed, 11 Sep 2019 16:28:34 +0800 Subject: [PATCH] add min and max --- CHANGELOG.md | 1 + .../cn/hutool/core/collection/CollUtil.java | 26 +++++++++++++++++++ .../java/cn/hutool/core/map/TableMap.java | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5efe4df3c..010dd6f5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ * 【setting】 SettingLoader支持自定义分隔符 * 【http】 Content-Type添加默认值(issue#I11YHI@Gitee) * 【socket】 增加Closeable接口(issue#532@Github) +* 【core】 CollUtil增加min和max方法 ### Bug修复 * 【core】 修复NetUtil.getUsableLocalPort问题(pr#69@Gitee) diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java index 2e0d91a57..a4334fd5c 100644 --- a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java @@ -2499,6 +2499,32 @@ public class CollUtil { return values; } + + /** + * 取最大值 + * + * @param 元素类型 + * @param coll 集合 + * @return 最大值 + * @since 4.6.5 + * @see Collections#max(Collection) + */ + public static > T max(Collection coll) { + return Collections.max(coll); + } + + /** + * 取最大值 + * + * @param 元素类型 + * @param coll 集合 + * @return 最大值 + * @since 4.6.5 + * @see Collections#min(Collection) + */ + public static > T min(Collection coll) { + return Collections.min(coll); + } // ---------------------------------------------------------------------------------------------- Interface start /** diff --git a/hutool-core/src/main/java/cn/hutool/core/map/TableMap.java b/hutool-core/src/main/java/cn/hutool/core/map/TableMap.java index d2d0eb588..e25a24716 100644 --- a/hutool-core/src/main/java/cn/hutool/core/map/TableMap.java +++ b/hutool-core/src/main/java/cn/hutool/core/map/TableMap.java @@ -19,7 +19,7 @@ import cn.hutool.core.util.ArrayUtil; * @param */ public class TableMap implements Map, Serializable { - private static final long serialVersionUID = -5852304468076152385L; + private static final long serialVersionUID = 1L; private List keys; private List values;