/*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package com.suning.commerce.order.util;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
/**
* @author nicholas tse
*
*/
public class StringUtil {
private static final String CLASS_NAME = StringUtil.class.getName();
private static final Logger LOGGER = LoggingHelper.getLogger(StringUtil.class);
public static BigDecimal mul(BigDecimal v1, BigDecimal v2) {
BigDecimal b1 = new BigDecimal(Double.toString(v1.doubleValue()));
BigDecimal b2 = new BigDecimal(Double.toString(v2.doubleValue()));
return b1.multiply(b2);
}
public static String gbkToAscii(String s) {
String methodName = "gbkToAscii";
if (s == null)
return "";
try {
s = new String(s.getBytes("GBK"), "iso8859-1");
} catch (Exception e) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, e.getMessage(), e);
}
return s;
}
public static String asciiToGbk(String s) {
String methodName = "asciiToGbk";
if (s == null)
return null;
try {
s = new String(s.getBytes("iso8859-1"), "GBK");
} catch (Exception e) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, e.getMessage(), e);
return null;
}
return s;
}
public static String getDouble2String(double s) {
DecimalFormat df = new DecimalFormat("0.##");
return df.format(s) + "%";
}
public static String[] parseStringToArray(String s, String delim) {
StringTokenizer st = new StringTokenizer(s, delim);
List v = new ArrayList();
while (st.hasMoreElements()) {
String tmp = st.nextToken();
v.add(tmp);
}
return (String[]) v.toArray(new String[v.size()]);
}
public static String[] parseStringToArray2(String s, String delim) {
List v = new ArrayList();
int startIdx = 0;
if (s != null && !s.equals("")) {
while (s.indexOf(delim) != -1) {
int idx = s.indexOf(delim);
v.add(s.substring(0, idx).trim());
startIdx += idx + delim.length();
s = s.substring(startIdx);
startIdx = 0;
}
}
v.add((s != null) ? s.trim() : "");
return (String[]) v.toArray(new String[v.size()]);
}
public static String replaceNonDigiCharToZero(String s) {
if (s == null || s.equals("")) {
return "0";
}
for (int ii = 0; ii < s.length(); ii++) {
if (!Character.isDigit(s.charAt(ii))) {
s = s.replace(s.charAt(ii), '0');
}
}
return s;
}
/**
* replace all the targets with patterns
*
* @param s
* @param target
* @param pattern
* @return
*/
public static String replace(String s, String target, String pattern) {
while (s.indexOf(target) != -1) {
int i = s.indexOf(target);
s = s.substring(0, i) + pattern + s.substring(i + target.length());
}
return s;
}
public String isNull(Object obj) {
return obj == null ? "" : obj.toString();
}
private static final char zeroArray[] = "0000000000000000000000000000000000000000000000000000000000000000".toCharArray();
public static String[] splitStr(String sStr, String sSplitter) {
if (sStr == null || sStr.length() <= 0 || sSplitter == null || sSplitter.length() <= 0)
return null;
String[] saRet = null;
int iLen = sSplitter.length();
int[] iIndex = new int[sStr.length()];
iIndex[0] = sStr.indexOf(sSplitter, 0);
if (iIndex[0] == -1) {
saRet = new String[1];
saRet[0] = sStr;
return saRet;
}
int iIndexNum = 1;
while (true) {
iIndex[iIndexNum] = sStr.indexOf(sSplitter, iIndex[iIndexNum - 1] + iLen);
if (iIndex[iIndexNum] == -1)
break;
iIndexNum++;
}
Vector vStore = new Vector();
int i = 0;
String sub = null;
for (i = 0; i < iIndexNum + 1; i++) {
if (i == 0)
sub = sStr.substring(0, iIndex[0]);
else if (i == iIndexNum)
sub = sStr.substring(iIndex[i - 1] + iLen, sStr.length());
else
sub = sStr.substring(iIndex[i - 1] + iLen, iIndex[i]);
if (sub != null && sub.length() > 0)
vStore.add(sub);
}
if (vStore.size() <= 0)
return null;
saRet = new String[vStore.size()];
Enumeration e = vStore.elements();
for (i = 0; e.hasMoreElements(); i++)
saRet[i] = (String) e.nextElement();
return saRet;
}
public static boolean isNum(String str) {
if (str == null || str.length() <= 0)
return false;
char[] ch = str.toCharArray();
for (int i = 0; i < str.length(); i++)
if (!Character.isDigit(ch[i]))
return false;
return true;
}
public static String symbol(String value) {
String val = "";
if (value != null) {
val = value;
}
val = replaceStrEx(val, "'", "’");
val = replaceStrEx(val, ",", ",");
val = replaceStrEx(val, "\"", "“");
// val = replaceStrEx(val,"\"","“");
return val;
}
public static String replaceStrEx(String sReplace, String sOld, String sNew) {
if (sReplace == null || sOld == null || sNew == null)
return null;
int iLen = sReplace.length();
int iLenOldStr = sOld.length();
int iLenNewStr = sNew.length();
if (iLen <= 0 || iLenOldStr <= 0 || iLenNewStr < 0)
return sReplace;
int[] iIndex = new int[iLen];
iIndex[0] = sReplace.indexOf(sOld, 0);
if (iIndex[0] == -1)
return sReplace;
int iIndexNum = 1;
while (true) {
iIndex[iIndexNum] = sReplace.indexOf(sOld, iIndex[iIndexNum - 1] + 1);
if (iIndex[iIndexNum] == -1)
break;
iIndexNum++;
}
Vector vStore = new Vector();
String sub = sReplace.substring(0, iIndex[0]);
if (sub != null)
vStore.add(sub);
int i = 1;
for (i = 1; i < iIndexNum; i++) {
vStore.add(sReplace.substring(iIndex[i - 1] + iLenOldStr, iIndex[i]));
}
vStore.add(sReplace.substring(iIndex[i - 1] + iLenOldStr, iLen));
StringBuffer sbReplaced = new StringBuffer("");
for (i = 0; i < iIndexNum; i++) {
sbReplaced.append(vStore.get(i) + sNew);
}
sbReplaced.append(vStore.get(i));
return sbReplaced.toString();
}
public static String replaceStr(String sReplace, String sOld, String sNew) {
if (sReplace == null || sOld == null || sNew == null)
return null;
int iLen = sReplace.length();
int iLenOldStr = sOld.length();
int iLenNewStr = sNew.length();
if (iLen <= 0 || iLenOldStr <= 0 || iLenNewStr < 0)
return sReplace;
int iIndex = -1;
iIndex = sReplace.indexOf(sOld, 0);
if (iIndex == -1)
return sReplace;
String sub = sReplace.substring(0, iIndex);
StringBuffer sbReplaced = new StringBuffer("");
sbReplaced.append(sub + sNew);
sbReplaced.append(sReplace.substring(iIndex + iLenOldStr, iLen));
return sbReplaced.toString();
}
public static String cvtTOgbk(String encoding, String string) {
String methodName = "cvtTOgbk";
if (string == null) {
return "";
}
try {
return new String(string.getBytes(encoding), "GBK");
} catch (UnsupportedEncodingException e) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, e.getMessage(), e);
return string;
}
}
public static String cvtTOgbk(String str) {
String methodName = "cvtTOgbk";
if (str == null)
return "";
try {
return new String(str.getBytes("iso-8859-1"), "GBK");
} catch (java.io.UnsupportedEncodingException un) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, un.getMessage(), un);
return str;
}
}
public static String cvtTOiso(String str) {
String methodName = "cvtTOiso";
if (str == null)
return "";
try {
return new String(str.getBytes("GBK"), "iso-8859-1");
} catch (java.io.UnsupportedEncodingException un) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, un.getMessage(), un);
return str;
}
}
public static String cvtToUTF8(String str) {
String methodName = "cvtToUTF8";
if (str == null)
return "";
try {
return new String(str.getBytes("iso-8859-1"), "GBK");
} catch (java.io.UnsupportedEncodingException un) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, un.getMessage(), un);
return str;
}
}
public static int toInteger(String integer) {
return toInteger(integer, 0);
}
public static int toInteger(String integer, int def) {
int ret = 0;
try {
ret = Integer.parseInt(integer);
} catch (NumberFormatException nfx) {
ret = def;
}
return ret;
}
public static long toLong(String longStr) {
return toLong(longStr, 0);
}
public static long toLong(String longStr, long def) {
long ret = 0;
try {
ret = Long.parseLong(longStr);
} catch (NumberFormatException nfx) {
ret = def;
}
return ret;
}
public static double toDouble(String doubleStr) {
return toDouble(doubleStr, 0.0);
}
public static double toDouble(String doubleStr, double def) {
double ret = 0.0;
try {
ret = Double.parseDouble(doubleStr);
} catch (NumberFormatException nfx) {
ret = def;
}
return ret;
}
public static Timestamp convertStringToTimeStamp(String str) {
String methodName = "convertStringToTimeStamp";
if (str == null || "".equals(str)) {
str = "2008/08/08 15:32:51";
}
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
try {
date = df.parse(str);
} catch (ParseException e) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, e.getMessage(), e);
}
Timestamp registerDate = new Timestamp(date.getTime());
return registerDate;
}
public static Timestamp convertStringToTimeStamp2(String str) {
String methodName = "convertStringToTimeStamp2";
if (str == null || "".equals(str)) {
str = "2008-08-08 15:32:51";
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
try {
date = df.parse(str);
} catch (ParseException e) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, e.getMessage(), e);
}
Timestamp registerDate = new Timestamp(date.getTime());
return registerDate;
}
public static String convertStringToTimeStamp3(String str) {
String methodName = "convertStringToTimeStamp3";
if (str == null || "".equals(str)) {
str = "2008-08-08 15:32:51";
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
String returnValue = "";
Date date = null;
try {
date = df.parse(str);
returnValue = df1.format(date);
} catch (ParseException e) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, e.getMessage(), e);
}
return returnValue;
}
public static String contactStr(String[] saStr, String sContacter) {
if (saStr == null || saStr.length <= 0 || sContacter == null || sContacter.length() <= 0)
return null;
StringBuffer sRet = new StringBuffer("");
for (int i = 0; i < saStr.length; i++) {
if (i == saStr.length - 1)
sRet.append(saStr[i]);
else
sRet.append(saStr[i] + sContacter);
}
return sRet.toString();
}
public static String contactStr(String[] saStr, String sContacter, String str) {
if (saStr == null || saStr.length <= 0 || sContacter == null || sContacter.length() <= 0)
return null;
StringBuffer sRet = new StringBuffer("");
for (int i = 0; i < saStr.length; i++) {
if (i == saStr.length - 1)
sRet.append(str + saStr[i] + str);
else
sRet.append(str + saStr[i] + str + sContacter);
}
return sRet.toString();
}
public static boolean validHomepage(String homepage) {
if (homepage == null)
return false;
if (homepage.length() == 0)
return false;
if (homepage.length() > 7) {
if (homepage.toLowerCase().indexOf("http://") == 0 && homepage.indexOf(".") > 0)
return false;
else
return true;
} else {
if (homepage.length() == 7 && homepage.toLowerCase().indexOf("http://") == 0)
return false;
else
return true;
}
}
public static boolean isEmailUrl(String str) {
if ((str == null) || (str.length() == 0))
return false;
if ((str.indexOf('@') > 0) && (str.indexOf('@') == str.lastIndexOf('@'))) {
if ((str.indexOf('.') > 0) && (str.lastIndexOf('.') > str.indexOf('@'))) {
return true;
}
}
return false;
}
public static String cvtTOgb2312(String str) {
String methodName = "cvtTOgb2312";
if (str == null)
return "";
try {
return new String(str.getBytes("iso-8859-1"), "gb2312");
} catch (java.io.UnsupportedEncodingException un) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, methodName, un.getMessage(), un);
return str;
}
}
public static String chkNull(String str) {
if (str == null)
return "未知";
else
return str;
}
public static String chkNullBlank(String str) {
if (str == null)
return "";
else if (str.trim().equals("null"))
return "";
else
return str.trim();
}
public static String chkNullBlankS(String str) {
if (str == null) {
return "0";
} else if (str.trim().equals("null")) {
return "0";
} else if (str.trim().equals("")) {
return "0";
} else {
return str.trim();
}
}
public static String chkNullBlankS1(String str) {
if (str == null) {
return "s";
} else if (str.trim().equals("null")) {
return "s";
} else if (str.trim().equals("")) {
return "s";
} else {
return str.trim();
}
}
public static String chkNullDate(Date date) {
if (date == null)
return "";
else {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return df.format(date);
}
}
public static String chkNullBlank(Object object) {
if (object != null)
return chkNullBlank(object.toString());
else
return "";
}
public static String[] checkBox(String[] source, String[] pos) {
if (source == null || pos == null || source.length < pos.length)
return null;
String[] res = new String[pos.length];
for (int i = 0; i < pos.length; i++) {
res[i] = source[Integer.parseInt(pos[i])];
}
return res;
}
public static String randomString(int len) {
String asctbl = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_";
String str = "";
for (int i = 0; i < len; i++) {
int offset = (int) Math.round(Math.random() * (asctbl.length() - 1));
str += asctbl.substring(offset, offset + 1);
}
return str;
}
public static String ParseMsg(String strMsg, String strValue, int intLen) {
if (strMsg == null)
strMsg = strValue;
long lMsgLength = strMsg.getBytes().length;
if (lMsgLength < intLen) {
while (lMsgLength < intLen) {
strMsg = strMsg + strValue;
lMsgLength = strMsg.getBytes().length;
}
}
return strMsg;
}
public static String getValue(Object str) {
if (str == null || str.equals("null"))
return "";
else
return str.toString();
}
public static Date formateDate(String dateString, String hourStr, String minStr) {
Calendar calendar = Calendar.getInstance();
int year = Integer.parseInt(dateString.substring(0, 4));
int month = Integer.parseInt(dateString.substring(5, 7));
int day = Integer.parseInt(dateString.substring(8, 10));
int hour = Integer.parseInt(hourStr);
int min = Integer.parseInt(minStr);
calendar.set(year, month - 1, day, hour, min, 0);
return calendar.getTime();
}
public static String TimestampDateFormat(Timestamp timestamp) {
if (timestamp == null) {
return null;
}
String timestampStr = null;
timestampStr = "to_timestamp('" + timestamp.toString() + "','YYYY-MM-DD HH24:MI:SSXFF')";
return timestampStr;
}
/**
* 给出"YYYY-MM-DD","HH","MI"三个字符串,返回一个oracle的时间格式
*
* @author Ltao 2004-12-12
* @param dateString
* @param hourStr
* @param minStr
* @return oracle的时间格式 形如"to_date(..." , 如果三个参数中缺少其中任意一个,则返回null;
*/
public static String oracleDateFormat(String dateString, String hourStr, String minStr, String secStr) {
if (dateString == null || hourStr == null || minStr == null || secStr == null || dateString.equals("") || hourStr.equals("") || minStr.equals("")
|| secStr.equals("")) {
return null;
}
String oracleDateStr = null;
String tempStr = dateString + " " + hourStr + ":" + minStr + ":" + secStr;
oracleDateStr = "to_date('" + tempStr + "','YYYY-MM-DD HH24:MI:SS')";
return oracleDateStr;
}
/**
* 取timestamp的形如"YYYY-MM-DD"的日期字符串,
*
* @author Ltao 2004-12-12
* @param time
* 时间
* @return 形如"YYYY-MM-DD"的日期字符串, 如果time为null,则返回null;
*/
public static String getDateStr(Timestamp time) {
if (time == null) {
return "";
}
String result = null;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd ");
result = df.format(time);
return result;
}
/**
* 取timestamp的形如"HH24:MI:SS"的时间字符串,
*
* @param time 时间
* @return 形如"HH24:MI:SS"的时间字符串, 如果time为null,则返回null;
*/
public static String getHourMinuteSecondStr(Timestamp time) {
if (time == null) {
return "";
}
String result = null;
DateFormat df = new SimpleDateFormat("HH:mm:ss");
result = df.format(time);
return result;
}
/**
* 取Date的形如"HH24:MI:SS"的时间字符串,
*
* @param time
* 时间
* @return 形如"HH24:MI:SS"的时间字符串, 如果time为null,则返回null;
*/
public static String getHourMinuteSecondStr(Date date) {
if (date == null) {
return "";
}
String result = null;
DateFormat df = new SimpleDateFormat("hh:mm:ss");
result = df.format(date);
return result;
}
/**
* 取timestamp的形如"HH24:MI"的时间字符串,
*
* @author Ltao 2004-12-12
* @param time
* 时间
* @return 形如"HH24:MI"的时间字符串, 如果time为null,则返回null;
*/
public static String getHourMinuteStr(Timestamp time) {
if (time == null) {
return "";
}
String result = null;
DateFormat df = new SimpleDateFormat("hh:mm");
result = df.format(time);
return result;
}
public static String log2String(HashMap hashMap) {
StringBuilder result = new StringBuilder();
Object[] keyList = hashMap.keySet().toArray();
for (int i = 0; i < keyList.length; i++) {
String keyName = keyList[i] == null ? "" : keyList[i].toString();
String keyValue = hashMap.get(keyName) == null ? "" : hashMap.get(keyName).toString();
result.append(keyName + ":" + hashMap.get(keyList[i].toString()) + "\n");
}
return result.toString();
}
public static String log2ContentName(HashMap hashMap) {
String result = "";
if (hashMap.get("Content Name") != null) {
result = (String) hashMap.get("Content Name");
}
return result;
}
public static String removeQueryString(String queryStr, String paramName) {
int i = queryStr.indexOf(paramName);
if (i >= 0) {
int j = queryStr.indexOf("&", i);
if (j > 0)
queryStr = queryStr.substring(0, i) + queryStr.substring(j + 1);
else if (i == 0)
queryStr = "";
else
queryStr = queryStr.substring(0, i - 1);
}
return queryStr;
}
/**
* 把时间类型传换成String,空的话换成""
*
* @return
*/
public static String getDateWeb(Date newDate) {
return newDate == null ? "" : newDate.toString();
}
/**
* 把时间类型传换成String,空的话换成""
*
* @return
*/
public static String getStrWeb(String str) {
return str == null ? "" : str.toString();
}
/**
* 把时间类型传换成String,空的话换成""
*
* @return
*/
public static String getLongWeb(Long newLong) {
return newLong == null ? "" : newLong.toString();
}
/**
* 分割以指定符号的字符串
*
* @param splitStr
* @return
*/
public static String[] getSplitString(String splitStr, String splitType) {
StringTokenizer str = new StringTokenizer(splitStr, splitType);
int strNum = str.countTokens();
String strTemp[] = new String[strNum];
int i = 0;
while (str.hasMoreElements()) {
strTemp[i] = (String) str.nextElement();
i++;
}
return strTemp;
}
public static String percentage(double d) {
Double double1 = new Double(d);
int i = double1.intValue();
return i + "%";
}
// 把字符串中大写的字母都变成小写
public static String changeSmall(String str) {
String smallStr = "";
char indexChar;
for (int i = 0; str != null && i < str.length(); i++) {
indexChar = str.charAt(i);
if (indexChar == 'A') {
indexChar = 'a';
} else if (indexChar == 'B') {
indexChar = 'b';
} else if (indexChar == 'C') {
indexChar = 'c';
} else if (indexChar == 'D') {
indexChar = 'd';
} else if (indexChar == 'E') {
indexChar = 'e';
} else if (indexChar == 'F') {
indexChar = 'f';
} else if (indexChar == 'G') {
indexChar = 'g';
} else if (indexChar == 'H') {
indexChar = 'h';
} else if (indexChar == 'I') {
indexChar = 'i';
} else if (indexChar == 'J') {
indexChar = 'j';
} else if (indexChar == 'K') {
indexChar = 'k';
} else if (indexChar == 'L') {
indexChar = 'l';
} else if (indexChar == 'M') {
indexChar = 'm';
} else if (indexChar == 'N') {
indexChar = 'n';
} else if (indexChar == 'O') {
indexChar = 'o';
} else if (indexChar == 'P') {
indexChar = 'p';
} else if (indexChar == 'Q') {
indexChar = 'q';
} else if (indexChar == 'R') {
indexChar = 'r';
} else if (indexChar == 'S') {
indexChar = 's';
} else if (indexChar == 'T') {
indexChar = 't';
} else if (indexChar == 'U') {
indexChar = 'u';
} else if (indexChar == 'V') {
indexChar = 'v';
} else if (indexChar == 'W') {
indexChar = 'w';
} else if (indexChar == 'X') {
indexChar = 'x';
} else if (indexChar == 'Y') {
indexChar = 'y';
} else if (indexChar == 'Z') {
indexChar = 'z';
}
smallStr += indexChar;
}
return smallStr;
}
public static String percentage(String s1, String s2) {
return percentage(toInteger(s1) * 100 / toInteger(s2));
}
/**
* change window type path to unix
*
* @param originalPath
* @return String
*/
public static String makeAbsolutePath(String originalPath) {
originalPath = originalPath.replace('\\', '/');
if ('/' == originalPath.charAt(0)) {
return originalPath;
}
/* Check for a drive specification for windows-type path */
if (originalPath.substring(1, 2).equals(":")) {
return originalPath;
}
/* and put the two together */
return originalPath;
}
public static String str2booleanValue(String value) {
if (value != null && value.trim().equals("1"))
return "1";
else
return "0";
}
public static String concateFormArray(List values) {
return concateFormArray(values, ",");
}
public static String concateFormArray(List values, String delimiter) {
if (values == null || values.size() == 0)
return "";
String temp[] = new String[values.size()];
values.toArray(temp);
return contactStr(temp, delimiter);
}
public static final String zeroPadString(String string, int length) {
if (string == null || string.length() > length) {
return string;
} else {
StringBuffer buf = new StringBuffer(length);
buf.append(zeroArray, 0, length - string.length()).append(string);
return buf.toString();
}
}
public static final String moneyFormat(String param) {
String ret = "";
try {
double parValue = Double.parseDouble(param);
ret = new DecimalFormat("0.00").format(parValue);
} catch (Exception e) {
ret = "0.00";
}
return ret;
}
public static final String moneyFormat1(String param) {
String ret = "";
try {
double parValue = Double.parseDouble(param);
ret = new DecimalFormat("0").format(parValue);
} catch (Exception e) {
ret = "0";
}
return ret;
}
/**
* transform null to ""
*
* @param param
* @return String
*/
public static final String tranNull(String param) {
String strPra = "";
if (null == param) {
strPra = "";
} else {
strPra = param;
}
return strPra;
}
public static final String excutingTime(String dateTime) throws Exception {
if (dateTime == null || "".equals(dateTime)) {
return getDefaultTime();
} else {
return dateTime;
}
}
public static final String[] excutingTArray(String[] dateTime) throws Exception {
if (dateTime == null) {
String[] array = { getDefaultTime() };
return array;
} else
{
return dateTime;
}
}
public static final String excutingTimeArray(String[] dateTime) throws Exception {
if (dateTime == null) {
String[] array = { getDefaultTime() };
dateTime = array;
}
StringBuffer str = new StringBuffer("");
str.append("[");
for (int i = 0; i < dateTime.length; i++) {
str.append("'" + dateTime[i] + "'");
if ((i != (dateTime.length - 1))) {
str.append(",");
}
}
str.append("]");
return str.toString();
}
protected static final String getDefaultTime() throws Exception {
Date date = null;
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, 7);
date = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);
}
/**
*
* @param obj
*/
public static boolean isNotEmpty(String obj) {
return obj != null && obj.trim().length() > 0;
}
/**
*
* @param obj
* @return
*/
public static boolean isEmpty(String obj) {
return !isNotEmpty(obj);
}
public static String toString(Object obj)
{
return ReflectionToStringBuilder.toString(obj);
}
public static void main(String [] args)
{
boolean result=true;
String status = result ? SNOrderConstants.ONE_STRING : SNOrderConstants.ZERO;
System.out.println("status="+status);
}
}
String 自定义函数
最新推荐文章于 2022-03-30 17:23:13 发布