📄 basecommoncheck.java
字号:
package COMMON;
import java.math.BigDecimal;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
//update by YM
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
/**
* <DL>
* <DT><B>僋儔僗奣梫</B><DD>
*丂嫟捠僠僃僢僋娭悢<BR>
* <BR>
* 嬶懱揑側僼傽僀儖偺條幃偼壓婰偺捠傝<BR>
* <pre>
* ;<- comment
* ;
* </pre>
* </DD>
* </DL>
* <P></P>
* @author shaohua
* @version 1
*/
public class BaseCommonCheck {
public BaseCommonCheck() {
}
/**
* 僼傽僀儖偺僞僀僾丂傪庢摼
* @param fileName String
* @return String
*/
public static String getFileType(String fileName) {
String fileType = "";
if (fileName == null || fileName.trim().equals("")) {
return "";
}
int index = fileName.lastIndexOf(".");
if (index >= 0) {
fileType = fileName.substring(index + 1);
fileType = fileType.toLowerCase();
}
if (fileType.equals("xls")) {
fileType = "GBS_excel.GIF";
} else if (fileType.equals("doc")) {
fileType = "GBS_word.GIF";
} else if (fileType.equals("pdf")) {
fileType = "GBS_pdf.GIF";
} else if (fileType.equals("txt")) {
fileType = "GBS_text.GIF";
} else if (fileType.equals("ppt")) {
fileType = "GBS_ppt.GIF";
} else {
fileType = "GBS_other.GIF";
}
return fileType;
}
/**
* URL 僠僃僢僋
* @param url String
* @return boolean
*/
public static boolean isURL(String url) {
if (!url.startsWith("HTTP://") && !url.startsWith("http://")) {
return false;
}
url = url.substring(7);
if (url.startsWith(".")) {
return false;
}
if (url.endsWith(".")) {
return false;
}
// url = url.replace(".".charAt(0),"a".charAt(0));
return true;
}
/**
* convert Null String to "0"
* @param str String
* @return String
* @author gxk
*/
public static String convertNullToZero(String str) {
if (BaseCommonCheck.isEmpty(str)) {
return "0";
}
return str;
}
/**
* Convert Null string to space ""
* @param str String
* @return String isnot null
* @author gxk
*/
public static String convertNullToSpace(String str) {
if (str == null) {
return "";
}
return str;
}
/**
* <DL>
* <DT><b>儊僜僢僪奣梫丗</b><DD>
* 嬻偒暥帤楍僠僃僢僋<BR>
* </DD><BR>
* </DL>
* @param str 暥帤楍
* @return true:嬻偒丟false:嬻偒偱偼側偄
*/
public static boolean isEmpty(String str) {
if (str == null) {
return true;
}
if ("".equals(str.trim())) {
return true;
}
return false;
}
/**
* String[] 僠僃僢僋
* @param str String[]
* @return true:嬻偒丟false:嬻偒偱偼側偄
* @author gxk
*/
public static boolean isEmpty(String[] str) {
if (str == null) {
return true;
}
if (str.length == 0) {
return true;
}
return false;
}
/**
* <DL>
* <DT><b>儊僜僢僪奣梫丗</b><DD>
* 惍悢僠僃僢僋<BR>
* </DD><BR>
* </DL>
* @param str 暥帤楍
* @return true:惍悢丟false:惍悢偱偼側偄
*/
public static boolean isInteger(String str) {
if (str == null) {
return false;
}
try {
String strtmp = Integer.toString(Integer.parseInt(str.trim()));
while (strtmp.length() < str.length()) {
strtmp = "0" + strtmp;
}
if (!strtmp.equals(str)) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
/**
* <DL>
* <DT><b>儊僜僢僪奣梫丗</b><DD>
* 惍悢僠僃僢僋<BR>
* </DD><BR>
* </DL>
* @param str 暥帤楍
* @return true:惍悢丟false:惍悢偱偼側偄
*/
public static boolean isBigInteger(String str) {
if (str == null) {
return false;
}
try {
double dbl = new Double(str).doubleValue();
long lg = new BigDecimal(str).longValue();
if (dbl > lg) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
/**
* <DL>
* <DT><b>儊僜僢僪奣梫丗</b><DD>
* Float僠僃僢僋<BR>
* </DD><BR>
* </DL>
* @param str 暥帤楍
* @return true:float丟false:float偱偼側偄
*/
public static boolean isFloat(String str) {
if (str == null) {
return false;
}
try {
float value = Float.parseFloat(str.trim());
if (String.valueOf(value).equals("Infinity")) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
/**
* <DL>
* <DT><b>儊僜僢僪奣梫丗</b><DD>
* 暥帤楍僶僀僩悢傪庢摼<BR>
* </DD><BR>
* </DL>
* @param str 暥帤楍
* @return 奩摉暥帤楍偺僶僀僩悢
*/
public static int getLengthB(String str) {
if (str == null) {
return 0;
}
byte[] bytes = str.getBytes();
return bytes.length;
}
/**
* <DL>
* <DT><b>儊僜僢僪奣梫丗</b><DD>
* 僋儔儞僩抂偐傜僒僶抂偺暥帤偺曄峏<BR>
* </DD><BR>
* </DL>
* @param str 曄姺偝偣傞慜偺暥帤
* @return丂丂丂曄姺偝偣傞屻偺暥帤
*/
public static String isoToJIS(String str) {
if (isEmpty(str)) {
return str;
}
try {
str = new String(str.getBytes("iso-8859-1"), "Shift_JIS");
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
/**
* The method validate r_Value,
* if r_Value is email format return true ,else return false
* @param rValue
* @return boolean
*/
public static boolean isValidEmail(String str) {
//儊乕儖偺僼僅乕儅乕僩丗AAA@BBB.CC
if (null == str) {
return false;
}
//not exist @ or 俙晹暘偺length=0
if (str.indexOf("@") < 1) {
return false;
}
//Not exist . or B晹暘偺length=0
if (str.indexOf(".") < 1) {
return false;
}
if (str.endsWith(".")) {
return false;
}
if (str.substring(str.indexOf("@") + 1).startsWith(".")) {
return false;
}
// System.out.println("[DEBUG]CHECK MAIL " + str );
str = str.replace("-".charAt(0), "a".charAt(0));
str = str.replace("_".charAt(0), "a".charAt(0));
str = str.replace(".".charAt(0), "a".charAt(0));
// System.out.println("[DEBUG]CHECK MAIL " + str );
if (!BaseCommonCheck.isDigitandAlphabetHalfWidth(str.substring(0, str.indexOf("@")))) {
return false;
}
if (!BaseCommonCheck.isDigitandAlphabetHalfWidth(str.substring(str.indexOf("@") + 1))) {
return false;
}
return true;
}
/**
* 婰崋(敿妏)偐偳偆偐傪敾抐偡傞儊僜僢僪丅
*
* @param character 暥帤
* @return true - 婰崋(敿妏)偺応崌丄false - 婰崋(敿妏)偱側偄応崌
*/
public static boolean isCodeHalfWidthForm(char character) {
if (Character.UnicodeBlock.of(character).equals(Character.UnicodeBlock.BASIC_LATIN)
&& !Character.isLetterOrDigit(character)) {
return true;
}
return false;
}
public static boolean isDigitAndAlphabetAndCodeHalfWidth(String str) {
char[] t_StringChar = str.toCharArray();
for (int i = 0; i < t_StringChar.length; i++) {
if (!BaseCommonCheck.isDigitHalfWidthForm(t_StringChar[i])
&& !BaseCommonCheck.isAlphabetHalfWidthForm(t_StringChar[i])
&& !(BaseCommonCheck.isCodeHalfWidthForm(t_StringChar[i]))) {
return false;
}
}
return true;
}
/**
* Validate r_String which include only digital half width
* @param r_String
* @return boolean
*/
public static boolean isDigit(String r_String) {
char[] t_StringChar = r_String.toCharArray();
for (int i = 0; i < t_StringChar.length; i++) {
if (!BaseCommonCheck.isDigitHalfWidthForm(t_StringChar[i])) {
return false;
}
}
return true;
}
/**
* Validate char if is half width digital
* @param character
* @return boolean
*/
public static boolean isDigitHalfWidthForm(char character) {
if (Character.UnicodeBlock.of(character).equals(Character.UnicodeBlock.BASIC_LATIN)
&& Character.isDigit(character)) {
return true;
}
return false;
}
/**
* 塸暥帤(敿妏)偐偳偆偐傪敾抐偡傞儊僜僢僪丅
*
* @param character 暥帤
* @return true - 塸暥帤(敿妏)偺応崌丄false - 塸暥帤(敿妏)偱側偄応崌
*/
public static boolean isAlphabetHalfWidthForm(char character) {
if (Character.UnicodeBlock.of(character).equals(Character.UnicodeBlock.BASIC_LATIN)
&& (Character.isUpperCase(character) || Character.isLowerCase(character))) {
return true;
}
return false;
}
/**
* 塸暥帤(敿妏)偐偳偆偐傪敾抐偡傞儊僜僢僪丅
*
* @param r_String
* @return true - 塸暥帤(敿妏)偺応崌丄false - 塸暥帤(敿妏)偱側偄応崌
*/
public static boolean isAlphabet(String r_String) {
char[] t_StringChar = r_String.toCharArray();
for (int i = 0; i < t_StringChar.length; i++) {
if (!BaseCommonCheck.isAlphabetHalfWidthForm(t_StringChar[i])) {
return false;
}
}
return true;
}
/**
* 娍帤(慡妏)偐偳偆偐傪敾抐偡傞儊僜僢僪丅
*
* @param character 暥帤
* @return boolean
*/
public static boolean isKanjiFullWidthForm(char character) {
if (Character.UnicodeBlock.of(character).equals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS)) {
return true;
}
return false;
}
/**
* 僇僞僇僫(慡妏)偐偳偆偐傪敾抐偡傞儊僜僢僪丅
*
* @param character
* @return boolean
*/
public static boolean isKatakanaFullWidthForm(char character) {
if (Character.UnicodeBlock.of(character).equals(Character.UnicodeBlock.KATAKANA)) {
return true;
}
return false;
}
/**
* 傂傜偑側(慡妏)偐偳偆偐傪敾抐偡傞儊僜僢僪丅
*
* @param character 暥帤
* @return true - 傂傜偑側(慡妏)偺応崌丄false - 傂傜偑側(慡妏)偱側偄応崌
*/
public static boolean isHiraganaFullWidthForm(char character) {
if (Character.UnicodeBlock.of(character).equals(Character.UnicodeBlock.HIRAGANA)) {
return true;
}
return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -