工具类

本文详细介绍了AssertUtil工具类的功能和使用方法,包括检查数组、集合、映射和对象是否为空,比较两个列表是否相等,判断字符是否为数字,验证字符串是否全由数字组成,确保字符串长度不为零等。此工具类提供了丰富的断言方法,适用于多种数据类型和场景。
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package cn.com.do1.common.util;

import cn.com.do1.common.exception.BaseException;
import cn.com.do1.common.util.reflation.ClassType;
import cn.com.do1.common.util.reflation.ClassUtil;
import cn.com.do1.common.util.string.StringUtil;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class AssertUtil {
    public AssertUtil() {
    }

    public static <T> boolean isEmpty(T[] obj) {
        return obj == null || obj.length == 0;
    }

    public static boolean isEmpty(Object obj) {
        if (obj == null) {
            return true;
        } else {
            return obj instanceof String ? StringUtil.isNullEmpty((String)obj) : false;
        }
    }

    public static boolean compare(List<Comparable> l1, List<Comparable> l2) {
        if (l1 != null && !l1.isEmpty()) {
            if (l2 != null && !l2.isEmpty()) {
                Collections.sort(l1);
                Collections.sort(l2);
                if (l1.size() != l2.size()) {
                    return false;
                } else {
                    for(int i = 0; i < l1.size(); ++i) {
                        if (((Comparable)l1.get(i)).compareTo(l2.get(i)) != 0) {
                            return false;
                        }
                    }

                    return true;
                }
            } else {
                return false;
            }
        } else {
            return l2 == null || l2.isEmpty();
        }
    }

    public static boolean isEmpty(Collection obj) {
        return obj == null || obj.isEmpty();
    }

    public static boolean isEmpty(Map obj) {
        return obj == null || obj.isEmpty();
    }

    public static synchronized boolean objCobj(Object obj_1, Object obj_2) throws Exception {
        int n = 0;
        boolean flag = false;
        if (obj_1 == null) {
            return obj_2 == null;
        } else if (obj_2 == null) {
            return false;
        } else {
            Class obj1 = obj_1.getClass();
            Class obj2 = obj_2.getClass();
            if (obj1.equals(ClassType.stringType) && obj2.equals(ClassType.stringType)) {
                return obj_1.equals(obj_2);
            } else {
                Field[] obj1Fields = ClassUtil.getFields(obj1);
                Field[] obj2Fields = ClassUtil.getFields(obj2);
                if (obj1Fields.length != obj2Fields.length) {
                    return false;
                } else if (obj1Fields.length == 0 && obj1.equals(obj2)) {
                    return true;
                } else {
                    for(int i = 0; i < obj1Fields.length; ++i) {
                        Class obj1Type = obj1Fields[i].getType();
                        String obj1FieldName = obj1Fields[i].getName();

                        for(int j = 0; j < obj2Fields.length; ++j) {
                            Class obj2Type = obj2Fields[j].getType();
                            if (obj2Fields[j].getName().equals(obj1FieldName)) {
                                if (!obj1Type.equals(obj2Type)) {
                                    return false;
                                }

                                ++n;
                                Object tempobj2 = obj2Fields[j].get(obj_2);
                                Object tempobj1 = obj1Fields[i].get(obj_1);
                                if (!isEmpty(tempobj1)) {
                                    if (isEmpty(tempobj2)) {
                                        return false;
                                    }

                                    if (obj1Type.equals(ClassType.dateType)) {
                                        flag = tempobj1.toString().substring(0, 10).equals(tempobj2.toString().substring(0, 10));
                                    } else if (obj1Type.equals(ClassType.sqlTimeType)) {
                                        flag = tempobj1.toString().substring(0, 19).equals(tempobj2.toString().substring(0, 19));
                                    } else {
                                        flag = tempobj1.equals(tempobj2);
                                    }

                                    if (!flag) {
                                        return false;
                                    }
                                } else {
                                    if (!isEmpty(tempobj2)) {
                                        return false;
                                    }

                                    flag = true;
                                }
                            }
                        }
                    }

                    if (n != obj1Fields.length) {
                        return false;
                    } else {
                        return flag;
                    }
                }
            }
        }
    }

    public static boolean charIsNumb(int charValue) {
        return charValue >= 48 && charValue <= 57 || charValue >= 96 && charValue <= 105;
    }

    public static boolean objIsEmpty(Object obj) throws Exception {
        if (obj == null) {
            return true;
        } else {
            Field[] objFields = ClassUtil.getField(obj.getClass(), true);
            Field[] var5 = objFields;
            int var4 = objFields.length;

            for(int var3 = 0; var3 < var4; ++var3) {
                Field objField = var5[var3];
                if (!isEmpty(objField.get(obj))) {
                    return false;
                }
            }

            return true;
        }
    }

    public static boolean objIsEmptyEx(Object obj) {
        if (obj == null) {
            return true;
        } else {
            Field[] objFields = null;

            try {
                objFields = ClassUtil.getFields(obj.getClass());
            } catch (Exception var7) {
                return true;
            }

            if (isEmpty((Object[])objFields)) {
                return true;
            } else {
                Field[] var5 = objFields;
                int var4 = objFields.length;

                for(int var3 = 0; var3 < var4; ++var3) {
                    Field objField = var5[var3];
                    if (!Modifier.isFinal(objField.getModifiers())) {
                        try {
                            if (!isEmpty(objField.get(obj))) {
                                return false;
                            }
                        } catch (IllegalAccessException var6) {
                            return true;
                        }
                    }
                }

                return true;
            }
        }
    }

    public static boolean isFloat(String s) {
        return s.indexOf(".") > -1;
    }

    public static boolean shouldMor(String s) throws Exception {
        return shouldMor(s, 0);
    }

    public static boolean shouldMor(String s, int length) throws Exception {
        String[] temp = StringUtil.splitString(s, ".");
        switch(temp[1].charAt(length)) {
        case '0':
            return false;
        case '1':
            return false;
        case '2':
            return false;
        case '3':
            return false;
        case '4':
            return false;
        case '5':
            return true;
        case '6':
            return true;
        case '7':
            return true;
        case '8':
            return true;
        case '9':
            return true;
        default:
            throw new Exception("错误,小数点后非数字");
        }
    }

    public static boolean isNumb(String str) {
        if (isEmpty((Object)str)) {
            return false;
        } else {
            char[] chr = str.toCharArray();

            for(int i = 0; i < chr.length; ++i) {
                if (chr[i] < '0' || chr[i] > '9') {
                    return false;
                }
            }

            return true;
        }
    }

    public static boolean notNumb(String str) {
        if (isEmpty((Object)str)) {
            return true;
        } else {
            char[] chr = str.toCharArray();

            for(int i = 0; i < chr.length; ++i) {
                if (chr[i] < '0' || chr[i] > '9') {
                    return true;
                }
            }

            return false;
        }
    }

    public static void hasLength(String str, String msg) throws BaseException {
        if (str == null || str.length() < 1) {
            throw new BaseException(msg);
        }
    }

    public static boolean isAllEmpty(Object... obj) {
        Object[] var4 = obj;
        int var3 = obj.length;

        for(int var2 = 0; var2 < var3; ++var2) {
            Object o = var4[var2];
            if (!isEmpty(o)) {
                return false;
            }
        }

        return true;
    }

    public static boolean isAnyEmpty(Object... obj) {
        Object[] var4 = obj;
        int var3 = obj.length;

        for(int var2 = 0; var2 < var3; ++var2) {
            Object o = var4[var2];
            if (isEmpty(o)) {
                return true;
            }
        }

        return false;
    }

    public static boolean isAllNotEmpty(Object... obj) {
        Object[] var4 = obj;
        int var3 = obj.length;

        for(int var2 = 0; var2 < var3; ++var2) {
            Object o = var4[var2];
            if (isEmpty(o)) {
                return false;
            }
        }

        return true;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值