001/*
002 *    Copyright 2024-2025, Warm-Flow (290631660@qq.com).
003 *
004 *    Licensed under the Apache License, Version 2.0 (the "License");
005 *    you may not use this file except in compliance with the License.
006 *    You may obtain a copy of the License at
007 *
008 *       https://www.apache.org/licenses/LICENSE-2.0
009 *
010 *    Unless required by applicable law or agreed to in writing, software
011 *    distributed under the License is distributed on an "AS IS" BASIS,
012 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *    See the License for the specific language governing permissions and
014 *    limitations under the License.
015 */
016package org.dromara.warm.flow.core.utils;
017
018/**
019 * 数组工具类
020 * @author warm
021 * @since 2023/5/18 9:45
022 */
023public class ArrayUtil {
024    /**
025     * * 判断一个对象数组是否为空
026     *
027     * @param objects 要判断的对象数组
028     *                * @return true:为空 false:非空
029     */
030    public static boolean isEmpty(Object[] objects) {
031        return ObjectUtil.isNull(objects) || (objects.length == 0);
032    }
033
034    /**
035     * * 判断一个对象数组是否非空
036     *
037     * @param objects 要判断的对象数组
038     * @return true:非空 false:空
039     */
040    public static boolean isNotEmpty(Object[] objects) {
041        return !isEmpty(objects);
042    }
043
044    /**
045     * 如果数组是空,则返回默认值
046     *
047     * @param objects    数组
048     * @param defaultArr 默认值
049     * @return 结果
050     */
051    public static <T> T[] emptyDefault(T[] objects, T[] defaultArr) {
052        return isEmpty(objects) ? defaultArr : objects;
053    }
054
055    /**
056     * * 判断一个对象是否是数组类型(Java基本型别的数组)
057     *
058     * @param object 对象
059     * @return true:是数组 false:不是数组
060     */
061    public static boolean isArray(Object object) {
062        return ObjectUtil.isNotNull(object) && object.getClass().isArray();
063    }
064
065    /**
066     * 字符串转数组
067     *
068     * @param str 字符串
069     * @param sep 分隔符
070     * @return
071     */
072    public static String[] strToArrAy(String str, String sep) {
073        return StringUtils.isEmpty(str) ? null : str.split(sep);
074    }
075}