import java.util.Map; /** * 非空驗證工具類 */ public class UntilEmpty { /** * @see: 驗證string類型的是否為空 */ public static boolean isNullorEmpty(String str) { //為了執行忽略大小寫的比較,可以調用equalsIgnoreCase( )方法。當比較兩個字符串時,它會認為A-Z和a-z是一樣的。 if ((str == null) || ("".equals(str)) || ("null".equalsIgnoreCase(str)) || ("undefined".equalsIgnoreCase(str))) { return true; } return false; } /** * @see: 驗證實體是否為空 */ public static <T> boolean isNullorEmpty(T entity) { if (entity == null) { return true; } else { return false; } } /** * @see: 驗證StringBuffer類型的是否為空 */ public static boolean isNullorEmpty(StringBuffer str) { if (str == null ||"".equals(str.toString()) || str.length() == 0) { return true; } else { return false; } } /** * @see: 驗證Map類型的是否為空 */ public static boolean isNullorEmpty(Map map) { if ((map == null) || (map.size() == 0)) { return true; } return false; } /** * @see: 驗證Object數組類型的是否為空 */ public static boolean isNullorEmpty(Object[] obj) { if ((obj == null) || (obj.length == 0)) { return true; } return false; } /** * @see: 驗證Long類型的是否為空 */ public static boolean isNullorEmpty(Long longTime) { if ((longTime == null) || (longTime.longValue() <= 0L)) { return true; } return false; } /** * @see: 驗證String數組類型的是否為空 */ public static boolean isNullorEmpty(String[] str) { if ((str == null) || (str.length == 0)) { return true; } return false; } }