字符串和对象判空工具类

来源:互联网 发布:淘宝闲鱼怎么举报买家 编辑:程序博客网 时间:2024/05/29 17:42
/*        Copyright  DR.YangLong        Licensed under the Apache License, Version 2.0 (the "License");        you may not use this file except in compliance with the License.        You may obtain a copy of the License at        http://www.apache.org/licenses/LICENSE-2.0        Unless required by applicable law or agreed to in writing, software        distributed under the License is distributed on an "AS IS" BASIS,        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.        See the License for the specific language governing permissions and        limitations under the License.*/package com.quancai.erp.utils;/** * functional describe:字符串相关工具类 */public class StringUtilTools {    /**     * 判断字符串是不是NULL或是空字符串,如果是,返回true,不是false     *     * @param str 待判断字符串     * @return true/false     */    public static boolean isNullOrEmpty(final String str) {        return str == null || "".equals(str);    }    /**     * 判断字符串对象是不是NULL或空,如果是,返回true,不是false     * @param str 字符串对象     * @return true/false     */    public static boolean isNullOrEmpty(final Object str){        return str==null||"".equals(str.toString());    }    /**     * 对比2个对象的内容是否一致     * @param ob1 对象1     * @param ob2 对象2     * @return true/false     */    public static boolean equalObject(Object ob1,Object ob2){        return !(ob1==null||ob2==null)&&ob1.equals(ob2);    }    /**     * 对比2个String对象的内容是否一致,忽略大小写     * @param ob1 对象1     * @param ob2 对象2     * @return true/false     */    public static boolean equalStringObjectIgnoreCase(Object ob1,Object ob2){        return !(ob1==null||ob2==null)&&(ob1.toString().equalsIgnoreCase(ob2.toString()));    }    /**     *     * @param array 数组     * @param surffix 分割符号     * @return     */    public static String array2String(final String[] array,final String surffix){        StringBuilder builder=new StringBuilder();        for(int i=0;i<array.length;i++){            if(i==array.length-1){                builder.append(array[i]);            }            else {                builder.append(array[i]).append(surffix);            }        }        return builder.toString();    }    /**     * 调用对象的toString方法,返回对象的字符串,如果是NULL返回null字符串     * @param o 对象     * @return String     */    public static String wrapperNull(Object o){        if(o==null){            return "null";        }        return o.toString();    }}
0 0