guohongjin
2024-05-15 5b7639f0bd9e056738ec15100ed0532e965c6cd5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cn.stylefeng.roses.kernel.rule.util;
 
import cn.hutool.core.util.ArrayUtil;
 
import java.util.Collection;
 
/**
 * 字段类型判断
 *
 * @author fengshuonan
 * @date 2022/9/7 10:24
 */
public class MixFieldTypeUtil {
 
    /**
     * 判断fieldValue是否是Long、List<Long>、Long[]类型,如果是其中任何一种,则都返回true
     *
     * @author fengshuonan
     * @date 2022/9/7 10:24
     */
    public static boolean whetherAssignClass(Object fieldValue, Class<?> clazz) {
 
        // 判断value是否是指定类型
        if (clazz.isAssignableFrom(fieldValue.getClass())) {
            return true;
        }
 
        // 如果是集合类型
        else if (fieldValue instanceof Collection) {
            Collection<?> collectionList = (Collection<?>) fieldValue;
            for (Object item : collectionList) {
                if (clazz.isAssignableFrom(item.getClass())) {
                    return true;
                }
            }
        }
 
        // 如果是数组类型
        else if (ArrayUtil.isArray(fieldValue)) {
            Object[] objects = ObjectConvertUtil.objToArray(fieldValue);
            for (Object item : objects) {
                if (clazz.isAssignableFrom(item.getClass())) {
                    return true;
                }
            }
        }
 
        return false;
    }
 
}