欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Java工具類

張軍 2401 0
package zj.java.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSON;

import zj.check.util.CheckUtil;
import zj.common.exception.ServiceException;
import zj.date.util.DateUtil;
import zj.type.TypeUtil;

/**
 * java工具類
 * 
 * @version 1.00 (2014.09.15)
 * @author SHNKCS 張軍 {@link <a target=_blank href="http://www.shanghaijiadun.com">上海加盾信息科技有限公司</a>&nbsp;&nbsp;&nbsp;&nbsp;<a target=_blank href="http://www.dlhighland.cn">張軍個人網站</a>&nbsp;&nbsp;&nbsp;&nbsp;<a target=_blank href="http://user.qzone.qq.com/360901061/">張軍QQ空間</a>}
 */
public class JavaUtil implements Serializable {
	private static final long serialVersionUID = 1L;
	private transient static final Logger log = Logger.getLogger(JavaUtil.class);
	/**
	 * 單位進位,中文默認為4位即(萬、億)
	 */
	public static int UNIT_STEP = 4;

	/**
	 * 單位
	 */
	public static String[] CN_UNITS = new String[] { "個", "十", "百", "千", "萬", "十", "百", "千", "億", "十", "百", "千", "萬" };
	/**
	 * 漢字
	 */
	public static String[] CN_CHARS = new String[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };

	/**
	 * 打印json
	 * 
	 * @param json
	 */
	@SuppressWarnings("unchecked")
	public static Map<String, Object> parseMap(String json) {
		return parseJson(json, Map.class);
	}

	/**
	 * 打印json
	 * 
	 * @param json
	 */
	public static <T> T parseJson(String json, Class<T> clz) {
		T result = JSON.parseObject(json, clz);
		log.debug("json返回結果------------>");
		log.debug(JSON.toJSONString(result, true));
		return result;
	}

	/**
	 * 獲取系統換行符號
	 * 
	 * @return
	 */
	public static String getLineBreak() {
		if (JavaUtil.isWindows()) {
			return "\r\n";
		} else if (JavaUtil.isMac()) {
			return "\r";
		} else {
			return "\n";
		}
	}

	/**
	 * 分割email地址,轉換成一行
	 * 
	 * @param p_emails
	 *            email地址
	 */
	public static String emailSplitToOneline(String p_emails) {
		return emailSplitToOneline(p_emails, ";");
	}

	/**
	 * 分割email地址,轉換成一行
	 * 
	 * @param p_emails
	 *            email地址
	 */
	public static String emailSplitToOneline(String p_emails, String split) {
		// String s = "a; bbcdd55 \r\nb\r\nc\r\nd";
		String[] v_emails1 = JavaUtil.split(p_emails, getLineBreak());
		String r_emails = "";
		for (String v_email1 : v_emails1) {
			v_email1 = JavaUtil.trim(v_email1);
			if (CheckUtil.isNull(v_email1)) {
				continue;
			}
			String[] v_emails2 = JavaUtil.split(v_email1, split);
			for (String v_email2 : v_emails2) {
				v_email2 = JavaUtil.trim(v_email2);
				if (CheckUtil.isNull(v_email1)) {
					continue;
				}
				if (CheckUtil.isNotNull(r_emails)) {
					r_emails += split;
				}
				r_emails += v_email2;
			}
		}
		return r_emails;
	}

	/**
	 * 是否是windows
	 * 
	 * @return
	 */
	public static boolean isWindows() {
		try {
			String osName = System.getProperty("os.name");
			return JavaUtil.toLowerCase(osName).indexOf("windows") != -1;
		} catch (Exception e) {
			return true;
		}
	}

	/**
	 * 是否是mac系統
	 * 
	 * @return
	 */
	public static boolean isMac() {
		try {
			String osName = System.getProperty("os.name");
			return JavaUtil.toLowerCase(osName).indexOf("mac") != -1;
		} catch (Exception e) {
			return true;
		}
	}

	/**
	 * 支持到12位
	 *
	 * @param numberStr
	 *            中文數字
	 * @return int 數字
	 */
	public static int getIntegerByStr(String numberStr) {

		// 返回結果
		int sum = 0;

		// null或空串直接返回
		if (numberStr == null || ("").equals(numberStr)) {
			return sum;
		}

		// 過億的數字處理
		if (numberStr.indexOf("億") > 0) {
			String currentNumberStr = numberStr.substring(0, numberStr.indexOf("億"));
			int currentNumber = doByStr(currentNumberStr);
			sum += currentNumber * Math.pow(10, 8);
			numberStr = numberStr.substring(numberStr.indexOf("億") + 1);
		}

		// 過萬的數字處理
		if (numberStr.indexOf("萬") > 0) {
			String currentNumberStr = numberStr.substring(0, numberStr.indexOf("萬"));
			int currentNumber = doByStr(currentNumberStr);
			sum += currentNumber * Math.pow(10, 4);
			numberStr = numberStr.substring(numberStr.indexOf("萬") + 1);
		}

		// 小于萬的數字處理
		if (!("").equals(numberStr)) {
			int currentNumber = doByStr(numberStr);
			sum += currentNumber;
		}

		return sum;
	}

	/**
	 * 把億、萬分開每4位一個單元,解析并獲取到數據
	 * 
	 * @param testNumber
	 * @return
	 */
	public static int doByStr(String testNumber) {
		// 返回結果
		int sum = 0;

		// null或空串直接返回
		if (testNumber == null || ("").equals(testNumber)) {
			return sum;
		}

		// 獲取到千位數
		if (testNumber.indexOf("千") > 0) {
			String currentNumberStr = testNumber.substring(0, testNumber.indexOf("千"));
			sum += doByStrReplace(currentNumberStr) * Math.pow(10, 3);
			testNumber = testNumber.substring(testNumber.indexOf("千") + 1);
		}

		// 獲取到百位數
		if (testNumber.indexOf("百") > 0) {
			String currentNumberStr = testNumber.substring(0, testNumber.indexOf("百"));
			sum += doByStrReplace(currentNumberStr) * Math.pow(10, 2);
			testNumber = testNumber.substring(testNumber.indexOf("百") + 1);
		}

		// 對于特殊情況處理 比如10-19是個數字,十五轉化為一十五,然后再進行處理
		if (testNumber.indexOf("十") == 0) {
			testNumber = "一" + testNumber;
		}

		// 獲取到十位數
		if (testNumber.indexOf("十") > 0) {
			String currentNumberStr = testNumber.substring(0, testNumber.indexOf("十"));
			sum += doByStrReplace(currentNumberStr) * Math.pow(10, 1);
			testNumber = testNumber.substring(testNumber.indexOf("十") + 1);
		}

		// 獲取到個位數
		if (!("").equals(testNumber)) {
			sum += doByStrReplace(testNumber.replaceAll("零", ""));
		}

		return sum;
	}

	public static int doByStrReplace(String replaceNumber) {
		switch (replaceNumber) {
		case "一":
			return 1;
		case "二":
			return 2;
		case "三":
			return 3;
		case "四":
			return 4;
		case "五":
			return 5;
		case "六":
			return 6;
		case "七":
			return 7;
		case "八":
			return 8;
		case "九":
			return 9;
		case "零":
			return 0;
		default:
			throw new ServiceException("無法解析大寫數字【" + replaceNumber + "】");
		}
	}

	/**
	 * 數字轉大寫,僅僅轉大寫
	 * 
	 * @param pnum
	 *            數字字符串,可帶其它字符
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static String numToCnChar(String pnum) {
		char[] cnumAry = pnum.toCharArray();
		String snumNew = "";
		for (char cnum : cnumAry) {
			String snum = objToStr(cnum);
			if (CheckUtil.isPlusNum(snum)) {
				snumNew += CN_CHARS[TypeUtil.Primitive.intValue(snum)];
			} else {
				snumNew += snum;
			}
		}
		return snumNew;
	}

	/**
	 * 數字轉大寫日期(只支持4位數字年或2位數字月日)
	 * 
	 * @see 年、月、日分別調用
	 * @param pnum
	 *            數字
	 * @param decimal
	 *            是否是十進位,默認false,如果是true,則12-》十二
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static String numToCnCharDate(int pnum) {
		String rnum = numToCnChar(JavaUtil.objToStr(pnum));
		if (pnum < 1000) {
			if (pnum == 10) {
				rnum = "十";
			} else if (pnum > 10) {
				if (rnum.startsWith("一")) {
					rnum = "十" + rnum.substring(1);
				} else {
					rnum = rnum.substring(0, 1) + "十" + rnum.substring(1);
				}
			}
		}
		return rnum;
	}

	/**
	 * 數值轉換為中文字符串 如2轉化為貳
	 */
	public static String numToCn(long num) {
		return numToCn(num, true);
	}

	/**
	 * 數值轉換為中文字符串(口語化)
	 * 
	 * @param num
	 *            需要轉換的數值
	 * @param isColloquial
	 *            是否口語化。例如12轉換為'十二'而不是'一十二'。
	 * @return
	 */
	public static String numToCn(String num, boolean isColloquial) {
		int integer = 0, decimal = 0;
		StringBuffer strs = new StringBuffer(32);
		String[] splitNum = num.split("\\.");
		if (splitNum.length > 0)
			integer = Integer.parseInt(splitNum[0]); // 整數部分
		if (splitNum.length > 1)
			decimal = Integer.parseInt(splitNum[1]); // 小數部分
		String[] result_1 = numConvert(integer, isColloquial);
		for (String str1 : result_1)
			strs.append(str1);
		if (decimal == 0) {// 小數部分為0時
			return strs.toString();
		} else {
			String result_2 = numToCnChar("" + decimal); // 例如5.32,小數部分展示三二,而不是三十二
			strs.append("點");
			strs.append(result_2);
			return strs.toString();
		}
	}

	/**
	 * 對于int,long類型的數據處理
	 * 
	 * @param num
	 *            需要轉換的數值
	 * @param isColloquial
	 *            是否口語化。例如12轉換為'十二'而不是'一十二'。
	 * @return
	 */
	public static String numToCn(long num, boolean isColloquial) {
		String[] result = numConvert(num, isColloquial);
		StringBuffer strs = new StringBuffer(32);
		for (String str : result) {
			strs.append(str);
		}
		return strs.toString();
	}

	/**
	 * 將數值轉換為中文
	 * 
	 * @param num
	 *            需要轉換的數值
	 * @param isColloquial
	 *            是否口語化。例如12轉換為'十二'而不是'一十二'。
	 * @return
	 */
	public static String[] numConvert(long num, boolean isColloquial) {
		if (num < 10) {// 10以下直接返回對應漢字
			return new String[] { CN_CHARS[(int) num] };// ASCII2int
		}

		char[] chars = String.valueOf(num).toCharArray();
		if (chars.length > CN_UNITS.length) {// 超過單位表示范圍的返回空
			return new String[] {};
		}

		boolean isLastUnitStep = false;// 記錄上次單位進位
		ArrayList<String> cnchars = new ArrayList<String>(chars.length * 2);// 創建數組,將數字填入單位對應的位置
		for (int pos = chars.length - 1; pos >= 0; pos--) {// 從低位向高位循環
			char ch = chars[pos];
			String cnChar = CN_CHARS[ch - '0'];// ascii2int 漢字
			int unitPos = chars.length - pos - 1;// 對應的單位坐標
			String cnUnit = CN_UNITS[unitPos];// 單位
			boolean isZero = (ch == '0');// 是否為0
			boolean isZeroLow = (pos + 1 < chars.length && chars[pos + 1] == '0');// 是否低位為0

			boolean isUnitStep = (unitPos >= UNIT_STEP && (unitPos % UNIT_STEP == 0));// 當前位是否需要單位進位

			if (isUnitStep && isLastUnitStep) {// 去除相鄰的上一個單位進位
				int size = cnchars.size();
				cnchars.remove(size - 1);
				if (!CN_CHARS[0].equals(cnchars.get(size - 2))) {// 補0
					cnchars.add(CN_CHARS[0]);
				}
			}

			if (isUnitStep || !isZero) {// 單位進位(萬、億),或者非0時加上單位
				cnchars.add(cnUnit);
				isLastUnitStep = isUnitStep;
			}
			if (isZero && (isZeroLow || isUnitStep)) {// 當前位為0低位為0,或者當前位為0并且為單位進位時進行省略
				continue;
			}
			cnchars.add(cnChar);
			isLastUnitStep = false;
		}

		Collections.reverse(cnchars);
		// 清除最后一位的0
		int chSize = cnchars.size();
		String chEnd = cnchars.get(chSize - 1);
		if (CN_CHARS[0].equals(chEnd) || CN_UNITS[0].equals(chEnd)) {
			cnchars.remove(chSize - 1);
		}

		// 口語化處理
		if (isColloquial) {
			String chFirst = cnchars.get(0);
			String chSecond = cnchars.get(1);
			if (chFirst.equals(CN_CHARS[1]) && chSecond.startsWith(CN_UNITS[1])) {// 是否以'一'開頭,緊跟'十'
				cnchars.remove(0);
			}
		}
		return cnchars.toArray(new String[] {});
	}

	/**
	 * 檢查數據差異
	 * 
	 * @param text
	 *            數字
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static <T> List<T> diffColl(Collection<T> c1, Collection<T> c2) {
		List<T> result = new ArrayList<T>();
		try {
			// 添加至去重列表中
			Set<T> allC = new HashSet<T>();
			allC.addAll(c1);
			allC.addAll(c2);
			for (T v : allC) {
				if (c1.contains(v) && c2.contains(v)) {
					// 兩個集合中的數據共同包含
				} else {
					// 兩個集合中的數據不相同的
					result.add(v);
				}
			}
		} catch (Exception e) {
			throw new ServiceException(e);
		}
		return result;
	}

	/**
	 * DecimalFormat轉換數字
	 * 
	 * @param text
	 *            數字
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static String covertNumEToString(Object text) {
		return covertNumEToString(text, null);
	}

	/**
	 * DecimalFormat轉換數字
	 * 
	 * @param text
	 *            數字
	 * @param format
	 *            格式
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static String covertNumEToString(Object text, String format) {
		try {
			if (CheckUtil.isNull(format)) {
				format = "#.##";
			}
			if (!(text instanceof String)) {
				DecimalFormat df = new DecimalFormat(format);
				Double d = Double.parseDouble(df.format(text));
				String sd = df.format(d);
				return sd;
			}
			return objToStr(text);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}

	/**
	 * DecimalFormat轉換數字
	 * 
	 * @param text
	 *            數字
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static String covertToNumSplit(Object text) {
		return covertToNumSplit(text, null);
	}

	/**
	 * DecimalFormat轉換數字
	 * 
	 * @param text
	 *            數字
	 * @param format
	 *            格式
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static String covertToNumSplit(Object text, String format) {
		try {
			if (CheckUtil.isNull(format)) {
				format = "###,###.##";
			}
			DecimalFormat df = new DecimalFormat(format);
			return df.format(TypeUtil.Primitive.doubleValueNoCatchError(text));
		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}

	/**
	 * 轉換數字
	 * 
	 * @param text
	 *            數字
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static BigDecimal covertBigDecimal(Object text) {
		String value = JavaUtil.conversionStringToNumber(JavaUtil.trim(JavaUtil.objToStr(text)));
		BigDecimal bvalue = BigDecimal.ZERO;
		if (CheckUtil.isNotNull(value)) {
			try {
				bvalue = new BigDecimal(value);
			} catch (Exception e) {
				// 不做處理
			}
		}
		return bvalue;
	}

	/**
	 * 獲取in的字符串
	 * 
	 * @param strs
	 *            字符集合
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static String sqlInStr(Collection<String> strs) {
		String rtnStrs = "";
		int i = 0;
		for (String s : strs) {
			if (i != 0)
				rtnStrs += ",";
			rtnStrs += "'" + s + "'";
			i++;
		}
		return rtnStrs;
	}

	/**
	 * 轉換文件大小為B、KB、MB、GB
	 * 
	 * @param size
	 *            文件大小
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static String convertFileSize(long size) {
		// 轉成大數據
		if (size < 1024) {
			// B
			return String.valueOf(size) + "B";
		} else {
			// KB
			BigDecimal b1024 = new BigDecimal(1024);
			BigDecimal tempSize = new BigDecimal(size);
			BigDecimal valueSize = tempSize.divide(b1024, 8, BigDecimal.ROUND_HALF_UP);
			if (valueSize.compareTo(b1024) <= 0) {
				// 如果小于1024
				return valueSize.setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "KB";
			} else {
				// MB
				valueSize = valueSize.divide(b1024, 6, BigDecimal.ROUND_HALF_UP);
				if (valueSize.compareTo(b1024) <= 0) {
					// 如果小于1024
					return valueSize.setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "MB";
				} else {
					// GB
					valueSize = valueSize.divide(b1024, 4, BigDecimal.ROUND_HALF_UP);
					if (valueSize.compareTo(b1024) <= 0) {
						// 如果小于1024
						return valueSize.setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "GB";
					} else {
						// TB
						valueSize = valueSize.divide(b1024, 2, BigDecimal.ROUND_HALF_UP);
						if (valueSize.compareTo(b1024) <= 0) {
							// 如果小于1024
							return valueSize.setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "TB";
						} else {
							// 默認
							return tempSize.toString() + "B";
						}
					}
				}
			}
		}
	}

	/**
	 * 深度拷貝list數據
	 * 
	 * @param src
	 *            源集合
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> List<T> deepCopy(List<T> src) {
		try {
			ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
			ObjectOutputStream out = new ObjectOutputStream(byteOut);
			out.writeObject(src);
			ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
			ObjectInputStream in = new ObjectInputStream(byteIn);
			return (List<T>) in.readObject();
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 合并兩個數組
	 * 
	 * @param first
	 *            第一個數組
	 * @param second
	 *            第二個數組
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static <T> T[] concatArray(T[] first, T[] second) {
		T[] result = Arrays.copyOf(first, first.length + second.length);
		System.arraycopy(second, 0, result, first.length, second.length);
		return result;
	}

	// @SuppressWarnings("unchecked")
	// public static <T> T[] concatArray(T[] a, T[] b) {
	// final int alen = a.length;
	// final int blen = b.length;
	// if (alen == 0) {
	// return b;
	// }
	// if (blen == 0) {
	// return a;
	// }
	// final T[] result = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), alen + blen);
	// System.arraycopy(a, 0, result, 0, alen);
	// System.arraycopy(b, 0, result, alen, blen);
	// return result;
	// }
	/**
	 * 合并多個數組
	 * 
	 * @param first
	 *            第一個數組
	 * @param rest
	 *            多個組合
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> T[] concatArrayAll(T[] first, T[]... rest) {
		int totalLength = first.length;
		for (T[] array : rest) {
			totalLength += array.length;
		}
		T[] result = Arrays.copyOf(first, totalLength);
		int offset = first.length;
		for (T[] array : rest) {
			System.arraycopy(array, 0, result, offset, array.length);
			offset += array.length;
		}
		return result;
	}

	/**
	 * 替換字符串
	 * 
	 * @param template
	 *            模板字符串
	 * @param placeholder
	 * @param replacement
	 * @return
	 */
	public static String replaceOnce(String template, String placeholder, String replacement) {
		// System.out.println("varchar($2)".replaceAll("\\$2", "9")+replaceOnce("varchar($2)","$2","6"));
		int loc = template == null ? -1 : template.indexOf(placeholder);
		if (loc < 0) {
			return template;
		} else {
			return new StringBuffer(template.substring(0, loc)).append(replacement).append(template.substring(loc + placeholder.length())).toString();
		}
	}

	/**
	 * 去除text所有空格
	 * 
	 * @param text
	 * @return
	 */
	public static final String trims(String text) {
		if (CheckUtil.isNull(text)) {
			return text;
		}
		String newStr = "";
		char[] chars = text.toCharArray();
		for (char c : chars) {
			String s = JavaUtil.objToStr(c);
			if (CheckUtil.isNull(s)) {
				continue;
			}
			newStr += s;
		}
		return newStr;
	}

	/**
	 * 去除text左右空格
	 * 
	 * @param text
	 * @return
	 */
	public static final String trim(String text) {
		return ltrim(rtrim(text));
	}

	/**
	 * 替換左字符 String d = "b d a e abcd f "; String rs = CommonUtil.ltrimText(d, "a", "b", " d");
	 * 
	 * @param text
	 * @param trimText
	 * @return
	 */
	public static final String ltrimText(final String text, String... trimText) {
		if (text == null) {
			return null;
		}
		if (trimText == null || trimText.length == 0) {
			return ltrim(text);
		}
		int pos = 0;
		for (; pos < text.length(); pos++) {
			boolean notTrimChar = true;
			for (int i = 0; i < trimText.length; i++) {
				notTrimChar &= (trimText[i].indexOf(text.charAt(pos)) < 0);
			}
			if (notTrimChar) {
				break;
			}
		}
		return text.substring(pos);
	}

	/**
	 * 替換右字符
	 * 
	 * @param text
	 * @param trimText
	 * @return
	 */
	public static final String rtrimText(final String text, String... trimText) {
		if (text == null) {
			return null;
		}
		if (trimText == null || trimText.length == 0) {
			return rtrim(text);
		}
		int pos = text.length() - 1;
		for (; pos >= 0; pos--) {
			boolean notTrimChar = true;
			for (int i = 0; i < trimText.length; i++) {
				notTrimChar &= (trimText[i].indexOf(text.charAt(pos)) < 0);
			}
			if (notTrimChar) {
				break;
			}
		}
		return text.substring(0, pos + 1);
	}

	/**
	 * 替換左字符串
	 * 
	 * @param text
	 * @return
	 */
	public static final String ltrim(String text) {
		return ltrim(text, null);
	}

	/**
	 * 替換左字符串
	 * 
	 * @param text
	 * @param trimText
	 * @return
	 */
	public static final String ltrim(String text, String trimText) {
		if (text == null)
			return null;
		if (trimText == null)
			trimText = " ";
		int pos;
		for (pos = 0; pos < text.length() && trimText.indexOf(text.charAt(pos)) >= 0; pos++)
			;
		return text.substring(pos);
	}

	/**
	 * 替換右字符串
	 * 
	 * @param text
	 * @return
	 */
	public static final String rtrim(String text) {
		return rtrim(text, null);
	}

	/**
	 * 替換右字符串
	 * 
	 * @param text
	 * @param trimText
	 * @return
	 */
	public static final String rtrim(String text, String trimText) {
		if (text == null)
			return null;
		if (trimText == null)
			trimText = " ";
		int pos;
		for (pos = text.length() - 1; pos >= 0 && trimText.indexOf(text.charAt(pos)) >= 0; pos--)
			;
		return text.substring(0, pos + 1);
	}

	/**
	 * 分割字符串類
	 * 
	 * @author zhangjun
	 * 
	 */
	public static class SplitConstants {
		public static final String TRIM = "all";
		public static final String NRIM = "none";
		public static final String LTRIM = "left";
		public static final String RTRIM = "right";

		public static final String NO_CASE = "";
		public static final String TO_UPPER_CASE = "0";
		public static final String TO_LOWER_CASE = "1";
	}

	/**
	 * 分割字符串
	 * 
	 * @param str
	 * @param delim
	 * @return
	 */
	public static final String[] split(String str, String delim) {
		return split(str, delim, SplitConstants.TRIM, SplitConstants.NO_CASE);
	}

	/**
	 * 分割字符串
	 * 
	 * @param str
	 * @param delim
	 * @param caseType
	 * @return
	 */
	public static final String[] split(String str, String delim, String caseType) {
		return split(str, delim, SplitConstants.TRIM, caseType);
	}

	/**
	 * 分割字符串
	 * 
	 * @param str
	 * @param delim
	 * @param trim
	 *            去除左右空格
	 * @param caseType
	 * @return
	 */
	public static final String[] split(String str, String delim, String trim, String caseType) {
		String[] arrayStrings;
		try {
			arrayStrings = mySplit(str, delim, trim, caseType);
		} catch (Throwable t) {
			arrayStrings = null;
		}
		if (arrayStrings == null) {
			arrayStrings = new String[0];
		}
		return arrayStrings;

	}

	/**
	 * 分割字符串
	 * 
	 * @param s
	 * @param delimiter
	 * @param trim
	 * @param caseType
	 * @return
	 */
	private static String[] mySplit(String str, String delimiter, String trim, String caseType) {
		int delimiterLength;
		int stringLength = str.length();
		if (delimiter == null || (delimiterLength = delimiter.length()) == 0) {
			return new String[] { str };
		}
		int count;
		int start;
		int end;
		count = 0;
		start = 0;
		while ((end = str.indexOf(delimiter, start)) != -1) {
			count++;
			start = end + delimiterLength;
		}
		count++;
		String[] result = new String[count];
		count = 0;
		start = 0;
		while ((end = str.indexOf(delimiter, start)) != -1) {
			result[count] = getTrimStr(str.substring(start, end), trim, caseType);
			count++;
			start = end + delimiterLength;
		}
		end = stringLength;
		result[count] = getTrimStr(str.substring(start, end), trim, caseType);
		return (result);
	}

	/**
	 * 合并字符串
	 * 
	 * @param str
	 * @param trim
	 * @param caseType
	 * @return
	 */
	private static String getTrimStr(String str, String trim, String caseType) {
		if (SplitConstants.TRIM.equals(trim)) {
			str = str.trim();
		} else if (SplitConstants.LTRIM.equals(trim)) {
			str = ltrim(str);
		} else if (SplitConstants.RTRIM.equals(trim)) {
			str = rtrim(str);
		}
		if (SplitConstants.TO_LOWER_CASE.equals(caseType)) {
			str = str.toLowerCase();
		} else if (SplitConstants.TO_UPPER_CASE.equals(caseType)) {
			str = str.toUpperCase();
		}
		return str;
	}

	/**
	 * 轉strs數組為字符串用split分割
	 * 
	 * @param strs
	 * @param split
	 * @return
	 */
	public static String getAryStrs(String[] strs, String split) {
		return getAryStrs(strs, split, "");
	}

	/**
	 * 轉split分割的str字符串,轉新的分割newSplit,添加在值左右添加addStr字符串
	 * 
	 * @param str
	 * @param split
	 * @param newSplit
	 * @param addStr
	 * @return
	 */
	public static String getAryStrs(String str, String split, String newSplit, String addStr) {
		return getAryStrs(split(str, split), newSplit, addStr);
	}

	/**
	 * 轉strs數組為字符串用split分割,添加在值左右添加addStr字符串
	 * 
	 * @param strs
	 * @param split
	 * @param addStr
	 * @return
	 */
	public static String getAryStrs(String[] strs, String split, String addStr) {
		String rtnStrs = "";
		try {
			if (strs.length == 1 && strs[0].equals(""))
				return "";
			for (int i = 0; i < strs.length; i++) {
				if (i != 0)
					rtnStrs += split;
				rtnStrs += addStr + strs[i] + addStr;
			}
		} catch (Exception e) {
			rtnStrs = "";
			log.error(e.getMessage());
		}
		return rtnStrs;
	}

	/**
	 * 返回String
	 * 
	 * @param o
	 * @return
	 */
	public static String objToStr(Object obj) {
		String str = "";
		if (obj == null) {
			return str;
		} else {
			if (obj instanceof Date) {
				str = DateUtil.dateParse((Date) obj, "yyyy-MM-dd HH:mm:ss");
			} else {
				str = obj.toString();
			}
		}
		return str;
	}

	/**
	 * 返回String
	 * 
	 * @param o
	 * @return
	 */
	public static String objToStrNull(Object obj) {
		if (obj == null) {
			return null;
		} else {
			return objToStr(obj);
		}
	}

	/**
	 * 轉換成大寫
	 * 
	 * @param o
	 * @return
	 */
	public static String toUpperCase(String o) {
		return o == null ? null : o.toUpperCase();
	}

	/**
	 * 轉換成小寫
	 * 
	 * @param o
	 * @return
	 */
	public static String toLowerCase(String o) {
		return o == null ? null : o.toLowerCase();
	}

	/**
	 * LIST轉數組
	 * 
	 * @param list
	 * @param clazz
	 * @return
	 */
	public static <T> T[] listToArray(List<T> list, Class<T> clazz) {
		if (list == null || list.size() == 0)
			return null;
		@SuppressWarnings("unchecked")
		T[] array = (T[]) Array.newInstance(clazz, list.size());
		for (int i = 0; i < array.length; i++) {
			array[i] = list.get(i);
		}
		return array;
	}

	/**
	 * 獲取最大長度文字
	 * 
	 * @param text
	 * @param count
	 * @return
	 */
	public static String getMaxText(String text, int count) {
		// 設置文章標題最大值
		if (text == null || text.trim().equals(""))
			return "";
		int maxIndex = -1;
		maxIndex = text.length();
		if (maxIndex > count) {
			return text.substring(0, count) + "...";
		} else {
			return text;
		}
	}

	/**
	 * 轉換重復的list集合
	 * 
	 * @param list
	 * @return
	 */
	public static List<Map<Object, List<Object>>> convertRepeatList(List<Map<Object, Object>> list) {
		List<Map<Object, List<Object>>> rtnList = new ArrayList<Map<Object, List<Object>>>();
		Map<Object, Object> newMap = new HashMap<Object, Object>();
		for (Map<Object, Object> map : list) {
			Object key = map.keySet().iterator().next();
			newMap.put(key, null);
		}
		Map<Object, List<Object>> newMaps = null;
		List<Object> newLists = null;
		for (Object key : newMap.keySet()) {
			newMaps = new HashMap<Object, List<Object>>();
			newLists = new ArrayList<Object>();
			for (Map<Object, Object> map : list) {
				Object value2 = map.get(key);
				if (map.containsKey(key)) {
					newLists.add(value2);
				}
			}
			newMaps.put(key, newLists);
			rtnList.add(newMaps);
		}
		return rtnList;
	}

	/**
	 * 獲取UUID唯一標識
	 * 
	 * @return
	 */
	public static synchronized String getUUID() {
		// + "-" + System.currentTimeMillis()
		return getUUID("");
	}

	/**
	 * 
	 * @return
	 */
	public static synchronized String getUUID32() {
		// + "-" + System.currentTimeMillis()
		return UUID.randomUUID().toString().replaceAll("-", "");
	}

	/**
	 * 獲取UUID唯一標識
	 * 
	 * @return
	 */
	public static synchronized String getUUID(Class<?> cla) {
		return getUUID(cla.getSimpleName());
	}

	/**
	 * 獲取UUID唯一標識
	 * 
	 * @return
	 */
	public static synchronized String getUUID(String prefix) {
		String ymdhmss = DateUtil.dateParse(new Date(), "yyyyMMddHHmmssSSS");
		return (CheckUtil.isNull(prefix) ? "id_" + ymdhmss : toLowerCase(prefix) + "_" + ymdhmss) + "_" + getUUID32();
	}

	/**
	 * Object對象換int類型
	 * 
	 * @param o
	 * @return
	 */
	public static int getIntValue(Object o) {
		if (o == null) {
			return 0;
		} else {
			try {
				if (o instanceof BigDecimal) {
					return ((BigDecimal) o).intValue();
				} else if (o instanceof Integer) {
					return ((Integer) o).intValue();
				} else if (o instanceof Long) {
					return ((Long) o).intValue();
				} else if (o instanceof String) {
					return Integer.parseInt(String.valueOf(o));
				} else {
					return Integer.parseInt(o + "");
				}
			} catch (Exception e) {
				log.error(e.getMessage());
				return 0;
			}
		}
	}

	/**
	 * 去除數組中為null或""的值
	 * 
	 * @param values
	 * @return
	 */
	public static String[] aryTrimValue(String[] values) {
		if (values == null) {
			return null;
		} else {
			List<String> valuesLst = new ArrayList<String>();
			for (String value : values) {
				if (CheckUtil.isNotNull(value)) {
					valuesLst.add(value);
				}
			}
			return (String[]) valuesLst.toArray(new String[valuesLst.size()]);
		}
	}

	/**
	 * 提取字符串中的整數字
	 * 
	 * @param txt
	 * @return
	 */
	public static int conversionStringToNum(String txt) {
		try {
			return Integer.parseInt(conversionStringToString("[^0-9]", txt));
		} catch (Exception e) {
			return 0;
		}
	}

	/**
	 * 提取字符串中的數字
	 * 
	 * @param txt
	 * @return
	 */
	public static String conversionStringToNumber(String txt) {
		return conversionStringToString("[^0-9\\.-]", txt);
	}

	/**
	 * 提取字符串中的數字
	 * 
	 * @param txt
	 * @return
	 */
	public static String conversionStringToString(String regEx, String txt) {
		if (CheckUtil.isNull(txt))
			return null;
		// String regEx = "[^0-9]";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(txt);
		// 替換非數字字符
		String str = m.replaceAll("").trim();
		return str;
	}

	/**
	 * 取得布爾值
	 * 
	 * @param txt
	 * @return
	 */
	@Deprecated
	public static boolean getBoolean(String txt) {
		try {
			return Boolean.parseBoolean(txt);
		} catch (Exception e) {
			log.error(e.getMessage());
			return false;
		}
	}

	/**
	 * 取得Long值
	 * 
	 * @param txt
	 * @return
	 */
	@Deprecated
	public static long getLong(String txt) {
		try {
			return Long.parseLong(txt);
		} catch (Exception e) {
			log.error(e.getMessage());
			return 0l;
		}
	}

	/**
	 * 獲取批量集合值
	 * 
	 * @param batchList
	 *            集合數據
	 * @param batchSize
	 *            每頁顯示條數
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return 批量集合值
	 */
	public static <T> List<List<T>> getBatchList(List<T> batchList, int batchSize) {
		List<List<T>> batchLists = new ArrayList<List<T>>();
		if (batchSize == 0) {
			return batchLists;
		}
		List<T> tempBatchList = null;
		int mod = batchList.size() % batchSize;
		int remainder = batchList.size() / batchSize;
		for (int i = 0; i < remainder; i++) {
			tempBatchList = new ArrayList<T>();
			for (int j = 1 + batchSize * i; j <= batchSize * (i + 1); j++) {
				tempBatchList.add(batchList.get(j - 1));
			}
			batchLists.add(tempBatchList);
		}
		if (mod != 0) {
			tempBatchList = new ArrayList<T>();
			for (int i = batchSize * remainder; i < batchList.size(); i++) {
				tempBatchList.add(batchList.get(i));
			}
			batchLists.add(tempBatchList);
		}
		return batchLists;
	}

	/**
	 * 獲取固定批量集合
	 * 
	 * @param batchList
	 *            集合數據
	 * @param batchSize
	 *            批量集合大小
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return 批量集合
	 */
	public static <T> List<List<T>> getFixedBatchList(List<T> batchList, int batchSize) {
		List<List<T>> batchLists = new ArrayList<List<T>>();
		if (batchSize == 0) {
			return batchLists;
		}
		int count = batchList.size();
		// 每個線程處理的集合數
		int preCount = count / batchSize;
		// 判斷是否整除線程數
		int modCount = count % batchSize;
		if (modCount != 0) {
			preCount++;
		}
		// 記錄索引
		int index = 0;
		List<T> tempTask = new ArrayList<T>();
		batchLists.add(tempTask);
		for (int i = 0; i < count; i++) {
			T value = batchList.get(i);
			tempTask.add(value);
			if (i != count - 1) {
				// 如果非最后一個元素
				index++;
				// 如果等于計算出來的每頁條數
				if (index == preCount) {
					// 實例化集合
					tempTask = new ArrayList<T>();
					batchLists.add(tempTask);
					// 重新開始
					index = 0;
				}
			}
		}
		return batchLists;
	}

	/**
	 * 根據頁碼條數計算多少頁
	 * 
	 * @param total
	 *            總條數
	 * @param rows
	 *            每頁顯示條數
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return 總頁數
	 */
	public static int calcPageCount(int total, int rows) {
		int pageCount = total / rows;
		int mod = total % rows;
		if (mod != 0) {
			pageCount++;
		}
		return pageCount;
	}

	/**
	 * 根據總條數獲取固定頁數
	 * 
	 * @param total
	 *            總條數
	 * @param rows
	 *            每頁顯示條數
	 * @param page
	 *            當前頁
	 * @param showPageCount
	 *            顯示多少頁
	 * 
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return 集合對象
	 * @see 開始頁:map.get("startPage")
	 * @see 結束頁:map.get("pageCount")
	 */
	public static Map<String, Object> calcPageCount(int total, int rows, int page, int showPageCount) {
		int pageCount = calcPageCount(total, rows);
		return calcPageCount(pageCount, page, showPageCount);
	}

	/**
	 * 根據總條數獲取固定頁數
	 * 
	 * @param pageCount
	 *            總頁碼
	 * @param page
	 *            當前頁
	 * @param showPageCount
	 *            顯示多少頁
	 * 
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return 集合對象
	 * @see 開始頁:map.get("startPage")
	 * @see 結束頁:map.get("pageCount")
	 */
	public static Map<String, Object> calcPageCount(int pageCount, int page, int showPageCount) {
		Map<String, Object> map = new HashMap<String, Object>();
		// 最新開始頁碼值
		int newStartPage = 1;
		// 最新結束頁碼值
		int newPageCount = pageCount;
		// 計算左右顯示的頁碼個數
		int prePageCount = showPageCount / 2;
		// 判斷右邊顯示的頁碼個數
		int modPageCount = showPageCount % 2;
		// 右邊多取個頁碼
		int leftPageCount = prePageCount;
		int rightPageCount = prePageCount;
		if (modPageCount == 0) {
			rightPageCount = rightPageCount - 1;
		}
		// 如果當前頁碼值大于指定的頁碼個數
		if (page > prePageCount) {
			// 右邊頁碼個數的最后一個頁碼
			int endPage = page + rightPageCount;
			// 如果小于總頁碼個數
			if (endPage < pageCount) {
				// 賦值右邊頁碼個數的最后一個頁碼
				newPageCount = endPage;
			}
			// 左邊頁碼個數的第一個頁碼
			newStartPage = page - leftPageCount;
			// 取得當前頁面后的右邊頁碼個數(如果rightPageCountCheck=0時,newStartPage=0,所以下面會有判斷newStartPage是否小于等于0)
			int rightPageCountCheck = newPageCount - page;
			if (rightPageCountCheck < rightPageCount) {
				// 判斷右邊頁碼個數沒有達到和左邊的頁碼個數一至
				// 取得右邊頁碼個數相差頁碼個數
				int rightDiffPageCount = rightPageCount - rightPageCountCheck;
				// 如果未達到,則當前頁碼前面的頁碼總數向前移動,使得頁碼達到11個頁碼
				newStartPage = newStartPage - rightDiffPageCount;
			}
		} else {
			if (pageCount > showPageCount - 1) {
				// 如果頁碼個數大于10,則輸出最大頁碼個數11個
				newPageCount = showPageCount;
			}
		}
		if (newStartPage <= 0) {
			// 開始頁碼從1開始
			newStartPage = 1;
		}
		// 設置返回值
		map.put("startPage", newStartPage);
		map.put("pageCount", newPageCount);
		return map;
	}

	/**
	 * 獲取最后分割符前面的字符串
	 * 
	 * @param text
	 * @param split
	 * @return
	 */
	public static String getBeforeTextLastDelimiter(String text, String split) {
		if (text == null)
			return null;
		if ("".equals(text))
			return "";
		int lastIndex = text.lastIndexOf(split);
		if (lastIndex != -1) {
			text = text.substring(0, lastIndex);
		}
		return text;
	}

	/**
	 * 去除小數點后的字符
	 * 
	 * @param text
	 * @param split
	 * @return
	 */
	public static Object getIsNumValue(Object value) {
		if (value == null)
			return null;
		if ("".equals(value))
			return "";
		String stext = value.toString();
		int lastIndex = stext.lastIndexOf(".");
		if (lastIndex == -1) {
			return value;
		}
		String beforeText = getBeforeTextLastDelimiter(stext, ".");
		String afterText = getAfterTextLastDelimiter(stext, ".");
		// System.out.println(beforeText);
		// System.out.println(afterText);
		if (CheckUtil.isPlusNum(beforeText) && CheckUtil.isPlusNum(afterText)) {
			if (BigDecimal.ZERO.compareTo(new BigDecimal(afterText)) == 0) {
				return beforeText;
			} else {
				return value;
			}
		} else {
			return value;
		}
	}

	/**
	 * 獲取最后分割符后面的字符串
	 * 
	 * @param text
	 * @param split
	 * @return
	 */
	public static String getAfterTextLastDelimiter(String text, String split) {
		if (text == null)
			return null;
		if ("".equals(text))
			return "";
		int lastIndex = text.lastIndexOf(split);
		if (lastIndex != -1) {
			text = text.substring(lastIndex + 1);
		}
		return text;
	}

	/**
	 * 獲取map中的值為map對象
	 * 
	 * @param map
	 * @param key
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static synchronized <K, V> Map<K, V> getValueForMap(Map<K, V> map, String key) {
		Map<K, V> valueMap = null;
		Object value = null;
		if (map == null) {
			valueMap = new HashMap<K, V>();
		} else {
			value = map.get(key);
			valueMap = value instanceof Map ? (Map<K, V>) value : new HashMap<K, V>();
		}
		return valueMap;
	}

	/**
	 * 獲取map中的值為list.map對象
	 * 
	 * @param map
	 * @param key
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static synchronized <K, V> List<Map<K, V>> getValueForListMap(Map<K, V> map, String key) {
		List<Map<K, V>> valueListMap = null;
		Object value = null;
		if (map == null) {
			valueListMap = new ArrayList<Map<K, V>>();
		} else {
			value = map.get(key);
			valueListMap = value instanceof List ? (List<Map<K, V>>) value : new ArrayList<Map<K, V>>();
		}
		return valueListMap;
	}

	/**
	 * 獲取map中的值為list對象
	 * 
	 * @param map
	 * @param key
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static synchronized <K, V, L> List<L> getValueForList(Map<K, V> map, String key) {
		List<L> valueListMap = null;
		Object value = null;
		if (map == null) {
			valueListMap = new ArrayList<L>();
		} else {
			value = map.get(key);
			valueListMap = value instanceof List ? (List<L>) value : new ArrayList<L>();
		}
		return valueListMap;
	}

	/**
	 * list轉set
	 * 
	 * @param map
	 * @param key
	 * @return
	 */
	public static <T> Set<T> listToSet(List<T> P_coll) {
		Set<T> R_coll = new HashSet<T>();
		if (P_coll == null) {
			return R_coll;
		} else {
			for (T V_t : P_coll) {
				R_coll.add(V_t);
			}
		}
		return R_coll;
	}

	/**
	 * set轉list
	 * 
	 * @param map
	 * @param key
	 * @return
	 */
	public static <T> List<T> setToList(Set<T> P_coll) {
		List<T> R_coll = new ArrayList<T>();
		if (P_coll == null) {
			return R_coll;
		} else {
			for (T V_t : P_coll) {
				R_coll.add(V_t);
			}
		}
		return R_coll;
	}

	/**
	 * 判斷兩數組相同
	 * 
	 * @param a1
	 * @param a2
	 * @return
	 */
	public static boolean arrayEquals(Object[] a1, Object[] a2) {
		if (a1 == null) {
			return a2 == null || a2.length == 0;
		}

		if (a2 == null) {
			return a1.length == 0;
		}

		if (a1.length != a2.length) {
			return false;
		}

		for (int i = 0; i < a1.length; i++) {
			if (a1[i] != a2[i]) {
				return false;
			}
		}

		return true;
	}

	/**
	 * 判斷兩集合是否相同
	 * 
	 * @param list1
	 * @param list2
	 * @return
	 */
	public static boolean collEquals(Collection<Object> list1, Collection<Object> list2) {
		// 個數相同
		boolean ok = true;
		boolean isCheck = false;
		quit: while (list1.size() != 0 && list1.size() == list2.size()) {
			isCheck = true;
			for (Object value : list1) {
				if (list2.contains(value)) {
					list2.remove(value);
					list1.remove(value);
					break;
				} else {
					ok = false;
					break quit;
				}
			}
		}
		// if (isCheck && ok) {
		// System.out.println("集合相同");
		// } else {
		// System.out.println("集合不相同");
		// }
		return isCheck && ok;
	}

	/**
	 * 判斷兩集合是否相同
	 * 
	 * @param list1
	 * @param list2
	 * @return
	 */
	public static boolean collEqualsStr(Collection<String> list1, Collection<String> list2) {
		List<Object> list1Obj = new ArrayList<Object>();
		List<Object> list2Obj = new ArrayList<Object>();
		for (String v : list1) {
			list1Obj.add(v);
		}
		for (String v : list2) {
			list2Obj.add(v);
		}
		return collEquals(list1Obj, list2Obj);
	}

	/**
	 * 首字母變小寫
	 * 
	 * @param text
	 *            字符串
	 * @return 以第一個字母小寫其他不變
	 */
	public static String firstLowerCase(String text) {
		return text.substring(0, 1).toLowerCase() + text.substring(1, text.length());
	}

	/**
	 * 首字母變大寫
	 * 
	 * @param text
	 * @return
	 */
	public static String firstUpperCase(String text) {
		return text.substring(0, 1).toUpperCase() + text.substring(1, text.length());
	}

	/**
	 * 以分割符split首字母變大寫(默認第一個字符不改變大寫)
	 * 
	 * @param text
	 *            校驗字符串
	 * @param split
	 *            分割符
	 * @return 轉換后的結果
	 */
	public static String upperCaseSplit(String text, String split) {
		return upperCaseSplit(text, split, false);
	}

	/**
	 * 以分割符split首字母變大寫
	 * 
	 * @param text
	 *            校驗字符串
	 * @param split
	 *            分割符
	 * @param first
	 *            是否首字母大寫
	 * @return 轉換后的結果
	 */
	public static String upperCaseSplit(String text, String split, boolean first) {
		String[] texts = split(text, split);
		String newText = "";
		for (int i = 0; i < texts.length; i++) {
			String str = texts[i];
			if (CheckUtil.isNull(str)) {
				continue;
			}
			if (i == 0) {
				if (first) {
					newText += firstUpperCase(str);
				} else {
					newText += str;
				}
			} else {
				newText += firstUpperCase(str);
			}
		}
		return newText;
	}

	/**
	 * 轉換數據庫字段為java屬性
	 * 
	 * @param text
	 *            數據庫字段名
	 * @author 張軍
	 * @date 2015-11-03 21:59:00
	 * @modifiyNote
	 * @version 1.0
	 * @return
	 */
	public static String convertDbToJavaField(String text) {
		return JavaUtil.upperCaseSplit(JavaUtil.toLowerCase(text), "_");
	}

	/**
	 * 改變第一行bug BufferedReader.readLine()讀取第一行會出現bug,首行第一個字符會是一個空字符  line = br.readLine(); line = readFirstLine(line); 文件保存為UTF-8格式,會出現此問題(例如:文件內容第一行以#號開頭) stream/a.txt不正常,b.txt正常
	 * 
	 * @param line
	 * @return
	 * @author zhangjun
	 */
	public static String readFirstLine(String line) {
		if (line == null)
			return null;
		line = line.trim();
		if ("".equals(line)) {
			return line;
		}
		char s = line.charAt(0);
		int hc = String.valueOf(s).hashCode();
		if (hc == 65279) {
			if (line.length() > 1) {
				line = line.substring(1);
			} else {
				line = "";
			}
		}
		return line;
	}

	/**
	 * 隨機數
	 * 
	 * @author zhangjun
	 * 
	 */
	public static class RandomUtil {
		private static Random RD = null;
		static {
			RD = new Random();
		}

		/**
		 * 獲取[s-e]之間的隨機數
		 * 
		 * @param s
		 *            開始數字
		 * @param e
		 *            結束數字
		 * @return 隨機數
		 */
		public static int getInt(int s, int e) {
			return RD.nextInt(e - s + 1) + s;
		}
	}

	/**
	 * 獲取手機號去掉+86
	 *
	 * @param P_mobile
	 *            手機號
	 * @return
	 */
	public static String getMobile(String P_mobile) {
		if (CheckUtil.isNull(P_mobile)) {
			return "";
		}
		if (P_mobile.startsWith("+86")) {
			// 去除
			P_mobile = P_mobile.substring(3);
		}
		return P_mobile;
	}

	/**
	 * 字符串轉set
	 *
	 * @param value
	 *            字符串
	 * @return
	 */
	public static Set<String> strToSet(String value) {
		return strToSet(value, ",");
	}

	/**
	 * 字符串轉list
	 *
	 * @param value
	 *            字符串
	 * @return
	 */
	public static List<String> strToList(String value) {
		return strToList(value, ",");
	}

	/**
	 * 字符串轉set
	 *
	 * @param value
	 *            字符串
	 * @param split
	 *            分割符
	 * @return
	 */
	public static Set<String> strToSet(String value, String split) {
		Set<String> V_toIds = new HashSet<>();
		String[] R_sysIdsAry = JavaUtil.split(value, split);
		for (String VF_value : R_sysIdsAry) {
			V_toIds.add(VF_value);
		}
		return V_toIds;
	}

	/**
	 * 字符串轉list
	 *
	 * @param value
	 *            字符串
	 * @param split
	 *            分割符
	 * @return
	 */
	public static List<String> strToList(String value, String split) {
		List<String> V_toIds = new ArrayList<>();
		String[] R_sysIdsAry = JavaUtil.split(value, split);
		for (String VF_value : R_sysIdsAry) {
			V_toIds.add(VF_value);
		}
		return V_toIds;
	}
}
/**
 * @Description  TestJavaUtil.java
 * @author 張軍
 * @date 2022年3月6日 上午10:48:53
 * @version V1.0
 */
package test.java;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import zj.check.util.CheckUtil;
import zj.java.util.JavaUtil;

/**
 * @author 張軍
 * @date 2022年3月6日 上午10:48:53
 * @version V1.0
 */
public class TestJavaUtil {
	@Test
	public void 分割email地址轉換成一行() {
		String 前臺傳的email值 = "";
		for (int a = 1; a <= 5; a++) {
			if (CheckUtil.isNotNull(前臺傳的email值)) {
				前臺傳的email值 += "\r\n";
			}
			前臺傳的email值 += "zhangjun" + a + "@126.com";
		}
		System.out.println("前臺傳的email值:\n" + 前臺傳的email值);
		String 分割后結果 = JavaUtil.emailSplitToOneline(前臺傳的email值);
		System.out.println("分割后結果:\n" + 分割后結果);
	}

	@Test
	public void 判斷系統() {
		System.out.println("是否是windows:" + JavaUtil.isWindows());
		System.out.println("是否是mac系統:" + JavaUtil.isMac());
	}

	@Test
	public void 中文數字轉數字() {
		System.out.println("中文數字轉數字:" + JavaUtil.getIntegerByStr("六萬七千三百八十二"));
		System.out.println("中文數字轉數字:" + JavaUtil.getIntegerByStr("五千零一"));
	}

	@Test
	public void 數字轉大寫() {
		System.out.println("數字轉大寫:" + JavaUtil.numToCnChar("1234567890"));
	}

	@Test
	public void 數字轉大寫日期() {
		System.out.println("4位數字年:" + JavaUtil.numToCnCharDate(2022));
		System.out.println("2位數字月或日:" + JavaUtil.numToCnCharDate(12));
		System.out.println("1位數字月或日:" + JavaUtil.numToCnCharDate(9));
	}

	@Test
	public void 數值轉換為中文字符串() {
		System.out.println("數值轉換為中文字符串:" + JavaUtil.numToCn(20221231));
		System.out.println("第2個參數是否口語化。例如12轉換為'十二'而不是'一十二'。:" + JavaUtil.numToCnCharDate(12));
	}

	@Test
	public void 獲取集合差異() {
		List<String> l1 = new ArrayList<>();
		l1.add("a");
		l1.add("b");
		l1.add("c");
		l1.add("d");
		l1.add("e");
		List<String> l2 = new ArrayList<>();
		l2.add("a1");
		l2.add("b");
		l2.add("c1");
		l2.add("d");
		l2.add("e1");
		System.out.println("獲取集合差異:" + JavaUtil.diffColl(l1, l2));
	}

	@Test
	public void 數字格式化() {
		System.out.println("數字格式化:" + JavaUtil.covertToNumSplit(1234567890));
	}

	@Test
	public void 轉為大數字() {
		System.out.println("轉為大數字:" + JavaUtil.covertBigDecimal(1234567890));
		System.out.println("轉為大數字:" + JavaUtil.covertBigDecimal("1234567890123456789").setScale(5, BigDecimal.ROUND_HALF_UP));
	}

	@Test
	public void 獲取in的字符串() {
		List<String> l2 = new ArrayList<>();
		l2.add("a1");
		l2.add("b");
		l2.add("c1");
		l2.add("d");
		l2.add("e1");
		System.out.println("獲取in的字符串: in(" + JavaUtil.sqlInStr(l2) + ")");
	}

	@Test
	public void 轉換文件大小() {
		System.out.println("轉換文件大小為B、KB、MB、GB:" + JavaUtil.convertFileSize(123456));
		System.out.println("轉換文件大小為B、KB、MB、GB:" + JavaUtil.convertFileSize(1234567890));
	}

	@Test
	public void 深度拷貝list數據() {
		List<String> 源集合 = new ArrayList<>();
		源集合.add("a");
		源集合.add("b");
		源集合.add("c");
		源集合.add("d");
		源集合.add("e");
		List<String> 目標集合 = JavaUtil.deepCopy(源集合);
		源集合.remove(0);
		源集合.remove(1);
		System.out.println("源集合:" + 源集合);
		System.out.println("移除src里的元素,dest元素不會發生變化");
		System.out.println("目標集合:" + 目標集合);
	}

	@Test
	public void 合并多個數組() {
		String[] 數組1 = new String[] { "a", "b", "c" };
		String[] 數組2 = new String[] { "d", "e", "f" };
		String[] 數組3 = new String[] { "11", "22", "33" };
		System.out.println("數組1:" + Arrays.toString(數組1));
		System.out.println("數組2:" + Arrays.toString(數組2));
		System.out.println("數組3...n:" + Arrays.toString(數組3));
		System.out.println("合并N個數組:" + Arrays.toString(JavaUtil.concatArrayAll(數組1, 數組2, 數組3)));
	}

	@Test
	public void 按實際字符分割字符串() {
		String 字符串 = "a.b.c.d.e";
		System.out.println("按實際字符分割字符串:" + Arrays.toString(JavaUtil.split(字符串, ".")));
	}

	@Test
	public void LIST轉數組() {
		List<String> 源集合 = new ArrayList<>();
		源集合.add("a");
		源集合.add("b");
		源集合.add("c");
		源集合.add("d");
		源集合.add("e");
		System.out.println("LIST轉數組:" + Arrays.toString(JavaUtil.listToArray(源集合, String.class)));
	}

	@Test
	public void 獲取最大長度文字() {
		System.out.println("獲取最大長度文字:" + JavaUtil.getMaxText("獲取最大長度文字", 3));
	}

	@Test
	public void 去除數組中為null或空的值() {
		String[] 數組1 = new String[] { "a", "b", "c", "", "", null, "\n", "666666666" };
		System.out.println("去除數組前的值:" + Arrays.toString(數組1));
		System.out.println("去除數組中為null或空的值:" + Arrays.toString(JavaUtil.aryTrimValue(數組1)));
	}

	@Test
	public void 提取字符串中的整數字() {
		System.out.println("提取字符串:" + "我是123中456國7890結束");
		System.out.println("提取字符串中的整數字:" + JavaUtil.conversionStringToNum("我是123中456國7890結束"));
	}

	@Test
	public void 提取字符串中的整數字帶小數或正負數() {
		System.out.println("提取字符串:" + "我是-123中456國7.890結束");
		System.out.println("提取字符串中的整數字帶小數或正負數:" + JavaUtil.conversionStringToNumber("我是-123中456國7.890結束"));
	}

	@Test
	public void 固定集合元素() {
		int count = 10;
		List<String> 原集合值 = new ArrayList<String>();
		for (int i = 0; i < count; i++) {
			原集合值.add("值:" + i);
		}
		System.out.println("原集合值:" + 原集合值);
		List<List<String>> 固定批量值 = JavaUtil.getBatchList(原集合值, 3);
		System.out.println("固定集合元素,每個集合3個元素:" + 固定批量值);
	}

	@Test
	public void 固定批量集合() {
		int count = 10;
		List<String> 原集合值 = new ArrayList<String>();
		for (int i = 0; i < count; i++) {
			原集合值.add("值:" + i);
		}
		System.out.println("原集合值:" + 原集合值);
		List<List<String>> 固定批量值 = JavaUtil.getFixedBatchList(原集合值, 3);
		System.out.println("固定批量集合,3個批次元素:" + 固定批量值);
	}

	@Test
	public void 根據頁碼條數計算多少頁() {
		System.out.println("總條數:" + 10);
		System.out.println("每頁顯示條數:" + 3);
		System.out.println("根據頁碼條數計算多少頁:" + JavaUtil.calcPageCount(10, 3));
	}

	@Test
	public void 獲取最后分割符前面的字符串() {
		String 字符串 = "獲取最后分割符#前面的字符串";
		System.out.println("字符串:" + 字符串);
		System.out.println("獲取最后分割符#前面的字符串:" + JavaUtil.getBeforeTextLastDelimiter(字符串, "#"));
	}

	@Test
	public void 獲取最后分割符后面的字符串() {
		String 字符串 = "獲取最后分割符#前面的字符串";
		System.out.println("字符串:" + 字符串);
		System.out.println("獲取最后分割符#前面的字符串:" + JavaUtil.getAfterTextLastDelimiter(字符串, "#"));
	}

	@Test
	public void 去除小數點后的字符() {
		System.out.println("去除前字符:123.12345000");
		System.out.println("去除小數點后為0的字符:" + JavaUtil.getIsNumValue(123.12345000));
		System.out.println("去除前字符:12345678.00000");
		System.out.println("去除小數點后為0的字符:" + JavaUtil.getIsNumValue("12345678.00000"));
	}

	@Test
	public void 獲取map中的值為map對象() {
		Map<String, Map<String, Object>> map = new HashMap<>();
		Map<String, Object> value = new HashMap<>();
		value.put("test", "我是值a");
		map.put("a", value);
		value = new HashMap<>();
		value.put("test", "我是值b");
		map.put("b", value);
		value = new HashMap<>();
		value.put("test", "我是值c");
		map.put("c", value);
		System.out.println("map:" + map);
		System.out.println("獲取map中key為b的值為map對象:" + JavaUtil.getValueForMap(map, "b"));
		System.out.println("獲取map中key為d的值為map對象:" + JavaUtil.getValueForMap(map, "d"));
	}

	@Test
	public void 獲取map中的值為list_map對象() {
		Map<String, List<Map<String, Object>>> map = new HashMap<>();
		List<Map<String, Object>> values = new ArrayList<>();
		
		Map<String, Object> value = new HashMap<>();
		values.add(value);
		value.put("test", "我是值a");
		map.put("a", values);

		value = new HashMap<>();
		values.add(value);
		value.put("test", "我是值b");
		map.put("b", values);

		value = new HashMap<>();
		values.add(value);
		value.put("test", "我是值c");
		map.put("c", values);

		System.out.println("map:" + map);
		System.out.println("獲取map中的值為list.map對象:" + JavaUtil.getValueForListMap(map, "b"));
		System.out.println("獲取map中的值為list.map對象:" + JavaUtil.getValueForListMap(map, "d"));
	}
}
map:{b=[{test=我是值a}, {test=我是值b}, {test=我是值c}], c=[{test=我是值a}, {test=我是值b}, {test=我是值c}], a=[{test=我是值a}, {test=我是值b}, {test=我是值c}]}
獲取map中的值為list.map對象:[{test=我是值a}, {test=我是值b}, {test=我是值c}]
獲取map中的值為list.map對象:[]
map:{b={test=我是值b}, c={test=我是值c}, a={test=我是值a}}
獲取map中key為b的值為map對象:{test=我是值b}
獲取map中key為d的值為map對象:{}
原集合值:[值:0, 值:1, 值:2, 值:3, 值:4, 值:5, 值:6, 值:7, 值:8, 值:9]
固定批量集合,3個批次元素:[[值:0, 值:1, 值:2, 值:3], [值:4, 值:5, 值:6, 值:7], [值:8, 值:9]]
獲取集合差異:[e1, e, c1, c, a, a1]
原集合值:[值:0, 值:1, 值:2, 值:3, 值:4, 值:5, 值:6, 值:7, 值:8, 值:9]
固定集合元素,每個集合3個元素:[[值:0, 值:1, 值:2], [值:3, 值:4, 值:5], [值:6, 值:7, 值:8], [值:9]]
數字格式化:1,234,567,890
數字轉大寫:一二三四五六七八九零
數組1:[a, b, c]
數組2:[d, e, f]
數組3...n:[11, 22, 33]
合并N個數組:[a, b, c, d, e, f, 11, 22, 33]
提取字符串:我是123中456國7890結束
提取字符串中的整數字:1234567890
數值轉換為中文字符串:二千零二十二萬一千二百三十一
第2個參數是否口語化。例如12轉換為'十二'而不是'一十二'。:十二
4位數字年:二零二二
2位數字月或日:十二
1位數字月或日:九
提取字符串:我是-123中456國7.890結束
提取字符串中的整數字帶小數或正負數:-1234567.890
轉為大數字:1234567890
轉為大數字:1234567890123456789.00000
是否是windows:true
是否是mac系統:false
LIST轉數組:[a, b, c, d, e]
前臺傳的email值:
zhangjun1@126.com
zhangjun2@126.com
zhangjun3@126.com
zhangjun4@126.com
zhangjun5@126.com
分割后結果:
zhangjun1@126.com;zhangjun2@126.com;zhangjun3@126.com;zhangjun4@126.com;zhangjun5@126.com
字符串:獲取最后分割符#前面的字符串
獲取最后分割符#前面的字符串:前面的字符串
字符串:獲取最后分割符#前面的字符串
獲取最后分割符#前面的字符串:獲取最后分割符
獲取in的字符串: in('a1','b','c1','d','e1')
獲取最大長度文字:獲取最...
去除前字符:123.12345000
去除小數點后為0的字符:123.12345
去除前字符:12345678.00000
去除小數點后為0的字符:12345678
去除數組前的值:[a, b, c, , , null, 
, 666666666]
去除數組中為null或空的值:[a, b, c, 666666666]
按實際字符分割字符串:[a, b, c, d, e]
轉換文件大小為B、KB、MB、GB:120.56KB
轉換文件大小為B、KB、MB、GB:1.15GB
中文數字轉數字:67382
中文數字轉數字:5001
總條數:10
每頁顯示條數:3
根據頁碼條數計算多少頁:4
源集合:[b, d, e]
移除src里的元素,dest元素不會發生變化
目標集合:[a, b, c, d, e]

更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!?。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产精品国产午夜免费福利看 | 国产成人免费视频网站高清观看视频 | 香蕉香蕉国产片一级一级毛片 | 久久一本日韩精品中文字幕屁孩 | 国产欧美日本 | 国产高清美女一级毛片 | 国产精品国产三级国产aⅴ入口 | 成人国产精品免费视频不卡 | 九九99国产精品视频 | 99黄色网 | 天天色综合天天 | xxx 日本韩国| 国产精品久久久久久久午夜 | 国产一区二区精品 | 一级寡妇乱色毛片全18 | 先锋影音资源网站 | 免费在线一区二区 | 国产欧美日韩精品一区二 | 日韩精品 电影一区 亚洲 | 五月婷婷 六月丁香 | 91视频网 | 男女久久久 | 亚洲天堂欧美在线 | 四虎1515hhhcom | 中国欧美日韩一区二区三区 | 精品无人乱码一区二区三区 | 在线精品国内外视频 | 国产精品国产三级国产aⅴ无密码 | 色爱影院 | 免费看特黄特黄欧美大片 | 爱草在线 | 久久草资源费视频在线观看 | 国产精品高清在线 | 日韩精品 电影一区 亚洲 | 成人黄色短视频在线观看 | 98香蕉草草视频在线精品看 | 亚洲国产精品热久久 | 久久国产精品视频 | 久久中文字幕美谷朱里 | 日本高清免费不卡在线播放 | 国产五月色婷婷六月丁香视频 |