类库 package org.onepiece;import java.text.SimpleDateFormat;import java.util.Date;public class StaticClass{ public final static String EmptyString = ""; public final static String MD5 = "MD5"; public final static String SHA1 = "SHA1"; pub
package org.onepiece; import java.text.SimpleDateFormat; import java.util.Date; public class StaticClass { public final static String EmptyString = ""; public final static String MD5 = "MD5"; public final static String SHA1 = "SHA1"; public final static String SHA256 = "SHA256"; public final static String SHA384 = "SHA384"; public final static String SHA512 = "SHA512"; public final static String UTF8 = "UTF-8"; public final static String Unicode = "Unicode"; public final static String GB2312 = "GB2312"; public final static String ASCII = "ASCII"; public final static String GBK = "GBK"; public final static String yyyy_MM_dd_HH_mm_ss = "yyyy-MM-dd HH:mm:ss"; public final static String yyyy_MM_dd = "yyyy-MM-dd"; public final static String HH_mm_ss = "HH:mm:ss"; public final static int defaultInt = 0; public final static long defaultLong = 0L; public final static double defaultDouble = 0.0d; public final static String mySqlDriver = "com.mysql.jdbc.Driver"; public final static String mySqlURL = "jdbc:mysql://localhost:3306/"; public final static String WindowsNewLine = "\n"; public final static String NewLine = "\r\n"; //指示指定的字符串是 null 还是 Empty 字符串 public static boolean StringIsNullOrEmpty(String str) { if (str==null || str.isEmpty()) { return true; } return false; } //指示指定的字符串是 null、空还是仅由空白字符组成 public static boolean StringIsNullOrWhiteSpace(String str) { if (str==null || str.isEmpty()) { return true; } if (str.trim().length()==0) { return true; } return false; } public static String GetStringOrDefault(String str) { return GetStringOrDefault(str,""); } public static String GetStringOrDefault(String str, String defaultValue) { return StringIsNullOrWhiteSpace(str) ? defaultValue : str; } //比较字符串,忽略大小写 public static boolean StringCompare(String str1, String str2) { if(StringIsNullOrWhiteSpace(str1) || StringIsNullOrWhiteSpace(str2)) { return false;} return str1.equalsIgnoreCase(str2); } //比较字符串,忽略大小写(包括比较NULL值) public static boolean StringCompareIncludeNull(String str1, String str2) { return GetStringOrDefault(str1).equalsIgnoreCase(GetStringOrDefault(str2)); } /* String str = "13147306612"; String result = HideString(str,3,4); printIn(result); str = "445321198707051030"; result = HideString(str,3,4); printIn(result); */ public static String HideString(String str, int startShowCount, int endShowCount) throws Exception { return HideString(str, startShowCount, endShowCount, "*"); } public static String HideString(String str, int startShowCount, int endShowCount, String symbol) throws Exception { if (StringIsNullOrWhiteSpace(str) == false && str.length() > (startShowCount + endShowCount)) { StringBuilder builder = new StringBuilder(); builder.append(str.substring(0, startShowCount)); int count = str.length() - startShowCount - endShowCount; for (int i = 0; i < count; i++) { builder.append(symbol); //builder.Append("*"); } //builder.append(str.substring(str.length() - endShowCount, endShowCount)); //C# builder.append(str.substring(str.length()-endShowCount,str.length()));//从多少到多少 return builder.toString(); } return str; } public static String getDateTimeString(Date date, String format) { if(StringIsNullOrWhiteSpace(format)) { format="yyyy-MM-dd HH:mm:ss"; } SimpleDateFormat sdf = new SimpleDateFormat(format); String dtString = sdf.format(date); return dtString; } }