1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package api.common.util;
- import java.util.*;
- public class CollectionUtil {
- public static <T> List<T> arrayToList(T[] array) {
- return Arrays.asList(array);
- }
- @SafeVarargs
- public static <T> ArrayList<T> createArrayList(T... elements) {
- return new ArrayList<>(Arrays.asList(elements));
- }
- @SafeVarargs
- public static <T> HashSet<T> createHashSet(T... elements) {
- return new HashSet<>(Arrays.asList(elements));
- }
- public static <T> Set<T> listToSet(List<T> list) {
- return new HashSet<>(list);
- }
- public static <T> List<T> setToList(Set<T> set) {
- return new ArrayList<>(set);
- }
- public static boolean isEmpty(Collection<?> collection) {
- return collection == null || collection.isEmpty();
- }
- public static boolean isEmpty(ArrayList<?> arrayList) {
- return arrayList == null || arrayList.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);
- }
- public static void addValueToMap(Map<String, Integer> map, int value, String key) {
- map.merge(key, value, Integer::sum);
- }
- }
|