浏览代码

add min and max

Looly 6 年之前
父节点
当前提交
a9b08161c3

+ 1 - 0
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)

+ 26 - 0
hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java

@@ -2499,6 +2499,32 @@ public class CollUtil {
 
 		return values;
 	}
+	
+	/**
+	 * 取最大值
+	 * 
+	 * @param <T> 元素类型
+	 * @param coll 集合
+	 * @return 最大值
+	 * @since 4.6.5
+	 * @see Collections#max(Collection)
+	 */
+	public static <T extends Comparable<? super T>> T max(Collection<T> coll) {
+		return Collections.max(coll);
+	}
+	
+	/**
+	 * 取最大值
+	 * 
+	 * @param <T> 元素类型
+	 * @param coll 集合
+	 * @return 最大值
+	 * @since 4.6.5
+	 * @see Collections#min(Collection)
+	 */
+	public static <T extends Comparable<? super T>> T min(Collection<T> coll) {
+		return Collections.min(coll);
+	}
 
 	// ---------------------------------------------------------------------------------------------- Interface start
 	/**

+ 1 - 1
hutool-core/src/main/java/cn/hutool/core/map/TableMap.java

@@ -19,7 +19,7 @@ import cn.hutool.core.util.ArrayUtil;
  * @param <V>
  */
 public class TableMap<K, V> implements Map<K, V>, Serializable {
-	private static final long serialVersionUID = -5852304468076152385L;
+	private static final long serialVersionUID = 1L;
 
 	private List<K> keys;
 	private List<V> values;