12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package api.common.util;
- import java.util.*;
- public class CollectionUtil {
- //* -------------------------------- before jdk9 --------------------------------
- public static <T> List<T> arrayToList(T[] array) {
- return Arrays.asList(array);
- }
- public static <T> ArrayList<T> createArrayList(T... elements) {
- return new ArrayList<>(Arrays.asList(elements));
- }
- public static <T> HashSet<T> 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 <T> 元素类型
- // * @return 只读 list
- // */
- // @SafeVarargs
- // public static <T> List<T> createUnmodifiableList(T... elements) {
- // return List.of(elements);
- // }
- //
- // /**
- // * 根据 list 创建只读的 list
- // *
- // * @param list list
- // * @param <E> 元素类型
- // * @return 只读 list
- // */
- // public static <E> List<E> createUnmodifiableList(List<E> list) {
- // return Collections.unmodifiableList(list);
- // }
- //
- // /**
- // * 根据 set 创建只读的 set
- // *
- // * @param set set
- // * @param <E> 元素类型
- // * @return 只读 list
- // */
- // public static <E> Set<E> createUnmodifiableList(Set<E> set) {
- // return Collections.unmodifiableSet(set);
- // }
- //
- //
- // /**
- // * 根据 map 创建只读的 map
- // *
- // * @param map map
- // * @param <K> 键类型
- // * @param <V> 值类型
- // * @return 只读 map
- // */
- // public static <K, V> Map<K, V> createUnmodifiableList(Map<K, V> map) {
- // return Collections.unmodifiableMap(map);
- // }
- }
|