package redwrench.manong.com.redwrench.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CheckUtil {
/**
* 判断数组是否为空
* S2T3Fo4
* @paramr
* @return true 为空 false 不为空
*/
public static boolean IsEmpty(Object[] ObjIn) {
return (ObjIn == null || ObjIn.length == 0);
}
//
// /**
// * 判断一个字符串是否为空
// *
// * @param str
// * @return
// */
// public static boolean IsEmpty(String str) {
// return (str == null || str.length() == 0);
// }
/**
* 判断一个字符串 是否null,且内容不为null,"" ," "等
*
* @param str
* @return
*/
public static boolean IsEmpty(String str) {
return (str == null || str.trim().length() == 0 || str.trim().equalsIgnoreCase("null"));
}
/**
* 验证一个对象是否为空
*
* @param o
* @return
*/
public static boolean IsEmpty(Object o) {
return (o == null);
}
/**
* 判断数组是否为空
*
* @param
* @return true 为空 false 不为空
*/
@SuppressWarnings("rawtypes")
public static boolean IsEmpty(Collection colIn) {
return (colIn == null || colIn.isEmpty());
}
/**
* 判断Map是否为空
*
* @param
* @return true 为空 false 不为空
*/
@SuppressWarnings("rawtypes")
public static boolean IsEmpty(Map mapIn) {
return (mapIn == null || mapIn.isEmpty());
}
public static boolean IsEmpty(@SuppressWarnings("rawtypes") List list) {
return (list == null || list.isEmpty());
}
/**
* 判断字符串是否为空或者null
*
* @param strParam
* 验证参数
* @return 为空或null时返回True
*/
public static boolean isBlankOrNull(String strParam) {
return (strParam == null) || (strParam.trim().length() == 0);
}
/**
* 判断是否为整数
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isInteger(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^-?\\d+$");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为(非零的)正整数
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isPosInteger(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^\\+?[1-9][0-9]*$");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为(非零的)负整数
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isNegInteger(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^\\-[1-9][0-9]*$");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为非负整数(正整数 + 0)
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isNonNegInteger(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^\\d+$");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为非正整数(负整数 + 0)
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isNonPosInteger(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^((-\\d+)|(0+))$");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为浮点数
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isFloat(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^(-?\\d+)(\\.\\d+)?");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为非负浮点数(正浮点数 + 0)
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isNonNegFloat(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^\\d+(\\.\\d+)?$");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为正浮点数
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isPosFloat(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为非正浮点数(负浮点数 + 0)
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isNonPosFloat(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为负浮点数
*
* @param strNum
* 待查字符串
* @return 是则返回true
*/
public static boolean isNegFloat(String strNum) {
// 空串不为数字
if (null == strNum || "".equals(strNum))
return false;
Pattern pattern = Pattern.compile("^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$");
Matcher isNum = pattern.matcher(strNum);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 判断是否为数值 包含 正负号和小数点
*
* @param str
* @return
*/
public static boolean isNumeric(String str) {
char c;
int pointNum = 0;
for (int i = str.length(); --i >= 0;) {
c = str.charAt(i);
// 是否为数字
if ((c <= 0x0039 && c >= 0x0030) == false)
// 是否为小数点
if (c == 0x002e) {
// 是否只有一个小数点
if (pointNum == 0) {
pointNum++;
} else {
// 超过一个小数点时出错
return false;
}
} else {
// 是否为减号或加号且在最开头
if (c != 0x002d && c != 0x002b || i != 0) {
// 都不是时出错
return false;
}
}
}
return true;
}
/**
* 判断是否为日期
*
* @param strDate
* 需要解析的日期字符串
* @return 合法日期返回true
*/
public static boolean isDate(String strDate) {
if (null