package api.common.util; import java.util.*; public class CollectionUtil { //* -------------------------------- before jdk9 -------------------------------- public static List arrayToList(T[] array) { return Arrays.asList(array); } public static ArrayList createArrayList(T... elements) { return new ArrayList<>(Arrays.asList(elements)); } public static HashSet createHashSet(T... elements) { return new HashSet<>(Arrays.asList(elements)); } public static boolean isEmpty(Collection collection) { return collection == null || collection.isEmpty(); } public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); } public static boolean isNotEmpty(Collection collection) { return !isEmpty(collection); } public static boolean isNotEmpty(Map map) { return !isEmpty(map); } // //* -------------------------------- jdk9 -------------------------------- // // /** // * 根据数组或参数序列创建只读的 list // * // * @param elements 数组或参数序列 // * @param 元素类型 // * @return 只读 list // */ // @SafeVarargs // public static List createUnmodifiableList(T... elements) { // return List.of(elements); // } // // /** // * 根据 list 创建只读的 list // * // * @param list list // * @param 元素类型 // * @return 只读 list // */ // public static List createUnmodifiableList(List list) { // return Collections.unmodifiableList(list); // } // // /** // * 根据 set 创建只读的 set // * // * @param set set // * @param 元素类型 // * @return 只读 list // */ // public static Set createUnmodifiableList(Set set) { // return Collections.unmodifiableSet(set); // } // // // /** // * 根据 map 创建只读的 map // * // * @param map map // * @param 键类型 // * @param 值类型 // * @return 只读 map // */ // public static Map createUnmodifiableList(Map map) { // return Collections.unmodifiableMap(map); // } }