From 012235d05d8dc7c2decdc7229d93033b0399ecbb Mon Sep 17 00:00:00 2001
From: xiejun <xiejun@vci-tech.com>
Date: 星期日, 10 十一月 2024 15:49:53 +0800
Subject: [PATCH] 集成获取mdm分发通用数据格式接口集成
---
Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/CollectionUtil.java | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 177 insertions(+), 0 deletions(-)
diff --git a/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/CollectionUtil.java b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/CollectionUtil.java
new file mode 100644
index 0000000..e678bbb
--- /dev/null
+++ b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/CollectionUtil.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2018-2028, DreamLu All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the dreamlu.net developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: DreamLu 鍗㈡槬姊� (596392912@qq.com)
+ */
+package org.springblade.core.tool.utils;
+
+import org.springframework.lang.Nullable;
+import org.springframework.util.CollectionUtils;
+
+import java.lang.reflect.Array;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 闆嗗悎宸ュ叿绫�
+ *
+ * @author L.cm
+ */
+public class CollectionUtil extends CollectionUtils {
+
+ /**
+ * Return {@code true} if the supplied Collection is not {@code null} or empty.
+ * Otherwise, return {@code false}.
+ *
+ * @param collection the Collection to check
+ * @return whether the given Collection is not empty
+ */
+ public static boolean isNotEmpty(@Nullable Collection<?> collection) {
+ return !CollectionUtil.isEmpty(collection);
+ }
+
+ /**
+ * Return {@code true} if the supplied Map is not {@code null} or empty.
+ * Otherwise, return {@code false}.
+ *
+ * @param map the Map to check
+ * @return whether the given Map is not empty
+ */
+ public static boolean isNotEmpty(@Nullable Map<?, ?> map) {
+ return !CollectionUtil.isEmpty(map);
+ }
+
+ /**
+ * Check whether the given Array contains the given element.
+ *
+ * @param array the Array to check
+ * @param element the element to look for
+ * @param <T> The generic tag
+ * @return {@code true} if found, {@code false} else
+ */
+ public static <T> boolean contains(@Nullable T[] array, final T element) {
+ if (array == null) {
+ return false;
+ }
+ return Arrays.stream(array).anyMatch(x -> ObjectUtil.nullSafeEquals(x, element));
+ }
+
+ /**
+ * Concatenates 2 arrays
+ *
+ * @param one 鏁扮粍1
+ * @param other 鏁扮粍2
+ * @return 鏂版暟缁�
+ */
+ public static String[] concat(String[] one, String[] other) {
+ return concat(one, other, String.class);
+ }
+
+ /**
+ * Concatenates 2 arrays
+ *
+ * @param one 鏁扮粍1
+ * @param other 鏁扮粍2
+ * @param clazz 鏁扮粍绫�
+ * @return 鏂版暟缁�
+ */
+ public static <T> T[] concat(T[] one, T[] other, Class<T> clazz) {
+ T[] target = (T[]) Array.newInstance(clazz, one.length + other.length);
+ System.arraycopy(one, 0, target, 0, one.length);
+ System.arraycopy(other, 0, target, one.length, other.length);
+ return target;
+ }
+
+ /**
+ * 瀵硅薄鏄惁涓烘暟缁勫璞�
+ *
+ * @param obj 瀵硅薄
+ * @return 鏄惁涓烘暟缁勫璞★紝濡傛灉涓簕@code null} 杩斿洖false
+ */
+ public static boolean isArray(Object obj) {
+ if (null == obj) {
+ return false;
+ }
+ return obj.getClass().isArray();
+ }
+
+ /**
+ * 涓嶅彲鍙� Set
+ *
+ * @param es 瀵硅薄
+ * @param <E> 娉涘瀷
+ * @return 闆嗗悎
+ */
+ @SafeVarargs
+ public static <E> Set<E> ofImmutableSet(E... es) {
+ Objects.requireNonNull(es, "args es is null.");
+ return Arrays.stream(es).collect(Collectors.toSet());
+ }
+
+ /**
+ * 涓嶅彲鍙� List
+ *
+ * @param es 瀵硅薄
+ * @param <E> 娉涘瀷
+ * @return 闆嗗悎
+ */
+ @SafeVarargs
+ public static <E> List<E> ofImmutableList(E... es) {
+ Objects.requireNonNull(es, "args es is null.");
+ return Arrays.stream(es).collect(Collectors.toList());
+ }
+
+ /**
+ * Iterable 杞崲涓篖ist闆嗗悎
+ *
+ * @param elements Iterable
+ * @param <E> 娉涘瀷
+ * @return 闆嗗悎
+ */
+ 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);
+ }
+ Iterator<E> iterator = elements.iterator();
+ List<E> list = new ArrayList<>();
+ while (iterator.hasNext()) {
+ list.add(iterator.next());
+ }
+ return list;
+ }
+
+ /**
+ * 灏唊ey value 鏁扮粍杞负 map
+ *
+ * @param keysValues key value 鏁扮粍
+ * @param <K> key
+ * @param <V> value
+ * @return map 闆嗗悎
+ */
+ 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");
+ }
+ Map<K, V> keyValueMap = new HashMap<>(kvLength);
+ for (int i = kvLength - 2; i >= 0; i -= 2) {
+ Object key = keysValues[i];
+ Object value = keysValues[i + 1];
+ keyValueMap.put((K) key, (V) value);
+ }
+ return keyValueMap;
+ }
+
+}
--
Gitblit v1.9.3