package com.qianwen.core.tool.utils;
|
|
import java.lang.reflect.Array;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.Collection;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.Set;
|
import java.util.stream.Collectors;
|
import org.springframework.lang.Nullable;
|
import org.springframework.util.CollectionUtils;
|
|
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/utils/CollectionUtil.class */
|
public class CollectionUtil extends CollectionUtils {
|
public static boolean isNotEmpty(@Nullable Collection<?> collection) {
|
return !isEmpty(collection);
|
}
|
|
public static boolean isNotEmpty(@Nullable Map<?, ?> map) {
|
return !isEmpty(map);
|
}
|
|
public static <T> boolean contains(@Nullable T[] array, final T element) {
|
if (array == null) {
|
return false;
|
}
|
return Arrays.stream(array).anyMatch(x -> {
|
return ObjectUtil.nullSafeEquals(x, element);
|
});
|
}
|
|
public static String[] concat(String[] one, String[] other) {
|
return (String[]) concat(one, other, String.class);
|
}
|
|
public static <T> T[] concat(T[] one, T[] other, Class<T> clazz) {
|
T[] target = (T[]) ((Object[]) Array.newInstance((Class<?>) clazz, one.length + other.length));
|
System.arraycopy(one, 0, target, 0, one.length);
|
System.arraycopy(other, 0, target, one.length, other.length);
|
return target;
|
}
|
|
public static boolean isArray(Object obj) {
|
if (null == obj) {
|
return false;
|
}
|
return obj.getClass().isArray();
|
}
|
|
@SafeVarargs
|
public static <E> Set<E> ofImmutableSet(E... es) {
|
Objects.requireNonNull(es, "args es is null.");
|
return (Set) Arrays.stream(es).collect(Collectors.toSet());
|
}
|
|
@SafeVarargs
|
public static <E> List<E> ofImmutableList(E... es) {
|
Objects.requireNonNull(es, "args es is null.");
|
return (List) Arrays.stream(es).collect(Collectors.toList());
|
}
|
|
public static <E> List<E> toList(Iterable<E> elements) {
|
Objects.requireNonNull(elements, "elements es is null.");
|
if (elements instanceof Collection) {
|
return new ArrayList((Collection) elements);
|
}
|
List<E> list = new ArrayList<>();
|
for (E e : elements) {
|
list.add(e);
|
}
|
return list;
|
}
|
|
/* JADX WARN: Multi-variable type inference failed */
|
public static <K, V> Map<K, V> toMap(Object... keysValues) {
|
int kvLength = keysValues.length;
|
if (kvLength % 2 != 0) {
|
throw new IllegalArgumentException("wrong number of arguments for met, keysValues length can not be odd");
|
}
|
HashMap hashMap = new HashMap(kvLength);
|
for (int i = kvLength - 2; i >= 0; i -= 2) {
|
Object key = keysValues[i];
|
Object value = keysValues[i + 1];
|
hashMap.put(key, value);
|
}
|
return hashMap;
|
}
|
}
|