- /**
- * 版權所有:華信設計
- * 項目名稱:上海移動項目第三期
- * 建立者: Zhou Danyong
- * 建立日期: 2010-09-30
- * 檔案說明: ArrayList 功能類
- * 最近修改者:Zhou Danyong
- * 最近修改日期:2010-12-23
- */
- package com.huaxin.shpm3.common.util;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import com.huaxin.util.StringTool;
- /**
- * Tool for ArrayList.
- * Which inlcuded some functions like converts an Array to a comma-delimited String, as so on, you can append you
- * function in you your, make a stamp meanwhile.
- *
- * @author Zhou Danyong 2010-11-01
- * @since 1.1
- */
- @SuppressWarnings("unchecked")
- public class ArrayListUtil extends StringTool {
- /**
- * Delete the truble item from the list, and convert the reslut as an SQL String. Which can
- * used in SQL directly.
- *
- * @author Zhou Danyong 2010-11-01
- * @param list
- * @param trouble
- * @return safeString
- * @since 1.0
- */
- public static String doKickOutStringThenConvertListToAnSQLString(ArrayList list, String trouble) {
- String wholeString = "",safeString = "";
- //1.Change List to SQL String
- for (Iterator iterator = list.iterator(); iterator.hasNext();) {
- HashMap map = (HashMap) iterator.next();
- wholeString +="'"+map.get("AAA")+"'";
- if (iterator.hasNext()) {
- wholeString += ",";
- }
- }
- list = null;
- //2.Kick out self
- //2.1.middle position
- if(StringUtil.countOccurrencesOf(wholeString,"'"+trouble+"'"+",")>0){
- safeString = StringUtil.delete(wholeString, "'"+trouble+"'"+",");
- //2.2.end position
- }else if(StringUtil.countOccurrencesOf(wholeString,trouble)>0){
- safeString = StringUtil.delete(wholeString, ","+"'"+trouble+"'");
- }
- //3.Return
- return safeString;
- }
- /**
- * Imitate StringBuffer's append operation.
- * <p>
- * Appends the specified <tt>ArrayList</tt> to the target one.
- * </p>
- *
- * @author Zhou Danyong 2010-12-23
- * @param targetList, appendList.
- * @return a expend ArrayList.
- * @since 1.0
- */
- public static ArrayList appendToArrayList(ArrayList targetList,ArrayList appendList){
- //Type check
- if (!ArrayList.class.isInstance(targetList)) {
- throw new RuntimeException("targetList must be ArrayList.");
- }
- if (!ArrayList.class.isInstance(appendList)) {
- throw new RuntimeException("appendList must be ArrayList.");
- }
- //Append target
- ArrayList list = new ArrayList();
- list.addAll(targetList);
- int oldCapacity = appendList.size();
- if (oldCapacity>10) {
- int newCapacity = (oldCapacity * 3)/2 + 1;
- list.ensureCapacity(newCapacity);
- }
- //Append
- int index = targetList.size();
- HashMap map = new HashMap();
- for (int i = 0; i < appendList.size(); i++) {
- map = (HashMap) appendList.get(i);
- list.add(index++, map);
- }
- return list;
- }
- }