Java tutorial
/** * Copyright 2010 CssWeb Microsystems, Inc. All rights reserved. * CssWeb PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * @(#)TradeUtil.java ?02:12:03 2010-9-14 */ package com.cssweb.android.trade.util; import java.math.BigDecimal; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.content.Context; import android.util.Log; import com.cssweb.android.common.CssIniFile; import com.cssweb.android.common.DateTool; import com.cssweb.android.connect.ConnPool; import com.cssweb.android.session.TradeUser; import com.cssweb.android.trade.service.FundService; import com.cssweb.android.trade.service.TradeService; import com.cssweb.android.util.ActivityUtil; import com.cssweb.android.util.CssStock; import com.cssweb.android.util.CssStockFund; /** * ? * * @author hujun * @version 1.0 * @see * @since 1.0 */ public class TradeUtil { public static final String SPLIT = "&"; public static final String g_pubKey_old = "29dlo*%AO+3i16BaweTw.lc!)61K{9^5"; public static final String g_pubKey = "29dlo*%AO+3i16BaweTw.lc!)61K{9^5";//30dlo*%AO+3i18BaweTw.lc!)61K{9^5 /*** * @author andy * */ public static final String MARKET_SHA = "SH"; public static final String MARKET_SHB = "HB"; public static final String MARKET_SZA = "SZ"; public static final String MARKET_SZB = "SB"; public static final String MARKET_TA = "TA"; public static final String MARKET_TU = "TU"; /** * ?? * @param csswebtype * @param funcid * @return * @throws JSONException */ public static String getGlobalRequest(String csswebtype, String funcid) throws JSONException { StringBuffer sb = new StringBuffer(); sb.append("funcid=" + funcid + SPLIT); sb.append("cssweb_type=" + csswebtype + SPLIT); sb.append("isSafe=0" + SPLIT); sb.append("clientip=" + TradeUser.getInstance().getClientip() + SPLIT); sb.append("cssweb_codekey=1.0" + SPLIT); sb.append("cssweb_clienttype=1" + SPLIT); //??? if (TradeUser.getInstance().getCustid() == null) { sb.append("FID_KHH=" + SPLIT); } else { sb.append("FID_KHH=" + TradeUser.getInstance().getCustid() + SPLIT); } return sb.toString(); } public static String getMoneyName(String moneytype) { String moneyName = ""; if (moneytype.equals("RMB")) { moneyName = "?"; } else if (moneytype.equals("USD")) { moneyName = ""; } else if (moneytype.equals("HKD")) { moneyName = "?"; } return moneyName; } public static String getFundsType(String zzhbz) { String fundsType = ""; if ("1".equals(zzhbz)) { fundsType = "??"; } else { fundsType = "??"; } return fundsType; } public static String getResult(String req) { return req.replace("\\+", "\\*"); } public static String checkResult(JSONObject j) throws JSONException { String res = null; if (j == null) { res = "-1"; } else if ("error".equals(j.getString("cssweb_code"))) { res = j.getString("cssweb_msg"); } return res; } public static String getTradeName(char n) { String name = ""; switch (n) { case 'B': name = "?"; break; case 'a': name = ""; break; case 'b': name = ""; break; case 'c': name = "?"; break; case 'd': name = ""; break; case 'e': name = "?"; break; case 'q': name = "?"; break; case 'S': name = "??"; break; case 'f': name = "?"; break; case 'g': name = "?"; break; case 'h': name = "??"; break; case 'i': name = "?"; break; case 'j': name = "??"; break; case 'r': name = "?"; break; case 'G': name = ""; break; case 'H': name = ""; break; case '3': name = ""; break; case '4': name = ""; break; case '5': name = ""; break; case '7': name = "?"; break; default: name = "--"; break; } return name; } /** * ? */ public static String dealFundTrdid(int trdid) { String reStr = "-"; switch (trdid) { case 24001: reStr = ""; break; case 24002: reStr = ""; break; case 24003: reStr = "?"; break; case 24101: reStr = ""; break; case 24103: reStr = "?"; break; case 24020: reStr = ""; break; case 24022: reStr = ""; break; case 24024: reStr = ""; break; case 24029: reStr = "?"; break; case 24129: reStr = "?"; break; case 24120: reStr = ""; break; case 24122: reStr = ""; break; case 24124: reStr = ""; break; case 24152: reStr = "?"; break; case 24153: reStr = "?"; break; case 24052: reStr = "?"; break; case 24053: reStr = "?"; break; case 24046: reStr = "??"; break; case 24146: reStr = "??"; break; case 24043: reStr = "?"; break; case 24143: reStr = "?"; break; case 24036: reStr = "?"; break; case 24037: reStr = "?"; break; case 24038: reStr = "?"; break; case 24136: reStr = "?"; break; case 24137: reStr = "?"; break; case 24138: reStr = "?"; break; } return reStr; } /*** * ?? ?? */ public static String getFlagName(int flag, String cancelFlag) { String flagName = "-"; switch (flag) { case 1: if ("W".equals(cancelFlag)) //? flagName = ""; else flagName = ""; break; case 2: if ("W".equals(cancelFlag)) //? flagName = "?"; else flagName = "?"; break; case 3: flagName = ""; break; case 4: flagName = "?"; break; case 5: flagName = "?"; break; case 6: flagName = ""; break; case 7: flagName = ""; break; case 8: flagName = "??"; break; case 9: flagName = ""; break; case 10: flagName = ""; break; case 11: flagName = ""; break; case 12: flagName = ""; break; case 13: flagName = ""; break; case 14: flagName = "?"; break; case 15: flagName = ""; break; case 16: flagName = "?"; break; case 17: flagName = ""; break; case 18: flagName = ""; break; case 19: flagName = ""; break; case 20: flagName = "?"; break; case 21: flagName = "?"; break; case 22: flagName = "?"; break; case 23: flagName = ""; break; case 24: flagName = "?"; break; case 25: flagName = ""; break; case 26: flagName = ""; break; case 27: flagName = ""; break; case 28: flagName = ""; break; case 29: flagName = "ETF"; break; case 30: flagName = "ETF"; break; case 31: flagName = "??"; break; case 32: flagName = ""; break; case 33: flagName = ""; break; case 34: flagName = "?"; break; case 35: flagName = "?"; break; case 37: flagName = ""; break; case 38: flagName = ""; break; case 41: flagName = ""; break; case 42: flagName = ""; break; case 43: flagName = ""; break; case 44: flagName = ""; break; case 45: flagName = ""; break; case 46: flagName = "?"; break; case 50: flagName = "???"; break; case 51: flagName = "??"; break; case 52: flagName = "??"; break; case 55: flagName = "??"; break; case 56: flagName = "???"; break; case 57: flagName = ""; break; case 58: flagName = "?"; break; case 59: flagName = ""; break; case 60: flagName = "?"; break; case 61: flagName = "?"; break; case 62: flagName = "?"; break; case 63: flagName = "??"; break; case 66: flagName = "??"; break; case 67: flagName = "???"; break; case 76: flagName = "??"; break; case 77: flagName = "?"; break; case 80: flagName = ""; break; case 81: flagName = ""; break; case 82: flagName = ""; break; case 83: flagName = ""; break; case 94: flagName = "?"; break; case 95: flagName = ""; break; case 96: flagName = "??"; break; case 97: flagName = ""; break; case 98: flagName = "?"; break; case 99: flagName = ""; break; } return flagName; } /** * ? ??? */ public static String dealOrderType(int mt) { String reStr = "-"; switch (mt) { case 0: reStr = "?"; break; case 1: reStr = "???"; break; case 2: reStr = "???"; break; case 101: reStr = ""; break; case 102: reStr = ""; break; case 103: reStr = "????"; break; case 104: reStr = "???"; break; case 105: reStr = "???"; break; } return reStr; } /** * ? */ public static String dealBankTranType(String mt) { String reStr = "-"; int order = 0; if (mt == null || mt.trim().equals("")) { order = 0; } else { order = Integer.parseInt(mt); } switch (order) { case 1: reStr = "?"; break; case 1024: reStr = ""; break; case 128: reStr = "?"; break; case 16: reStr = ""; break; case 16384: reStr = "?"; break; case 2: reStr = "?"; break; case 2048: reStr = ""; break; case 256: reStr = "?"; break; case 32: reStr = "?"; break; case 32768: reStr = ""; break; case 4: reStr = "?"; break; case 4096: reStr = "?"; break; case 512: reStr = "???"; break; case 64: reStr = "?"; break; case 8: reStr = ""; break; case 8192: reStr = "?"; break; } return reStr; } /** * * @return * */ public static String getBankName(String bankCode) { // String[] bankList = ; String bankName = ""; String st = "ZHCG:,GHCG:,ZSCG:,GDCG:,JHCG:,XYCG:,NHCG:,JTCG:,NJYH:?,PFYH:?,SFZH:?,SKZH:,SKZS:,GZZH:,FZZH:?,ZHWB:?,NJZS:?,SHCG:,MSCG:,HXCG:??,GFYH:?,ZXYH,:"; // ja. String[] it = st.split(","); for (int i = 0; i < it.length; i++) { String[] keyValue = it[i].split(":"); String key = keyValue[0]; String value = keyValue[1]; if (key.equals(bankCode)) { bankName = value; break; } } return bankName; } /** * ???? * @param mark * @return markname * @author hujun */ public static String getMarkName(String mark) { String markname = ""; if (mark.equals("SH")) { markname = "A"; } else if (mark.equals("SZ")) { markname = "A"; } else if (mark.equals("HB")) { markname = "B"; } else if (mark.equals("SB")) { markname = "B"; } else if (mark.equals("TU")) { markname = "U"; } else if (mark.equals("TA")) { markname = "A"; } // switch(mark) { // case '1':markname = "A";break; // case '0':markname = "A";break; // case '6':markname = "?A";break; // case '7':markname = "?B";break; // case '9':markname = "";break; // case 'A':markname = "?";break; // case '3':markname = "B";break; // case '2':markname = "B";break; // case 'J':markname = "?";break; // } return markname; } /** * */ public static String getFundavl() throws JSONException { StringBuffer sb = new StringBuffer(); sb.append("FID_BZ=" + TradeUtil.SPLIT); sb.append("FID_EXFLG=1"); JSONObject quoteData = ConnPool.sendReq("GET_FUNDS", "303002", sb.toString()); String resStr = TradeUtil.checkResult(quoteData); if (resStr == null) { JSONArray jArr = (JSONArray) quoteData.getJSONArray("item"); for (int i = 0; i < jArr.length() - 1; i++) { JSONObject jsonobj = jArr.getJSONObject(i); if ("1".equals(jsonobj.getString("FID_ZZHBZ"))) { String moneytype = jsonobj.getString("FID_BZ"); if ("RMB".equals(moneytype)) { TradeUser.getInstance() .setFundavlRMB(TradeUtil.formatNum(jsonobj.getString("FID_ZHYE"), 2)); TradeUser.getInstance() .setEnablefundavlRMB(TradeUtil.formatNum(jsonobj.getString("FID_KYZJ"), 2)); } else if ("USD".equals(moneytype)) { TradeUser.getInstance().setFundavlUS(TradeUtil.formatNum(jsonobj.getString("FID_ZHYE"), 3)); TradeUser.getInstance() .setEnablefundavlUS(TradeUtil.formatNum(jsonobj.getString("FID_KYZJ"), 3)); } else if ("HKD".equals(moneytype)) { TradeUser.getInstance().setFundavlHK(TradeUtil.formatNum(jsonobj.getString("FID_ZHYE"), 3)); TradeUser.getInstance() .setEnablefundavlHK(TradeUtil.formatNum(jsonobj.getString("FID_KYZJ"), 3)); } } } } return TradeUser.getInstance().getEnablefundavlRMB(); } // public static String getFundavlAll() throws JSONException { // double zhyeRMB = 0l; // double zhyeHKD = 0l; // double zhyeUSD = 0l; // double kyzjRMB = 0l; // double kyzjHKD = 0l; // double kyzjUSD = 0l; // StringBuffer sb = new StringBuffer(); // sb.append("FID_BZ=" + TradeUtil.SPLIT); // sb.append("FID_EXFLG=1"); // JSONObject quoteData = ConnPool.sendReq("GET_FUNDS", "303002", sb.toString()); // String resStr = TradeUtil.checkResult(quoteData); // if(resStr == null){ // JSONArray jArr = (JSONArray)quoteData.getJSONArray("item"); // for(int i=0;i<jArr.length()-1;i++){ // JSONObject jsonobj = jArr.getJSONObject(i); // String bz = jsonobj.getString("FID_BZ"); // double ye = Double.parseDouble(jsonobj.getString("FID_ZHYE")); // double ky = Double.parseDouble(jsonobj.getString("FID_KYZJ")); // if("RMB".equals(bz)){ // zhyeRMB += ye; // kyzjRMB += ky; // }else if("HKD".equals(bz)){ // zhyeHKD += ye; // kyzjHKD += ky; // }else if("USD".equals(bz)){ // zhyeUSD += ye; // kyzjUSD += ky; // } // TradeUser.getInstance().setFundavlRMB(TradeUtil.formatNum(zhyeRMB+"", 2)); // TradeUser.getInstance().setEnablefundavlRMB(TradeUtil.formatNum(kyzjRMB+"", 2)); // TradeUser.getInstance().setFundavlHK(TradeUtil.formatNum(zhyeHKD+"", 3)); // TradeUser.getInstance().setEnablefundavlHK(TradeUtil.formatNum(kyzjHKD+"", 3)); // TradeUser.getInstance().setFundavlUS(TradeUtil.formatNum(zhyeUSD+"", 3)); // TradeUser.getInstance().setEnablefundavlUS(TradeUtil.formatNum(kyzjUSD+"", 3)); // } // } // return TradeUser.getInstance().getEnablefundavlRMB(); // } //? public static String initFundData(Context context) { // new Thread() { // public void run() { String msg = ""; String openFundCompanyDate = ActivityUtil.getPreference(context, "openFundCompanyDate", ""); String openFundInfoDate = ActivityUtil.getPreference(context, "openFundInfoDate", ""); String openFundAccountDate = ActivityUtil.getPreference(context, "openFundAccountDate", ""); Log.i(">>>>>>>>?", ""); Log.i(">>>>>>>>openFundCompanyDate", openFundCompanyDate); Log.i(">>>>>>>>openFundInfoDate", openFundInfoDate); Log.i(">>>>>>>>openFundAccountDate", openFundAccountDate); String res = ""; try { // *****??******// if (!DateTool.getToday().equals(openFundCompanyDate)) { JSONObject fundCompanyData = FundService.getFundCompany(); res = TradeUtil.checkResult(fundCompanyData); if (res != null) { if (res.equals("-1")) { msg = "???"; } else { msg = res; } return msg; } else { CssIniFile.saveIni(context, 3, "fundCompany", fundCompanyData.toString()); ActivityUtil.savePreference(context, "openFundCompanyDate", DateTool.getToday()); } } //*****??******// if (!DateTool.getToday().equals(openFundInfoDate)) { JSONObject fundInfoData = FundService.getFundInfo(); res = TradeUtil.checkResult(fundInfoData); if (res != null) { if (res.equals("-1")) { msg = "???"; } else { msg = res; } return msg; } else { //?????dat JSONObject tempFundData = new JSONObject(); JSONArray tempJsonArray = new JSONArray(); JSONArray jarr = (JSONArray) fundInfoData.getJSONArray("item"); for (int i = 0; i < jarr.length() - 1; i++) { JSONObject tempObject = new JSONObject(); JSONObject jsonobj = jarr.getJSONObject(i); tempObject.put("FID_JJDM", jsonobj.getString("FID_JJDM")); tempObject.put("FID_TADM", jsonobj.getString("FID_TADM")); tempObject.put("FID_JJJC", jsonobj.getString("FID_JJJC")); tempObject.put("FID_JJQC", jsonobj.getString("FID_JJQC")); tempObject.put("FID_JJJZ", jsonobj.getString("FID_JJJZ")); tempObject.put("FID_FHFS", jsonobj.getString("FID_FHFS")); tempObject.put("FID_BZ", jsonobj.getString("FID_BZ")); tempObject.put("FID_SFFS", jsonobj.getString("FID_SFFS")); tempObject.put("FID_JYZT", jsonobj.getString("FID_JYZT")); tempObject.put("FID_JJFXDJ", jsonobj.getString("FID_JJFXDJ")); tempJsonArray.put(tempObject); } JSONObject temp = new JSONObject(); temp.put("cssweb_test : ", "0"); tempJsonArray.put(temp); tempFundData.put("cssweb_code", "success"); tempFundData.put("cssweb_type", "GET_FUND_INFO"); tempFundData.put("item", tempJsonArray); CssIniFile.saveIni(context, 4, "fundInfo", tempFundData.toString()); ActivityUtil.savePreference(context, "openFundInfoDate", DateTool.getToday()); } } // *****??******// if (!DateTool.getToday().equals(openFundAccountDate)) { JSONObject fundAccountInfoData = FundService.getFundAccountInfo(); res = TradeUtil.checkResult(fundAccountInfoData); if (res != null) { if (res.equals("-1")) { msg = "???"; } else { msg = res; } return msg; } else { CssIniFile.saveIni(context, 5, "fundAccount", fundAccountInfoData.toString()); ActivityUtil.savePreference(context, "openFundAccountDate", DateTool.getToday()); } } } catch (JSONException e) { e.printStackTrace(); } return msg; // } // }.start(); } // public static String initBanksData(Context context) { String msg = ""; String openBanksDate = ActivityUtil.getPreference(context, "openBanksDate", ""); Log.i(">>>>>>>>", ""); Log.i(">>>>>>>>openBanksDate", openBanksDate); String res = ""; try { // *****?******// if (!DateTool.getToday().equals(openBanksDate)) { JSONObject banksData = TradeService.getBanks(); res = TradeUtil.checkResult(banksData); if (res != null) { if (res.equals("-1")) { msg = "???"; } else { msg = res; } return msg; } else { CssIniFile.saveIni(context, 8, "banks", banksData.toString()); ActivityUtil.savePreference(context, "openBanksDate", DateTool.getToday()); } } } catch (JSONException e) { e.printStackTrace(); } return msg; } public String getZjzhByYhdm(String yhdm, Context context) throws JSONException { String zjzh = ""; JSONObject banksData = new JSONObject(); String filedate = ActivityUtil.getPreference(context, "openBanksDate", ""); if (!(filedate).equals(DateTool.getToday())) { //????? banksData = TradeService.getBanks(); } else { String jsonObject = CssIniFile.loadIni(context, 8, "banks"); if (null != jsonObject && !jsonObject.equals("")) { banksData = new JSONObject(jsonObject); } } JSONArray jarr = banksData.getJSONArray("item"); for (int i = 0; i < jarr.length() - 1; i++) { JSONObject jsonobj = jarr.getJSONObject(i); if (yhdm.equals(jsonobj.getString("FID_YHDM"))) { ; zjzh = jsonobj.getString("FID_ZJZH"); break; } } return zjzh; } public String getFundAccount(String tacode, Context context) throws JSONException { String jjzh = ""; JSONObject fundAccountData = new JSONObject(); String filedate = ActivityUtil.getPreference(context, "openFundAccountDate", ""); if (!(filedate).equals(DateTool.getToday())) { //????? fundAccountData = FundService.getFundAccountInfo(); } else { String jsonObject = CssIniFile.loadIni(context, 5, "fundAccount"); if (null != jsonObject && !jsonObject.equals("")) { fundAccountData = new JSONObject(jsonObject); } } JSONArray jarr = fundAccountData.getJSONArray("item"); for (int i = 0; i < jarr.length() - 1; i++) { JSONObject jsonobj = jarr.getJSONObject(i); if (tacode.equals(jsonobj.getString("FID_TADM"))) { ; jjzh = jsonobj.getString("FID_JJZH"); break; } } return jjzh; } public String getFundCodeName(String ofcode, Context context) throws JSONException { String jjjc = ""; JSONObject fundInfoData = new JSONObject(); String filedate = ActivityUtil.getPreference(context, "openFundInfoDate", ""); if (!(filedate).equals(DateTool.getToday())) { //????? fundInfoData = FundService.getFundInfo(); } else { String jsonObject = CssIniFile.loadIni(context, 4, "fundInfo"); if (null != jsonObject && !jsonObject.equals("")) { fundInfoData = new JSONObject(jsonObject); } } JSONArray jarr = fundInfoData.getJSONArray("item"); for (int i = 0; i < jarr.length() - 1; i++) { JSONObject jsonobj = jarr.getJSONObject(i); if (ofcode.equals(jsonobj.getString("FID_JJDM"))) { ; jjjc = jsonobj.getString("FID_JJJC"); break; } } return jjjc; } public String getFundCodeNav(String ofcode, Context context) throws JSONException { String fundNav = ""; JSONObject fundInfoData = new JSONObject(); String filedate = ActivityUtil.getPreference(context, "openFundInfoDate", ""); if (!(filedate).equals(DateTool.getToday())) { //????? fundInfoData = FundService.getFundInfo(); } else { String jsonObject = CssIniFile.loadIni(context, 4, "fundInfo"); if (null != jsonObject && !jsonObject.equals("")) { fundInfoData = new JSONObject(jsonObject); } } JSONArray jarr = fundInfoData.getJSONArray("item"); for (int i = 0; i < jarr.length() - 1; i++) { JSONObject jsonobj = jarr.getJSONObject(i); if (ofcode.equals(jsonobj.getString("FID_JJDM"))) { ; fundNav = jsonobj.getString("FID_JJJZ"); break; } } return fundNav; } public String getFundStatus(String ofcode, Context context) throws JSONException { String jyzt = ""; JSONObject fundInfoData = new JSONObject(); String filedate = ActivityUtil.getPreference(context, "openFundInfoDate", ""); if (!(filedate).equals(DateTool.getToday())) { //????? fundInfoData = FundService.getFundInfo(); } else { String jsonObject = CssIniFile.loadIni(context, 4, "fundInfo"); if (null != jsonObject && !jsonObject.equals("")) { fundInfoData = new JSONObject(jsonObject); } } JSONArray jarr = fundInfoData.getJSONArray("item"); for (int i = 0; i < jarr.length() - 1; i++) { JSONObject jsonobj = jarr.getJSONObject(i); if (ofcode.equals(jsonobj.getString("FID_JJDM"))) { ; jyzt = jsonobj.getString("FID_JYZT"); break; } } return jyzt; } public String getFundCompanyName(String tacode, Context context) throws JSONException { String fundcompanyName = ""; JSONObject fundCompanyData = new JSONObject(); String filedate = ActivityUtil.getPreference(context, "openFundCompanyDate", ""); if (!(filedate).equals(DateTool.getToday())) { //????? fundCompanyData = FundService.getFundCompany(); } else { String jsonObject = CssIniFile.loadIni(context, 3, "fundCompany"); if (null != jsonObject && !jsonObject.equals("")) { fundCompanyData = new JSONObject(jsonObject); } } JSONArray jarr = fundCompanyData.getJSONArray("item"); for (int i = 0; i < jarr.length() - 1; i++) { JSONObject jsonobj = jarr.getJSONObject(i); if (tacode.equals(jsonobj.getString("FID_TADM"))) { ; fundcompanyName = jsonobj.getString("FID_JGJC");//FID_JGMC break; } } return fundcompanyName; } public JSONObject getFundByCompany(String tacode, Context context) throws JSONException { JSONObject fundInfoData = null; JSONObject convertInData = new JSONObject(); JSONArray convertInarr = new JSONArray(); String filedate = ActivityUtil.getPreference(context, "openFundInfoDate", ""); if (!(filedate).equals(DateTool.getToday())) { //????? fundInfoData = FundService.getFundInfo(); } else { String jsonObject = CssIniFile.loadIni(context, 4, "fundInfo"); if (null != jsonObject && !jsonObject.equals("")) { fundInfoData = new JSONObject(jsonObject); } } JSONArray jarr = fundInfoData.getJSONArray("item"); for (int i = 0; i < jarr.length() - 1; i++) { JSONObject jsonobj = jarr.getJSONObject(i); if (!"0".equals(tacode)) { if (tacode.equals(jsonobj.getString("FID_TADM"))) { convertInarr.put(jsonobj); } } else {// convertInarr.put(jsonobj); } } convertInData.put("item", convertInarr); return convertInData; } public static List<CssStock> fillListToNull(int begin, int end, List<CssStock> list) { for (int i = begin; i < end; i++) { CssStock cssStock = new CssStock(); cssStock.setStkname(null); cssStock.setStkcode(null); cssStock.setZf(0); cssStock.setZjcj(0); cssStock.setZrsp(0); cssStock.setMarket(null); cssStock.setExchange(0); list.add(cssStock); } return list; } public static List<CssStock> fillListToNull(int begin, int end) { List<CssStock> list = new LinkedList<CssStock>(); for (int i = begin; i < end; i++) { CssStock cssStock = new CssStock(); cssStock.setStkname(""); cssStock.setStkcode(""); cssStock.setZf(0); cssStock.setZjcj(0); cssStock.setZrsp(0); cssStock.setZjcj(0); cssStock.setZf(0); cssStock.setZd(0); cssStock.setBjw1(0); cssStock.setSjw1(0); cssStock.setXs(0); cssStock.setZl(0); cssStock.setHs(0); cssStock.setJrkp(0); cssStock.setZgcj(0); cssStock.setZdcj(0); cssStock.setZje(0); cssStock.setAmp(0); cssStock.setLb(0); cssStock.setMarket("sh"); cssStock.setExchange(0); list.add(cssStock); } return list; } public static List<CssStock> fillHSZSListToNull(int begin, int end) { List<CssStock> list = new LinkedList<CssStock>(); for (int i = begin; i < end; i++) { CssStock cssStock = new CssStock(); cssStock.setStkname(""); cssStock.setStkcode(""); cssStock.setBjw1(0); cssStock.setZf(0); cssStock.setZd(0); cssStock.setZje(0); cssStock.setZl(0); cssStock.setXs(0); cssStock.setJrkp(0); cssStock.setZrsp(0); cssStock.setZgcj(0); cssStock.setZdcj(0); cssStock.setAmp(0); cssStock.setLb(0); cssStock.setMarket("hk"); cssStock.setExchange(0); list.add(cssStock); } return list; } public static List<CssStockFund> fillListToNull2(int begin, int end) { List<CssStockFund> list = new ArrayList<CssStockFund>(); for (int i = begin; i < end; i++) { CssStockFund cssStockFund = new CssStockFund(); cssStockFund.setStkfunname(""); cssStockFund.setMarket("sh"); cssStockFund.setStkcode(""); cssStockFund.setJjfnpj(0); cssStockFund.setJjtnpj(0); cssStockFund.setJz(0); cssStockFund.setLjjz(0); list.add(cssStockFund); } return list; } public static List<String[]> fillListToNull3(int begin, int end) { List<String[]> list = new ArrayList<String[]>(); for (int i = begin; i < end; i++) { String[] arr = new String[2]; arr[0] = ""; arr[1] = ""; list.add(arr); } return list; } public static List<String[]> fillListToNull4(int begin, int end) { List<String[]> list = new ArrayList<String[]>(); for (int i = begin; i < end; i++) { String[] arr = new String[9]; arr[0] = ""; arr[1] = "0"; arr[2] = "0"; arr[3] = "0"; arr[4] = "0"; arr[5] = "0"; arr[6] = "0"; arr[7] = "0"; arr[8] = "0"; list.add(arr); } return list; } public static List<String[]> fillListToNull5(int begin, int end) { List<String[]> list = new ArrayList<String[]>(); for (int i = begin; i < end; i++) { String[] arr = new String[7]; arr[0] = ""; arr[1] = "0"; arr[2] = "0"; arr[3] = "0"; arr[4] = "0"; arr[5] = "0"; arr[6] = "0"; list.add(arr); } return list; } public static List<String[]> fillListToNull6(int begin, int end, String stocks, String stocksname) { List<String[]> list = new ArrayList<String[]>(); String[] temp1 = null; String[] temp2 = null; int t = 0; if (null != stocks) { temp1 = stocks.split(","); if (null != temp1) { t = temp1.length; } } if (null != stocksname) { temp2 = stocksname.split(","); } for (int i = begin; i < end; i++) { String[] arr = new String[24]; if (i > t - 1) { arr[0] = ""; arr[1] = ""; } else { arr[0] = temp1[i].substring(2); arr[1] = temp2[i]; } arr[2] = "0"; arr[3] = "0"; arr[4] = "0"; arr[5] = "0"; arr[6] = "0"; arr[7] = "0"; arr[8] = "0"; arr[9] = "0"; arr[10] = "0"; arr[11] = "0"; arr[12] = "0"; arr[13] = "0"; arr[14] = "0"; arr[15] = "0"; arr[16] = "0"; arr[17] = "0"; arr[18] = "0"; arr[19] = "0"; arr[20] = "0"; arr[21] = "3"; arr[22] = "0"; arr[23] = "0"; list.add(arr); } return list; } public static String formateStatus(char status) { String dealStatus = ""; switch (status) { case '0': dealStatus = ""; break; case '1': dealStatus = ""; break; case '2': dealStatus = ""; break; case '3': dealStatus = ""; break; case '4': dealStatus = "?"; break; case '5': dealStatus = ""; break; case '6': dealStatus = ""; break; case '7': dealStatus = "?"; break; case '8': dealStatus = "?"; break; case '9': dealStatus = "?"; break; case 'A': dealStatus = ""; break; case 'B': dealStatus = ""; break; } return dealStatus; } public static String dealFundSBJG(int status) { String dealStatus = ""; switch (status) { case -1: dealStatus = ""; break; case 0: dealStatus = ""; break; case 1: dealStatus = ""; break; case 2: dealStatus = ""; break; } return dealStatus; } public static String dealFundStatus(int n) { String dealStatus = ""; switch (n) { case 0: dealStatus = ""; break; case 1: dealStatus = ""; break; case 2: dealStatus = ""; break; case 4: dealStatus = ""; break; case 8: dealStatus = ""; break; case 16: dealStatus = ""; break; case 64: dealStatus = ""; break; default: dealStatus = ""; break; } return dealStatus; } public static String formateBankStatus(char status) { String dealStatus = ""; switch (status) { case '0': dealStatus = ""; break; case '1': dealStatus = ""; break; case '2': dealStatus = "?"; break; case '3': dealStatus = ""; break; case '4': dealStatus = ""; break; case '5': dealStatus = ""; break; case '6': dealStatus = ""; break; case '7': dealStatus = "?"; break; case '8': dealStatus = ""; break; } return dealStatus; } /** * ??? * @param banktranId * @return */ public static String formatBankTranName(char banktranId) { String dealName = ""; switch (banktranId) { case '1': dealName = "?"; break; case '2': dealName = "?"; break; } return dealName; } public static String formateMatchType(char status) { String dealStatus = ""; switch (status) { case '0': dealStatus = "?"; break; case '1': dealStatus = "??"; break; case '2': dealStatus = "?"; break; case '3': dealStatus = "?"; break; case '4': dealStatus = "??"; break; } return dealStatus; } /** * ?? * @param status * @return */ public static String formateShareClass(int status) { String dealStatus = ""; switch (status) { case 1: dealStatus = "?"; break; case 2: dealStatus = "?"; break; default: dealStatus = ""; break; } return dealStatus; } /** * ???? * @param status * @return */ public static String formateDividend(int status) { String dealStatus = ""; switch (status) { case 1: dealStatus = ""; break; case 2: dealStatus = ""; break; default: dealStatus = "--"; break; } return dealStatus; } /** * ???? * @param mark * @return markname * @author hujun */ public static String getMarkName(char mark) { String markname = ""; switch (mark) { case '1': markname = "A"; break; case '0': markname = "A"; break; case '6': markname = "?A"; break; case '7': markname = "?B"; break; case '9': markname = ""; break; case 'A': markname = "?"; break; case '3': markname = "B"; break; case '2': markname = "B"; break; case 'J': markname = "?"; break; } return markname; } //? ? public static String getMarket(char market) { String value = ""; switch (market) { //?????? case '1': value = "SH"; break; } return value; } /** * ???? * @param risk * @return riskname * @author hujun */ public static String getRiskName(int risk) { String riskname = ""; switch (risk) { case 1: riskname = ""; break; case 2: riskname = "-AAA"; break; case 3: riskname = "-AA"; break; case 4: riskname = "-A"; break; case 5: riskname = ""; break; case 6: riskname = "-AAA"; break; case 7: riskname = "-AA"; break; case 8: riskname = "-A"; break; case 9: riskname = ""; break; default: riskname = ""; break; } return riskname; } /** * * @param mt ? * @return * */ public static String dealBusinessAction(int mt) { String reStr = "-"; switch (mt) { case 10101: reStr = ""; break;// case 10103: reStr = ""; break;// case 10112: reStr = ""; break;// case 10113: reStr = ""; break;//? case 10116: reStr = ""; break;//? case 10201: reStr = ""; break;//? case 10203: reStr = ""; break;//? case 10212: reStr = ""; break;// case 10213: reStr = ""; break;//?? case 10501: reStr = ""; break;//? case 10502: reStr = ""; break;// case 10503: reStr = ""; break;//? case 13001: reStr = ""; break; //? case 13011: reStr = ""; break;//? case 13015: reStr = ""; break;//? case 13031: reStr = ""; break;//? case 13032: reStr = ""; break;//? case 13101: reStr = ""; break; //?? case 13115: reStr = ""; break;//? case 13131: reStr = ""; break;//? case 13201: reStr = ""; break;// case 13202: reStr = ""; break;//? case 13203: reStr = ""; break;// case 14001: reStr = ""; break;//() case 14002: reStr = "()"; break;// case 14003: reStr = ""; break;//() case 14004: reStr = "()"; break;// case 14101: reStr = ""; break;// case 14102: reStr = ""; break;// case 14103: reStr = ""; break;// case 14201: reStr = ""; break;//? case 14202: reStr = ""; break;//? } return reStr; } public static String dealFundRiskType(String fxdj) { String reStr = ""; if ("0".equals(fxdj)) { reStr = ""; } else if ("1".equals(fxdj)) { reStr = "?"; } else if ("2".equals(fxdj)) { reStr = "?"; } else if ("3".equals(fxdj)) { reStr = "?"; } else if ("4".equals(fxdj)) { reStr = ""; } return reStr; } /** * ?? */ public static String formatNum(String str, int len) { if (str == null) return ""; int flag = 1; if (str.charAt(0) == '-' && str.charAt(1) == '.') { str = str.replace("-.", "-0."); flag = -1; } if (str.charAt(0) == '.') str = "0" + str; if (len < 0) len = 0; BigDecimal small = new BigDecimal("0"); BigDecimal big = new BigDecimal("0"); if (("0").equals(str) && len == 0) return "0"; if (str.indexOf(".") != -1) { String[] ary = str.split("\\."); big = BigDecimal.valueOf(Double.parseDouble(ary[0])); small = BigDecimal.valueOf(Double.parseDouble("0." + ary[1])); small = small.setScale(len > 0 ? len : 1, BigDecimal.ROUND_HALF_UP); if (str.charAt(0) == '-') { return big.subtract(small).multiply(new BigDecimal(flag)).setScale(len, BigDecimal.ROUND_HALF_UP) .toString(); } return big.add(small).multiply(new BigDecimal(flag)).setScale(len, BigDecimal.ROUND_HALF_UP).toString(); } else { return new BigDecimal(str).multiply(new BigDecimal(flag)).setScale(len, BigDecimal.ROUND_HALF_UP) .toString(); } } /** * */ public static String StringConvertTime(String str) { try { String result = null; if (null != str) { if (str.length() == 8) { result = str.substring(0, 2) + ":" + str.substring(2, 4) + ":" + str.substring(4, 6); } else if (str.length() == 7) { result = "0" + str.substring(0, 1) + ":" + str.substring(1, 3) + ":" + str.substring(3, 5); } return result; } } catch (Exception e) { e.printStackTrace(); } return null; } public static boolean checkUserLogin() { int loginType = TradeUser.getInstance().getLoginType(); if (loginType == 0) { return false; } return true; } /** * ? * @param value * @param falg ?, true,false? * @return true,false? */ public static boolean checkNumber(String value, boolean falg) { try { if (falg) { int intvalue = Integer.parseInt(value); if (intvalue <= 0) { return false; } return true; } else { double doublevalue = Double.parseDouble(value); if (doublevalue <= 0) { return false; } return true; } } catch (Exception e) { return false; } } //??? public static boolean checkPhone(String phone) { //String regex = "^\\(?\\d{3,4}[-\\)]?\\d{7,8}$"; String regex = "((\\d{11})|^((\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1})|(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))$)"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(phone); return matcher.find(); } // ?$:?[^@]:?@?? public static boolean checkEmail(String email) { //String regex = "^\\w+@\\w+\\.(com\\.cn)|\\w+@\\w+\\.(com|cn)$"; //struts2??? String regex = "\\b(^['_A-Za-z0-9-]+(\\.['_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z0-9]{2,})|(\\.[A-Za-z0-9]{2,}\\.[A-Za-z0-9]{2,}))$)\\b"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(email); return matcher.find(); } }