1 package com.zhouyy.netBank.util; 2 3 import java.util.*; 4 5 /** 6 * 判断工具类 7 */ 8 public class EmptyUtils { 9 10 /** 11 * 如果字符串为空或空串返回 12 * 13 * @param str 14 * @return boolean 15 */ 16 public static boolean isBlank(String str) { 17 return StringUtils.isBlank(str); 18 } 19 20 /** 21 * 字符串不为空返回true 22 * 23 * @param str 24 * @return boolean 25 */ 26 public static boolean isNotEmpty(String str) { 27 return StringUtils.isNotEmpty(str); 28 } 29 30 /** 31 * 如果字符串为空返回 32 * 33 * @param str 34 * @return boolean 35 */ 36 public static boolean isEmpty(String str) { 37 return StringUtils.isEmpty(str); 38 } 39 40 /** 41 * 判断对象、String、Long、Integer 是否为空 42 * 43 * @param obj 44 * @return boolean 45 */ 46 public static boolean isEmpty(Object obj) { 47 return obj == null; 48 } 49 50 public static boolean isEmpty(Integer obj) { 51 return obj == null; 52 } 53 54 public static boolean isEmpty(Double obj) { 55 return obj == null; 56 } 57 58 public static boolean isEmpty(Float obj) { 59 return obj == null; 60 } 61 62 public static boolean isEmpty(Long obj) { 63 return obj == null; 64 } 65 66 public static boolean isEmpty(Byte obj) { 67 return obj == null; 68 } 69 70 public static boolean isEmpty(Date obj) { 71 return obj == null; 72 } 73 74 public static boolean isEmpty(Object[] obj) { 75 return null == obj || obj.length == 0; 76 } 77 78 79 /** 80 * 如果List为空返回 81 * 82 * @param result 83 * @return boolean 84 */ 85 public static boolean isEmptyList(List<?> result) { 86 return isEmpty(result); 87 } 88 89 /** 90 * 判断是否为数值类型 91 * 92 * @param str 93 * @return boolean 94 */ 95 public static boolean isNumeric(String str) { 96 try { 97 if(isBlank(str)){ 98 return false; 99 } 100 double a = Double.parseDouble(str); 101 return true; 102 } catch (NumberFormatException e) { 103 return false; 104 } 105 } 106 107 /** 108 * 判断数组是否为空 109 * 110 * @param obj 111 * @return boolean 112 */ 113 public static boolean isEmptyArray(Object[] obj) { 114 return isEmpty(obj); 115 } 116 117 /** 118 * 判断List、Map是否为空 119 * 120 * @param collection List、Map 121 * @return boolean 122 * @author zhouyy 123 */ 124 public static boolean isEmpty(Collection collection) { 125 return (collection == null || collection.isEmpty()); 126 } 127 128 /** 129 * 判断List、Map是否不为空 130 * 131 * @param collection List、Map 132 * @return boolean 133 * @author zhouyy 134 */ 135 public static boolean isNotEmpty(Collection collection) { 136 return !isEmpty(collection); 137 } 138 139 /** 140 * 如果字符串为空返回 141 * 142 * @param str 143 * @return boolean 144 */ 145 public static boolean isEmpty(StringBuilder str) { 146 return null == str || isBlank(str.toString()); 147 } 148 149 /** 150 * 删除List中重复元素 151 * 152 * @param list 153 */ 154 public static void removeDuplicate(List list) { 155 HashSet h = new HashSet(list); 156 list.clear(); 157 list.addAll(h); 158 } 159 160 /** 161 * 删除List中重复元素,保持顺序 162 * @param list 163 */ 164 public static void removeDuplicateWithOrder(List list) { 165 Set set = new HashSet(); 166 List newList = new ArrayList(); 167 for (Iterator iter = list.iterator(); iter.hasNext(); ) { 168 Object element = iter.next(); 169 if (set.add(element)) { 170 newList.add(element); 171 } 172 } 173 list.clear(); 174 list.addAll(newList); 175 } 176 }