1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package api.common.util;
- import java.util.*;
- public class CollectionUtil {
- public static <E> E[] createArray(E[] elements) {
- return elements;
- }
- public static int[] createIntArray(int... elements) {
- return elements;
- }
- 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 <E> String listToSequence(List<E> list) {
- StringBuilder stringBuilder = new StringBuilder();
- list.forEach(element -> stringBuilder.append(element).append(","));
- if (list.size() != 0) {
- stringBuilder.deleteCharAt(stringBuilder.length() - 1);
- }
- return stringBuilder.toString();
- }
- public static List<String> sequenceStringToList(String sequenceString, String regex) {
- return Arrays.asList(sequenceString.split(regex));
- }
- 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);
- }
- }
|