java工具类

来源:互联网 发布:多益网络java面试题 编辑:程序博客网 时间:2024/05/03 07:25
Also its good to know that, if you are overridding .equals () method, make sure you are overridding .hashcode () method, otherwise you will end up with violating equivalence relation b/w equals and hashcode// 最好借助于Apache 工具类防止 findBugs 检查出问题[看源码实现方式]import org.apache.commons.collections.CollectionUtils;import org.apache.commons.lang.StringUtils;import org.apache.commons.lang.time.DateUtils;public static boolean isBlank(String str){int strLen;if(str == null || (strLen = str.length()) == 0)return true;for(int i = 0; i < strLen; i++)if(!Character.isWhitespace(str.charAt(i)))return false;return true;}public static boolean equals(String str1, String str2){return str1 != null ? str1.equals(str2) : str2 == null;}public static boolean equalsIgnoreCase(String str1, String str2){return str1 != null ? str1.equalsIgnoreCase(str2) : str2 == null;}

package com.qingyaun.kehua.customization.util;import java.util.Collection;import java.util.Map;/** * Get utils from here listed: * @see http://commons.apache.org/downloads/index.html<Lang,Logging,Math,BeanUtils,etc.....> * @see http://www.java2s.com/Code/Jar/g/Downloadgson222jar.htm * @See org.apache.commons.collections.CollectionUtils; * @See org.apache.commons.lang.StringUtils; * @See org.apache.commons.lang.time.DateUtils; * @author: xiongqingyuan * @date 2014-6-20 *  if (NullCheckUtils.isNotNull(ds) && StringUtils.equals(ParamHandleUtil.FLAG, ds.getFlag())) *  { *     ds2List(list, ds);                 *  } */@SuppressWarnings("unchecked")public class NullCheckUtils{         public static boolean isNullOrEmpty(Collection collection)      {        return (null == collection || 0 == collection.size())? true: false;     }     public static boolean isNotNullAndEmpty(Collection collection)      {        return !isNullOrEmpty(collection);     }     public static boolean isNullOrEmpty(Map map)      {        return (null == map || 0 == map.size())? true: false;     }     public static boolean isNotNullAndEmpty(Map map)      {        return !isNullOrEmpty(map);     }     public static boolean isNullOrEmpty(Object[] objects)      {        return (null == objects || 0 == objects.length)? true: false;     }     public static boolean isNotNullAndEmpty(Object[] objects)      {        return !isNullOrEmpty(objects);     }     public static boolean isNull(Object object)      {        return (null == object)? true: false;     }     public static boolean isNotNull(Object Object)      {        return !isNull(Object);     }     public static boolean isNullOrEmpty(String subject)      {        return (null == subject || "".equals(subject))? true: false;     }     public static boolean isNotNullAndEmpty(String subject)      {        return !isNullOrEmpty(subject);     }     }

0 0
原创粉丝点击