All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.huanminabc.utils_common.base.ObjIsUtil Maven / Gradle / Ivy

There is a newer version: 1.0.5-RELEASE
Show newest version
package com.gitee.huanminabc.utils_common.base;

/**
 * Obj 相关判断工具
 *
 * @Author: huanmin
 * @Date: 2022/6/19 21:58
 * @Version: 1.0
 * @Description: 文件作用详细描述....
 */



import java.time.temporal.TemporalAccessor;
import java.util.Collection;
import java.util.Date;
import java.util.Map;

public class ObjIsUtil {

    //---------------------------------------------------------------------
    // 对象类型判断
    //---------------------------------------------------------------------

    public static boolean isCollection(Object obj) {
        return obj instanceof Collection;
    }

    public static boolean isMap(Object obj) {
        return obj instanceof Map;
    }

    public static boolean isNumber(Object obj) {
        return obj instanceof Number;
    }

    public static boolean isBoolean(Object obj) {
        return obj instanceof Boolean;
    }

    public static boolean isEnum(Object obj) {
        return obj instanceof Enum;
    }

    public static boolean isDate(Object obj) {
        return obj instanceof Date || obj instanceof TemporalAccessor;
    }

    public static boolean isCharSequence(Object obj) {
        return obj instanceof CharSequence;
    }

    /**
     * 判断对象是否为八大基本类型包装类除外即(boolean, byte, char, short, int, long, float, and double)
* * @param obj * @return */ public static boolean isPrimitive(Object obj) { return obj != null && obj.getClass().isPrimitive(); } /** * 判断对象是否为包装类或者非包装类的基本类型 * * @param obj * @return */ public static boolean isWrapperOrPrimitive(Object obj) { return isPrimitive(obj) || isNumber(obj) || isCharSequence(obj) || isBoolean(obj); } /** * 判断一个对象是否为数组 * * @param obj * @return */ public static boolean isArray(Object obj) { return obj != null && obj.getClass().isArray(); } /** * 判断一个对象是否为基本类型数组即(int[], long[], boolean[], double[]....) * * @param obj * @return */ public static boolean isPrimitiveArray(Object obj) { return isArray(obj) && obj.getClass().getComponentType().isPrimitive(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy