/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
package jp.co.sint.tools;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.co.sint.basic.SILogin;
import jp.co.sint.basic.SINameValue;
import jp.co.sint.config.SIConfig;
import jp.co.sint.config.SIDBMultiConf;
import jp.co.sint.config.SIFlagConf;
import jp.co.sint.database.SIDBUtil;

import org.apache.log4j.Category;
import org.apache.regexp.RE;

/**
 * @version $Id: SIUtil.java,v 1.0 2003/07/25 Exp $
 * @author  Jinwang Chen
 * <br>Description: 共通utitliesのクラス
 * <p>History</p>
 * <p>Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reason</p>
 * ============&nbsp;&nbsp;&nbsp;==========&nbsp;&nbsp;===========================<br>
 * J.W.Chen       2003/07/25  Original
 */

public class SIUtil {
  // ログ用のインスタンスの生成
  private static Category log = Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  
  /**
   * <b>SIUtil</b> コンストラクタ
   * 
   * @param なし
   * @return なし
   * @throws なし
   */
  public SIUtil() {}
  
  /**
   * <b>isNull</b> nullの文字列をチェックします、指定の文字列がnull、あるいは、""の場合に nullをみなす
   * 
   * @param 対象の文字列
   * @return true 指定の文字列がnull false nullではない
   * @throws なし
   */
  public static boolean isNull(String source) {
    if (source == null || source.trim().length() == 0) return true;
    else return false;
  }
  
  /**
   * <b>isNotNull</b> nullの文字列をチェックします、指定の文字列がnull、あるいは、""の場合に nullをみなす
   * 
   * @param 対象の文字列
   * @return true 指定の文字列がnot null false チェックしたデータは、nullのデータです。
   * @throws なし
   */
  public static boolean isNotNull(String source) {
    return !isNull(source);
  }
  
  /**
   * <b>replace</b> 文字列の代替
   * 
   * @param subject 対象の文字列
   * @param find replaced文字列
   * @param replace replace文字列
   * @return 変更後の文字列
   * @throws なし
   */
  public static String replace(String lSrc, String lFind, String lReplace) {
    if (lSrc == null) return null;
    return SIStringUtil.replace(lSrc, lFind, lReplace);
  }
  
  /**
   * <b>sqlEncode</b> SQLの値に"'"があれば、"''"で入れ替えます。
   * 
   * @param val 対象のSQLの値
   * @return 変換後のSQLの値の
   * @throws なし
   */
  public static String sqlEncode(String val) {
    return SIDBUtil.sqlEncode(val);
  }
  
  /**
   * <b>htmlEncode</b> Quote metacharacters in HTML
   * 
   * @param source 対象のHTML文
   * @return 変更後のHTML文
   * @throws なし
   */
  public static String HTMLEncode(String source) {
    return SIHTMLUtil.HTMLEncode(source);
  }
  
  /**
   * <b>changeJIS</b> ShiftJisコードの日本語に変換する
   * 
   * @param source 文字列
   * @return ShiftJisコードに付ける文字列
   * @throws なし
   */
  public static String changeToJIS(String source) {
    return changeTo(source, SIConfig.SIENCODE_SHIFT_JIS);
  }
  
  public static String changeTo(String source, String encode) {
    if (source == null) return null;
    
    /*
     * 7.4.0 ST2060 修正ここから if (SIUtil.isNull(encode)){ return JISToCp932(source); }
     */
    try {
      // return JISToCp932(new String(source.getBytes("iso-8859-1"), encode));
      return JISToCp932(source);
      // 7.4.0 ST2060 修正ここまで
    } catch (Exception e) {
      return null;
    }
  }
  
  public static String[] changeTo(String[] source, String encode) {
    if (source == null) {
      source = new String[0];
      return source;
    }
    for (int i = 0; i < source.length; i++) {
      source[i] = SIUtil.changeTo(source[i].trim(), encode);
    }
    return source;
  }
  
  /**
   * <b>sortIterator</b> Iteratorの文字オブジェクトから配列文字列に変更して、ソートする
   * 
   * @param sortIterator 変更する文字列
   * @return 変更後の文字列
   * @throws なし
   */
  public static String[] sortIterator(Iterator sortIterator) {
    ArrayList sortedVal = new ArrayList();
    while (sortIterator.hasNext()) {
      sortedVal.add((String) sortIterator.next());
    }
    String[] sortedArray = (String[]) sortedVal.toArray(new String[0]);
    if (sortedArray != null) Arrays.sort(sortedArray);
    return sortedArray;
  }
  
  /**
   * <b>trimVal</b> 指定する文字列に前後のスペースを削除します。
   * 
   * @param val 対象文字列
   * @return 変更後の文字列
   * @throws なし
   */
  public static String trimVal(String val) {
    if (val == null) return "";
    else return val.trim();
  }
  
  /**
   * <b>getOrderName</b> 画面から選択した表示順の番号により、表示順のSQL文を作成する
   * 
   * @param orderNo 表示順の番号
   * @return 表示順のSQL文
   * @throws なし
   */
  public static String getOrderName(int orderNo) {
    if (orderNo == 0) return "ORDER BY " + getOrderName("price", 0);
    if (orderNo == 1) return "ORDER BY " + getOrderName("price", 1);
    if (orderNo == 2) return "";
    if (orderNo == 3) return "";
    return "";
  }
  
  /**
   * <b>getOrderColl</b> トップ画面に、表示の順番に選択可能の項目リスト
   * 
   * @param なし
   * @return 選択可能の項目リスト
   * @throws なし
   */
  public static Collection getOrderColl() {
    Collection lOrderColl = new ArrayList();
    lOrderColl.add(new SINameValue("価格の安い順", "0"));
    lOrderColl.add(new SINameValue("価格の高い順", "1"));
    lOrderColl.add(new SINameValue("新しい順", "2"));
    lOrderColl.add(new SINameValue("人気順", "3"));
    return lOrderColl;
  }
  
  /**
   * <b>getPageColl</b> トップなどの画面に、一画面ごとに、表示が可能なレコード数にマップセットに 設定する
   * 
   * @param なし
   * @return 可能なレコード数のマップセット
   * @throws なし
   */
  public static Collection getPageColl() {
    Collection lPageColl = new ArrayList();
    String lPageSize = "";
    for (int ii = 0; ii < SIConfig.SIPAGE_SIZE_LIST.length; ii++) {
      lPageSize = String.valueOf(SIConfig.SIPAGE_SIZE_LIST[ii]);
      lPageColl.add(new SINameValue(lPageSize, lPageSize));
    }
    return lPageColl;
  }
  
  /**
   * <b>getThumPageColl</b> トップなどの画面に、一画面ごとに、表示が可能なレコード数にマップセットに 設定する
   * 
   * @param なし
   * @return 可能なレコード数のマップセット
   * @throws なし
   */
  public static Collection getThumPageColl() {
    Collection lPageColl = new ArrayList();
    lPageColl.add(new SINameValue("3", "3"));
    lPageColl.add(new SINameValue("6", "6"));
    lPageColl.add(new SINameValue("9", "9"));
    lPageColl.add(new SINameValue("15", "15"));
    return lPageColl;
  }
  
  /**
   * <b>getNameFromColl</b> 共通のメソッド
   * 
   * @param lCollection 元のフラグのコネクション
   * @param lValue フラグの値
   * @return 画面に表示用のラベル
   * @throws なし
   */
  public static String getNameFromColl(Collection lCollection, String lValue) {
    if (lValue == null) return "";
    Iterator lIta = lCollection.iterator();
    
    SINameValue nameValue = new SINameValue();
    while (lIta.hasNext()) {
      nameValue = (SINameValue) lIta.next();
      if (nameValue.getValue().trim().equalsIgnoreCase(lValue)) return nameValue.getName();
    }
    return "";
  }
  
  public static boolean getNameFromCollCheck(Collection lCollection, String lValue) {
    if (lValue == null) return true;
    Iterator lIta = lCollection.iterator();
    
    SINameValue nameValue = new SINameValue();
    while (lIta.hasNext()) {
      nameValue = (SINameValue) lIta.next();
      if (nameValue.getValue().trim().equalsIgnoreCase(lValue)) return true;
    }
    return false;
  }
  
  /**
   * <b>appendColl</b> あるコネンクションに別のオブジェクトを追加します。
   * 
   * @param lSrcColl 元のコネクション
   * @param lAppendColl 追加されるオブジェクト
   * @return 新しいコネクション
   * @throws なし
   */
  public static Collection appendColl(Collection lSrcColl, Object lAppendColl) {
    if (lAppendColl instanceof Collection) {
      Iterator lAppendIta = ((Collection) lAppendColl).iterator();
      while (lAppendIta.hasNext()) {
        lSrcColl.add(lAppendIta.next());
      }
    } else lSrcColl.add(lAppendColl);
    return lSrcColl;
  }
  
  /**
   * <b>insertColl</b> コネンクションの一番の前に別のオブジェクトを追加します。
   * 
   * @param lSrcColl 元のコネクション
   * @param lAppendColl 追加されるオブジェクト
   * @return 新しいコネクション
   * @throws なし
   */
  public static Collection insertColl(Collection lSrcColl, Object lAppendColl) {
    Collection lResultColl = new ArrayList();
    if (lAppendColl instanceof Collection) {
      Iterator lAppendIta = ((Collection) lAppendColl).iterator();
      while (lAppendIta.hasNext()) {
        lResultColl.add(lAppendIta.next());
      }
    } else lResultColl.add(lAppendColl);
    return appendColl(lResultColl, lSrcColl);
  }
  
  public static String getOrderName(String lItemName, int lOrderFlag) {
    if (SIUtil.isNull(lItemName)) return "";
    return lItemName + " " + SIConfig.SIORDER_NAME[lOrderFlag];
  }
  
  /**
   * <b>match</b> 指定数のデータにチェックされるデータの全てのbitが設定されるかどうかをチェックします。
   * 
   * @param lSrc 指定数のデータの文字列
   * @param lMatched チェックされるデータ
   * @return true 設定される false 一部が設定されない
   * @throws なし
   */
  public static boolean match(String lSrc, String lMatched) {
    try {
      return match(Long.parseLong(lSrc), Long.parseLong(lMatched));
    } catch (Exception e) {
      return false;
    }
  }
  
  public static boolean notMatch(String lSrc, String lMatched) {
    try {
      return notMatch(Long.parseLong(lSrc), Long.parseLong(lMatched));
    } catch (Exception e) {
      return false;
    }
  }
  
  /**
   * <b>match</b> 指定数のデータにチェックされるデータの全てのbitが設定されるかどうかをチェックします。
   * 
   * @param lSrc 指定数のデータ
   * @param lMatched チェックされるデータ
   * @return true 設定される false 一部が設定されない
   * @throws なし
   */
  public static boolean match(long lSrcVal, long lMatchedVal) {
    if ((lSrcVal & lMatchedVal) > 0) return true;
    else return false;
  }
  
  public static boolean notMatch(long lSrcVal, long lMatchedVal) {
    return !match(lSrcVal, lMatchedVal);
  }
  
  /**
   * <b>lconvertTo</b> 指定文字データの長さは、指定される長さに至らないければ、左側に"0"で揃います。
   * 
   * @param lSrc 指定の文字データ
   * @param len 要求の文字長さ
   * @return 変換後の文字列
   * @throws なし
   * @deprecated since of {@link lFillIn}
   */
  public static String lconvertTo(String src, int len) {
    return lFillIn(src, len);
  }
  
  /**
   * <b>lconvertTo</b> 指定数のデータの長さは、指定される長さに至らないければ、左側に"0"で揃います。 nullをみなす
   * 
   * @param 対象の文字列
   * @return true 指定の文字列がnull false nullではない
   * @throws なし
   * @deprecated since of {@link lFillIn}
   */
  public static String lconvertTo(int src, int len) {
    return lFillIn(String.valueOf(src), len);
  }
  
  /**
   * <b>lFillIn</b> 指定文字データの長さは、指定される長さに至らないければ、左側に"0"で揃います。
   * 
   * @param lSrc 指定の文字データ
   * @param len 要求の文字長さ
   * @return 変換後の文字列
   * @throws なし
   */
  public static String lFillIn(String src, int len) {
    StringBuffer sb = new StringBuffer();
    if (src == null) return null;
    if (src.length() >= len) return src;
    for (int ii = 0; ii < len - src.length(); ii++)
      sb.append("0");
    sb.append(src);
    return sb.toString();
  }
  
  /**
   * <b>lFillIn</b> 指定数のデータの長さは、指定される長さに至らないければ、左側に"0"で揃います。 nullをみなす
   * 
   * @param 対象の文字列
   * @return true 指定の文字列がnull false nullではない
   * @throws なし
   */
  public static String lFillIn(int src, int len) {
    return lFillIn(String.valueOf(src), len);
  }
  
  /**
   * <b>lconvertTo</b> 指定文字データの長さは、指定される長さに至らないければ、右側に"0"で揃います。
   * 
   * @param lSrc 指定の文字データ
   * @param len 要求の文字長さ
   * @return 変換後の文字列
   * @throws なし
   * @deprecated since of {@link rFillIn}
   */
  public static String rconvertTo(String src, int len) {
    return rFillIn(src, len);
  }
  
  /**
   * <b>lconvertTo</b> 指定数のデータの長さは、指定される長さに至らないければ、右側に"0"で揃います。
   * 
   * @param lSrc 指定の文字データ
   * @param len 要求の文字長さ
   * @return 変換後の文字列
   * @throws なし
   * @deprecated since of {@link rFillIn}
   */
  public static String rconvertTo(int src, int len) {
    return rFillIn(String.valueOf(src), len);
  }
  
  /**
   * <b>rFillIn</b> 指定文字データの長さは、指定される長さに至らないければ、右側に"0"で揃います。
   * 
   * @param lSrc 指定の文字データ
   * @param len 要求の文字長さ
   * @return 変換後の文字列
   * @throws なし
   */
  public static String rFillIn(String src, int len) {
    StringBuffer sb = new StringBuffer();
    if (src == null) return null;
    if (src.length() >= len) return src;
    sb.append(src);
    for (int ii = 0; ii < len - src.length(); ii++)
      sb.append("0");
    return sb.toString();
  }
  
  /**
   * <b>rFillIn</b> 指定数のデータの長さは、指定される長さに至らないければ、右側に"0"で揃います。
   * 
   * @param lSrc 指定の文字データ
   * @param len 要求の文字長さ
   * @return 変換後の文字列
   * @throws なし
   */
  public static String rFillIn(int src, int len) {
    return rFillIn(String.valueOf(src), len);
  }
  
  /**
   * <b>getColl</b> 数字範囲内の全ての数字をコネクションに入れて戻します。
   * 
   * @param lMinNum 最初の数字
   * @param lMaxNum 最大の数字
   * @return 数字のコネクションリスト
   * @throws なし
   */
  public static Collection getColl(int lMinNum, int lMaxNum) {
    Collection lResultColl = new ArrayList();
    StringBuffer lVal = new StringBuffer();
    int lLen = String.valueOf(lMaxNum).length();
    String lName = "";
    
    for (int ii = 0; ii < lLen; ii++)
      lVal.append("-");
    lResultColl.add(new SINameValue(lVal.toString(), ""));
    
    for (int ii = lMinNum; ii <= lMaxNum; ii++) {
      lName = SIUtil.lFillIn(ii, lLen);
      lResultColl.add(new SINameValue(lName, lName));
    }
    return lResultColl;
  }
  
  public static String enableChecked(int ii) {
    if (ii == 0) return "";
    else return "checked";
  }
  
  public static String enableChecked(String ii) {
    try {
      return enableChecked(Integer.parseInt(ii));
    } catch (Exception ee) {
      return "";
    }
  }
  
  public static void checkAllowAuth(HttpServletRequest lRequest, HttpServletResponse lResponse, int lAuthType) throws ServletException, IOException {
    SILogin lLogin = SIHTMLUtil.getLogin(lRequest);
    if (!SIUtil.match(lAuthType, lLogin.getAdminType())) {
      SICustomErrors errors = new SICustomErrors();
      errors.addError(new SICustomError("manager.app.priv.disable"));
      
      lRequest.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
      SIHTMLUtil.forwardKey(lRequest, lResponse, "webshop.jsp.manager.auth.failure");
    }
  }
  
  public static void checkDenyAuth(HttpServletRequest lRequest, HttpServletResponse lResponse, int lAuthType) throws ServletException, IOException {
    SILogin lLogin = SIHTMLUtil.getLogin(lRequest);
    if (SIUtil.match(lAuthType, lLogin.getAdminType())) {
      SICustomErrors errors = new SICustomErrors();
      errors.addError(new SICustomError("manager.app.priv.disable"));
      
      lRequest.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
      SIHTMLUtil.forwardKey(lRequest, lResponse, "webshop.jsp.manager.auth.failure");
    }
  }
  
  /**
   * <b>checkAllowAccess</b> 管理画面に直接入力を避けるために、認証
   * 
   * @param lRequest リクエスト
   * @param lCurrShopCode 認証するモールコード
   * @return 拒否かどうか
   * @throws なし
   */
  public static void checkAllowAccess(HttpServletRequest lRequest, HttpServletResponse lResponse, String lCurrShopCode) throws ServletException, IOException {
    boolean lRes = false;
    SILogin lLogin = (SILogin) lRequest.getSession().getAttribute(SIConfig.SISESSION_MAN_LOGIN_NAME);
    if (lLogin == null) lRes = false;
    else if (SIUtil.match(SIConfig.SIADMIN_MM_SM, lLogin.getAdminType())) lRes = true;
    else if (SIUtil.isNull(lCurrShopCode)) lRes = false;
    else if (SIUtil.isNull(lLogin.getMallShopCode())) lRes = false;
    else if (lCurrShopCode.equals(lLogin.getMallShopCode())) lRes = true;
    else lRes = false;
    log.debug("checkAllowAccess:lCurrShopCode=" + lCurrShopCode + ",lLogin.getMallShopCode()=" + lLogin.getMallShopCode());
    
    if (!lRes) {
      SICustomErrors errors = new SICustomErrors();
      errors.addError(new SICustomError("manager.app.access.disable"));
      
      lRequest.setAttribute(SIConfig.SIERROR_ATTRIBUTE_MESSAGE_KEY, errors);
      SIHTMLUtil.forwardKey(lRequest, lResponse, "webshop.jsp.manager.auth.failure");
    }
  }
  
  public static String getImageFileNameOfStars(float ff) {
    int ii = (int) (ff * 2 - 2);
    if (ii < 0) return "lbl_Space.gif";
    else return SIConfig.SIREVIEW_STARS_FILE_NAME[ii];
  }
  
  public static String getImageFileNameOfSex(int ii) {
    return SIConfig.SIREVIEW_SEX_FILE_NAME[ii];
  }
  
  public static String jsEncode(String lSrc) {
    if (SIUtil.isNull(lSrc)) return "";
    return SIStringUtil.replace(lSrc, "'", "''");
  }
  
  /**
   * 小数かどうか判断する。
   * 
   * @param str
   * @return
   */
  public static boolean isDecimal(String str) {
    if (str.indexOf('.') < 0) { return false; }
    return true;
  }
  
  /**
   * <b>add</b> 二つ文字列数字を加算します。。
   * 
   * @param lNum1 一つ目の文字列数字
   * @param lNum1 二つ目の文字列数字
   * @return 加算
   * @throws なし
   */
  public static String add(String lNum1, String lNum2) {
    return add(lNum1, lNum2, "0", false);
  }
  
  public static String add(String lNum1, String lNum2, boolean doubleFlg) {
    return add(lNum1, lNum2, "0", doubleFlg);
  }
  
  public static String add(String lNum1, String lNum2, String lNum3) {
    return add(lNum1, lNum2, lNum3, false);
  }
  
  public static String add(String lNum1, String lNum2, String lNum3, boolean doubleFlg) {
    
    long num1_l = 0;
    double num1_d = 0;
    boolean num1 = true;
    if (isDecimal(lNum1)) {
      try {
        num1_d = Double.parseDouble(lNum1);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num1_d = 0;
      }
    } else {
      try {
        num1_l = Long.parseLong(lNum1);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num1_l = 0;
      }
      num1 = false;
    }
    
    long num2_l = 0;
    double num2_d = 0;
    boolean num2 = true;
    if (isDecimal(lNum2)) {
      try {
        num2_d = Double.parseDouble(lNum2);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num2_d = 0;
      }
    } else {
      try {
        num2_l = Long.parseLong(lNum2);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num2_l = 0;
      }
      num2 = false;
    }
    
    long num3_l = 0;
    double num3_d = 0;
    boolean num3 = true;
    if (isDecimal(lNum3)) {
      try {
        num3_d = Double.parseDouble(lNum3);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num3_d = 0;
      }
    } else {
      try {
        num3_l = Long.parseLong(lNum3);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num3_l = 0;
      }
      num3 = false;
    }
    
    double calcRes = 0;
    
    if (!num1 && !num2 && !num3) {
      return String.valueOf(num1_l + num2_l + num3_l);
    } else {
      if (num1) {
        calcRes = calcRes + num1_d;
      } else {
        calcRes = calcRes + num1_l;
      }
      if (num2) {
        calcRes = calcRes + num2_d;
      } else {
        calcRes = calcRes + num2_l;
      }
      if (num3) {
        calcRes = calcRes + num3_d;
      } else {
        calcRes = calcRes + num3_l;
      }
    }
    if (doubleFlg) return String.valueOf(calcRes);
    else return String.valueOf((new Double(calcRes)).longValue());
  }
  
  public static String add_LL(String lNum1, String lNum2) {
    return add_LLL(lNum1, lNum2, "0");
  }
  
  public static String add_DL(String lNum1, String lNum2) {
    double num1 = 0;
    long num2 = 0;
    try {
      num1 = Double.parseDouble(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1 = 0;
    }
    try {
      num2 = Long.parseLong(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum2);
      num2 = 0;
    }
    double ret = num1 + num2;
    return String.valueOf(ret);
  }
  
  public static String add_LLL(String lNum1, String lNum2, String lNum3) {
    long num1 = 0;
    long num2 = 0;
    long num3 = 0;
    try {
      num1 = Long.parseLong(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1 = 0;
    }
    try {
      num2 = Long.parseLong(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum2);
      num2 = 0;
    }
    try {
      num3 = Long.parseLong(lNum3);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum3);
      num3 = 0;
    }
    long ret = num1 + num2 + num3;
    return String.valueOf(ret);
  }
  
  /**
   * <b>sub</b> 二つ文字列数を引きます。
   * 
   * @param lNum1 一つ目の文字列数字
   * @param lNum1 二つ目の文字列数字
   * @return 引きさん
   * @throws なし
   */
  public static String sub(String lNum1, String lNum2) {
    return sub(lNum1, lNum2, false);
  }
  
  public static String sub(String lNum1, String lNum2, boolean doubleFlg) {
    long num1_l = 0;
    double num1_d = 0;
    boolean num1 = true;
    if (isDecimal(lNum1)) {
      try {
        num1_d = Double.parseDouble(lNum1);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num1_d = 0;
      }
    } else {
      try {
        num1_l = Long.parseLong(lNum1);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num1_l = 0;
      }
      num1 = false;
    }
    
    long num2_l = 0;
    double num2_d = 0;
    boolean num2 = true;
    if (isDecimal(lNum2)) {
      try {
        num2_d = Double.parseDouble(lNum2);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num2_d = 0;
      }
    } else {
      try {
        num2_l = Long.parseLong(lNum2);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num2_l = 0;
      }
      num2 = false;
    }
    
    double calcRes = 0;
    
    if (!num1 && !num2) { return String.valueOf(num1_l - num2_l); }
    if (num1 && num2) {
      calcRes = num1_d - num2_d;
    }
    if (!num1 && num2) {
      calcRes = num1_l - num2_d;
    }
    if (num1 && !num2) {
      calcRes = num1_d - num2_l;
    }
    
    if (doubleFlg) return String.valueOf(calcRes);
    else return String.valueOf((new Double(calcRes)).longValue());
  }
  
  public static String sub_LL(String lNum1, String lNum2) {
    long num1 = 0;
    long num2 = 0;
    try {
      num1 = Long.parseLong(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1 = 0;
    }
    try {
      num2 = Long.parseLong(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum2);
      num2 = 0;
    }
    long ret = num1 - num2;
    return String.valueOf(ret);
  }
  
  public static String sub_LD(String lNum1, String lNum2) {
    long num1 = 0;
    double num2 = 0;
    try {
      num1 = Long.parseLong(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1 = 0;
    }
    try {
      num2 = Double.parseDouble(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum2);
      num2 = 0;
    }
    double ret = num1 - num2;
    return String.valueOf(ret);
  }
  
  /**
   * <b>multi</b> 二つ文字列数字を掛けます。
   * 
   * @param lNum1 一つ目の文字列数字
   * @param lNum1 二つ目の文字列数字
   * @return 掛けた積
   * @throws なし
   */
  public static String multi(String lNum1, String lNum2) {
    return multi(lNum1, lNum2, false);
  }
  
  public static String multi(String lNum1, String lNum2, boolean doubleFlg) {
    long num1_l = 0;
    double num1_d = 0;
    boolean num1 = true;
    if (isDecimal(lNum1)) {
      try {
        num1_d = Double.parseDouble(lNum1);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num1_d = 0;
      }
    } else {
      try {
        num1_l = Long.parseLong(lNum1);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num1_l = 0;
      }
      num1 = false;
    }
    
    long num2_l = 0;
    double num2_d = 0;
    boolean num2 = true;
    if (isDecimal(lNum2)) {
      try {
        num2_d = Double.parseDouble(lNum2);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num2_d = 0;
      }
    } else {
      try {
        num2_l = Long.parseLong(lNum2);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num2_l = 0;
      }
      num2 = false;
    }
    
    double calcRes = 0;
    
    if (!num1 && !num2) { return String.valueOf(num1_l * num2_l); }
    if (num1 && num2) {
      calcRes = num1_d * num2_d;
    }
    if (!num1 && num2) {
      calcRes = num1_l * num2_d;
    }
    if (num1 && !num2) {
      calcRes = num1_d * num2_l;
    }
    
    if (doubleFlg) return String.valueOf(calcRes);
    else return String.valueOf((new Double(calcRes)).longValue());
  }
  
  public static String multi_LL(String lNum1, String lNum2) {
    long num1 = 0;
    long num2 = 0;
    try {
      num1 = Long.parseLong(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1 = 0;
    }
    try {
      num2 = Long.parseLong(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num2 = 0;
    }
    long ret = num1 * num2;
    return String.valueOf(ret);
  }
  
  public static String multi_LD(String lNum1, String lNum2) {
    long num1 = 0;
    double num2 = 0;
    try {
      num1 = Long.parseLong(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1 = 0;
    }
    try {
      num2 = Double.parseDouble(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum2);
      num2 = 0;
    }
    long ret = new Double(Math.floor(num1 * num2)).longValue();
    return String.valueOf(ret);
  }
  
  /**
   * <b>div</b> 二つ文字列数字を掛けます。
   * 
   * @param lNum1 一つ目の文字列数字
   * @param lNum1 二つ目の文字列数字
   * @return 掛けた積
   * @throws なし
   */
  public static String div(String lNum1, String lNum2) throws SIFatalException {
    return div(lNum1, lNum2, false);
  }
  
  public static String div(String lNum1, String lNum2, boolean doubleFlg) throws SIFatalException {
    
    long num1_l = 0;
    double num1_d = 0;
    boolean num1 = true;
    if (isDecimal(lNum1)) {
      try {
        num1_d = Double.parseDouble(lNum1);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num1_d = 0;
      }
    } else {
      try {
        num1_l = Long.parseLong(lNum1);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num1_l = 0;
      }
      num1 = false;
    }
    
    long num2_l = 0;
    double num2_d = 0;
    boolean num2 = true;
    if (isDecimal(lNum1)) {
      try {
        num2_d = Double.parseDouble(lNum2);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num2_d = 0;
      }
    } else {
      try {
        num2_l = Long.parseLong(lNum2);
      } catch (Exception e) {
        log.warn("not digit amount!!!lAmount=" + lNum1);
        num2_l = 0;
      }
      num2 = false;
    }
    
    if (num2_d == 0 && num2) throw new SIFatalException("can not dividied by zero!");
    if (num2_l == 0 && !num2) throw new SIFatalException("can not dividied by zero!");
    
    double calcRes = 0;
    
    if (!num1 && !num2) {
      calcRes = num1_l / (double) num2_l;
    }
    if (num1 && num2) {
      calcRes = num1_d / num2_d;
    }
    if (!num1 && num2) {
      calcRes = num1_l / num2_d;
    }
    if (num1 && !num2) {
      calcRes = num1_d / num2_l;
    }
    
    if (doubleFlg) return String.valueOf(calcRes);
    else return String.valueOf((new Double(calcRes)).longValue());
  }
  
  public static String div_DL(String lNum1, String lNum2) throws SIFatalException {
    double num1 = 0;
    long num2 = 0;
    try {
      num1 = Double.parseDouble(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1 = 0;
    }
    try {
      num2 = Long.parseLong(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum2);
      num2 = 0;
    }
    if (num2 == 0) throw new SIFatalException("can not dividied by zero!");
    double ret = num1 / num2;
    return String.valueOf(ret);
  }
  
  public static String div_LD(String lNum1, String lNum2) throws SIFatalException {
    long num1 = 0;
    double num2 = 0;
    try {
      num1 = Long.parseLong(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1 = 0;
    }
    try {
      num2 = Double.parseDouble(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum2);
      num2 = 0;
    }
    if (num2 == 0) throw new SIFatalException("can not dividied by zero!");
    long ret = new Double(Math.floor(num1 / num2)).longValue();
    return String.valueOf(ret);
  }
  
  public static String div_DD(String lNum1, String lNum2) throws SIFatalException {
    double num1 = 0;
    double num2 = 0;
    try {
      num1 = Double.parseDouble(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1 = 0;
    }
    try {
      num2 = Double.parseDouble(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum2);
      num2 = 0;
    }
    if (num2 == 0) throw new SIFatalException("can not dividied by zero!");
    double ret = num1 / num2;
    return getIntVal(String.valueOf(ret));
  }
  
  public static float div_FL(String lNum1, String lNum2) throws SIFatalException {
    
    float num1_f = 0;
    try {
      num1_f = Float.parseFloat(lNum1);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num1_f = 0;
    }
    
    float num2_f = 0;
    try {
      num2_f = Float.parseFloat(lNum2);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lNum1);
      num2_f = 0;
    }
    
    if (num2_f == 0) throw new SIFatalException("can not dividied by zero!");
    
    float calcRes = 0;
    
    calcRes = num1_f / num2_f;
    return calcRes;
    
  }
  
  public static boolean isTrue(String lVal) {
    if (SIUtil.isNull(lVal)) return false;
    else if (lVal.equals("1")) return true;
    else return false;
  }
  
  public static boolean isFalse(String lVal) {
    return !SIUtil.isTrue(lVal);
  }
  
  public static String getExtractCmd(File lFile) {
    if (lFile == null) return "";
    return getExtractCmd(lFile.getAbsolutePath());
  }
  
  public static String getExtractCmd(String lFileName) {
    if (isNull(lFileName)) return "";
    String lFileType = getFileType(lFileName);
    
    if (lFileType.equalsIgnoreCase(SIConfig.SICOMPRESS_LHA_FILE_TYPE)) {
      return SIConfig.SIEXTRACT_LHA_COMMAND;
    } else if (lFileType.equalsIgnoreCase(SIConfig.SICOMPRESS_ZIP_FILE_TYPE)) {
      return SIConfig.SIEXTRACT_ZIP_COMMAND;
    } else {
      return "";
    }
  }
  
  /**
   * <b>getFileType</b> ファイルの種類の取得
   * 
   * @param lFile 対象ファイル名
   * @return ファイルの種類文字列
   * @throws なし
   */
  public static String getFileType(String lFileName) {
    if (SIUtil.isNull(lFileName)) return "";
    
    int ii = lFileName.lastIndexOf(".");
    log.debug("lFileName=" + lFileName + "ii=" + ii);
    if (ii > 0) return lFileName.substring(ii + 1, lFileName.length());
    else return "";
  }
  
  /**
   * <b>getFileType</b> ファイルの種類の取得
   * 
   * @param lFile 対象ファイルオブジェクト
   * @return ファイルの種類文字列
   * @throws なし
   */
  public static String getFileType(File lFile) {
    return getFileType(lFile.getAbsolutePath());
  }
  
  public static boolean extractFile(File lSrcFile, File lDestPath) {
    return extractFile(lSrcFile.getAbsolutePath(), lDestPath.getAbsolutePath());
  }
  
  public static boolean extractFile(String lSrcFile, String lDestPath) {
    if (SIUtil.isNull(lSrcFile)) return false;
    String lCmd = SIUtil.getExtractCmd(lSrcFile);
    StringBuffer lExtractCmd = new StringBuffer(lCmd);
    String[] lExtractCmd0 = new String[5];
    String lFileType = getFileType(lSrcFile);
    
    if (SIUtil.isNull(lExtractCmd.toString())) {
      log.warn("not find the extract command for file " + lSrcFile);
      return false;
    }
    
    if (SIConfig.SIOS_CURRENT_NAME.equals(SIConfig.SIOS_WINDOW_SERIES_NAME)) {
      lSrcFile = "\"" + lSrcFile + "\"";
      if (SIUtil.isNotNull(lDestPath)) lDestPath = "\"" + lDestPath + "\"";
    } else {
      lExtractCmd0 = new String[] { lCmd, "-o", lSrcFile, "-d", lDestPath };
    }
    
    if (isNotNull(lDestPath) && lFileType.equalsIgnoreCase(SIConfig.SICOMPRESS_ZIP_FILE_TYPE)) {
      lExtractCmd = new StringBuffer(SIStringUtil.replace(lExtractCmd.toString(), "-d", ""));
      lExtractCmd.append(" ").append(lSrcFile).append(" -d ").append(lDestPath);
    } else {
      lExtractCmd.append(" ").append(lSrcFile).append(" ").append(lDestPath);
    }
    
    log.debug("lExtractCmd=" + lExtractCmd.toString());
    
    Runtime runtime = Runtime.getRuntime();
    Process process = null;
    try {
      if (SIConfig.SIOS_CURRENT_NAME.equals(SIConfig.SIOS_WINDOW_SERIES_NAME)) {
        process = runtime.exec(lExtractCmd.toString());
      } else {
        process = runtime.exec(lExtractCmd0);
      }
      
      // 7.1.1 ST0082 追加 ここから
      SIStreamGobbler lError = new SIStreamGobbler(process.getErrorStream(), "WSERR");
      SIStreamGobbler lOut = new SIStreamGobbler(process.getInputStream(), "WSOUT");
      
      lError.start();
      lOut.start();
      // 7.1.1 ST0082 追加 ここまで
      
      int exitValue = process.waitFor();
      if (exitValue == 0) {
        log.debug("extract success for file " + lSrcFile + " to " + lDestPath);
        return true;
      } else {
        log.debug("extract failure for file " + lSrcFile + " to " + lDestPath);
        return false;
      }
    } catch (IOException e) {
      e.printStackTrace();
      log.warn("IOException:" + e.toString() + " for file " + lSrcFile + " to " + lDestPath);
    } catch (InterruptedException e) {
      e.printStackTrace();
      log.warn("InterruptedException:" + e.toString() + " for file " + lSrcFile + " to " + lDestPath);
    }
    return false;
  }
  
  /**
   * <b>isCp932</b> CP932
   * 
   * @param なし
   * @return なし
   * @throws なし
   */
  public static boolean isCp932() {
    
    String p = System.getProperty("iscp932");
    String os = System.getProperty("os.name");
    log.debug("p=" + p + ",os=" + os + ",Locale.getDefault().getLanguage()=" + Locale.getDefault().getLanguage());
    
    if (Locale.getDefault().getLanguage().equals("ja")) {
      if (p != null && Boolean.getBoolean(p)) return true;
      else if (os != null && (os.equals("Windows 95") || os.equals("Windows NT") || os.equals("Windows 2000") || os.equals("Windows XP"))) return true;
      else return false;
    } else return false;
    
  }
  
  /**
   * <b>CP932ToJIS</b> converts Cp932 to JIS.
   * 
   * @param String 対象文字列
   * @return なし
   * @throws なし
   */
  public static String CP932ToJIS(String s) {
    if (isNull(s)) return s;
    StringBuffer lResultBuf = new StringBuffer();
    int hex;
    char cc;
    for (int ii = 0; ii < s.length(); ii++) {
      cc = s.charAt(ii);
      hex = (int) s.charAt(ii);
      switch (cc) {
      /*
       * 7.4.0 ST2083 修正 ここから case 0x005c: // REVERSE SOLIDUS -> cc = 0xff3c; // FULLWIDTH REVERSE SOLIDUS break; 7.4.0 ST2083 修正 ここまで
       */
      /* 7.4.0 ST2060 修正 ここから */
      case 0x301c: // WAVE DASH ->
        cc = 0xff5e; // FULLWIDTH TILDE
        break;
      case 0x2016: // DOUBLE VERTICAL LINE ->
        cc = 0x2225; // PARALLEL TO
        break;
      case 0x2212: // MINUS SIGN ->
        cc = 0xff0d; // FULLWIDTH HYPHEN-MINUS
        break;
      case 0x00a2: // CENT SIGN ->
        cc = 0xffe0; // FULLWIDTH CENT SIGN
        break;
      case 0x00a3: // POUND SIGN ->
        cc = 0xffe1; // FULLWIDTH POUND SIGN
        break;
      case 0x00ac: // NOT SIGN ->
        cc = 0xffe2; // FULLWIDTH NOT SIGN
        break;
      case 0x2014: // HORIZONTAL BAR ->
        cc = 0x2015; // EM DASH
        break;
      /*
       * case 0x2460: cc=0xfffd; break; 7.4.0 ST2060 修正 ここまで
       */
      }
      lResultBuf.append(cc);
    }
    return lResultBuf.toString();
  }
  
  /**
   * <b>toCp932</b> converts JIS to Cp932.
   * 
   * @param String 対象文字列
   * @return なし
   * @throws なし
   */
  public static String JISToCp932(String s) {
    if (isNull(s)) return s;
    
    StringBuffer lResultBuf = new StringBuffer();
    char cc;
    for (int ii = 0; ii < s.length(); ii++) {
      cc = s.charAt(ii);
      switch (cc) {
      /*
       * 7.4.0 ST2083 修正 ここから case 0x005c: // REVERSE SOLIDUS -> cc = 0xff3c; // FULLWIDTH REVERSE SOLIDUS break; 7.4.0 ST2083 修正 ここまで
       */
      case 0x301c: // WAVE DASH ->
        cc = 0xff5e; // FULLWIDTH TILDE
        break;
      case 0x2016: // DOUBLE VERTICAL LINE ->
        cc = 0x2225; // PARALLEL TO
        break;
      case 0x2212: // MINUS SIGN ->
        cc = 0xff0d; // FULLWIDTH HYPHEN-MINUS
        break;
      case 0x00a2: // CENT SIGN ->
        cc = 0xffe0; // FULLWIDTH CENT SIGN
        break;
      case 0x00a3: // POUND SIGN ->
        cc = 0xffe1; // FULLWIDTH POUND SIGN
        break;
      case 0x00ac: // NOT SIGN ->
        cc = 0xffe2; // FULLWIDTH NOT SIGN
        break;
      case 0x2014: // EM DASH ->
        cc = 0x2015; // HORIZONTAL BAR
        break;
      }
      lResultBuf.append(cc);
    }
    return lResultBuf.toString();
  }
  
  public static String getDigitTel(String lTel) {
    if (SIUtil.isNull(lTel)) return "";
    StringBuffer lResBuf = new StringBuffer();
    for (int ii = 0; ii < lTel.length(); ii++) {
      char c = lTel.charAt(ii);
      if (Character.isDigit(c)) lResBuf.append(c);
    }
    return lResBuf.toString();
  }
  
  /**
   * <b>say</b> ミニメソッド
   */
  public static void say(String lStr) {
    System.out.println(lStr);
  }
  
  public static String selectedCheck(String menu, String currentMenu) {
    String css = "";
    if (currentMenu != null && currentMenu.equals(menu)) {
      css = "background-color: #66FFFF";
    }
    return css;
  }
  
  /**
   * 値引率の合計のチェックをする
   * 
   * @param str
   * @return
   */
  public static String CheckDiscount(String str) {
    try {
      int discount = Integer.parseInt(str);
      if (discount > 100) {
        return "100";
      } else if (discount < 0) { return "0"; }
    } catch (Exception e) {
      return "0";
    }
    return str;
  }
  
  /**
   * カンマを増やす
   * 
   * @param str
   */
  // 7.2.0 ST0100 SIQuantityTag.javaに移行
  public static String NumberFormat(String str) {
    int zan = 3 - str.length() % 3;
    StringBuffer strbuff = new StringBuffer();
    
    for (int i = 0; i < str.length(); i++) {
      if ((i + zan) % 3 == 0 && i != 0 && i != str.length()) {
        strbuff.append(",");
      }
      strbuff.append(str.charAt(i));
    }
    return strbuff.toString();
  }
  
  public static String getOS() {
    String lOs = System.getProperty("os.name");
    if (SIUtil.isNotNull(lOs) && lOs.startsWith("Windows")) {
      return SIConfig.SIOS_WINDOW_SERIES_NAME;
    } else if (SIUtil.isNotNull(lOs) && (lOs.startsWith("Linux") || lOs.startsWith("Unix"))) {
      return SIConfig.SIOS_UNIX_SERIES_NAME;
    } else return "";
  }
  
  public static String getOsFileName(String lFileName) {
    if (SIUtil.isNull(lFileName)) return lFileName;
    
    if (SIConfig.SIOS_CURRENT_NAME.equals(SIConfig.SIOS_WINDOW_SERIES_NAME)) {
      lFileName = SIStringUtil.replace(lFileName, "/", "\\");
    } else {
      lFileName = SIStringUtil.replace(lFileName, "\\", "/");
    }
    return lFileName;
  }
  
  public static boolean notIn(String str, int index) {
    if (SIUtil.isNull(str)) return true;
    String[][] list = SIFlagConf.SIFLAG_NAME[index];
    for (int i = 0; i < list.length; i++) {
      if (str.equals(list[i][1])) return false;
    }
    return true;
  }
  
  public static String flagNameList(int index) {
    StringBuffer str = new StringBuffer();
    String[][] list = SIFlagConf.SIFLAG_NAME[index];
    for (int i = 0; i < list.length; i++) {
      str.append("「" + list[i][1] + "」");
    }
    return str.toString();
  }
  
  public static String getVersion() {
    StringBuffer lVer = new StringBuffer();
    if (SIDBMultiConf.SIDB_CURRENT_INX == SIDBMultiConf.SIDB_POSTGRESQL_INX) lVer.append("P");
    else if (SIDBMultiConf.SIDB_CURRENT_INX == SIDBMultiConf.SIDB_ORACLE_INX) lVer.append("O");
    
    if (SIConfig.SIRUNNING_MODE_CURRENT == SIConfig.SIRUNNING_MODE_TOGETHER) lVer.append("括");
    else if (SIConfig.SIRUNNING_MODE_CURRENT == SIConfig.SIRUNNING_MODE_INDIVIDUAL) lVer.append("個");
    else if (SIConfig.SIRUNNING_MODE_CURRENT == SIConfig.SIRUNNING_MODE_SHOP) lVer.append("店");
    return lVer.toString();
  }
  
  // 7.1.1 ST0177 追加 ここから
  /**
   * <b>str2Int</b> 文字列を標準の数字列に変更します。
   * 
   * @param lSrc 文字列
   * @return 整数の文字列
   * @throws なし
   */
  public static String str2Int(String lSrc) {
    if (isNull(lSrc)) return lSrc;
    else {
      try {
        int lDes = Integer.parseInt(lSrc);
        return String.valueOf(lDes);
      } catch (NumberFormatException e) {
        return lSrc;
      }
    }
  }
  
  /**
   * <b>isDigit</b> 指定のデータが１〜９の半角数字でかどうかをチェックします。
   * 
   * @param lCheckedData チェック対象のデータ
   * @return true 半角数字 false 非半角数字
   * @throws なし
   */
  public static boolean isDigitNegative(String lCheckedData) {
    if (SIUtil.isNull(lCheckedData)) return true;
    RE negative = new RE("^\\-[0-9]*$");
    return (negative.match(lCheckedData)) && !lCheckedData.equals("-0");
  }
  
  /**
   * <b>setNegative</b> 反対の符号をつける（プラスはマイナス、プラス値はマイナスをつける）
   * 
   * @param lCheckedData チェック対象のデータ
   * @return 符号をつけた値
   * @throws なし
   */
  public static String setNegative(String lCheckedData) {
    String result = lCheckedData;
    if (isNull(lCheckedData) || lCheckedData.equals("0")) return result;
    
    if (isDigitNegative(lCheckedData) || SICheckUtil.isDigit(lCheckedData)) {
      result = String.valueOf(Long.parseLong(lCheckedData) - 2 * Long.parseLong(lCheckedData));
    } else {
      result = "0";
    }
    return result;
  }
  
  /**
   * <b>setSign</b> ＋符号をつける
   * 
   * @param lCheckedData 対象のデータ
   * @return 符号をつけた値
   * @throws なし
   */
  public static String setSign(String lCheckedData) {
    String result = lCheckedData;
    if (isNull(lCheckedData) || lCheckedData.equals("0") || lCheckedData.equals("-0")) return "0";
    if (Integer.parseInt(lCheckedData) > 0) result = "+" + result;
    return result;
  }
  
  /**
   * <b>setNegative</b> YYYYMM->YYYY/MM
   * 
   * @param lCheckedData チェック対象のデータ
   * @return 結果
   * @throws なし
   */
  public static String setDate(String lCheckedData) {
    String result = lCheckedData;
    if (isNull(lCheckedData)) result = "";
    if (lCheckedData.trim().length() == 6) {
      result = lCheckedData.trim().substring(0, 4) + "/" + lCheckedData.trim().substring(4, 6);
    }
    return result;
  }
  
  /**
   * <b>getAmountName</b> YYYYMMが入るとMMによってカラム名を作成（例：200604はamount4に変換される）
   * 
   * @param amountName 対象のデータ
   * @return 結果
   * @throws なし
   */
  public static String getAmountName(String amountName) {
    String result = "";
    result = "amount" + String.valueOf(Integer.parseInt(amountName.substring(4, 6)));
    return result;
  }
  
  /**
   * <b>getPreAmountName</b> YYYYMMが入るとMMによって前月のカラム名を作成（例：200604はamount3に変換される）
   * 
   * @param amountName 対象のデータ
   * @return 結果
   * @throws なし
   */
  public static String getPreAmountName(String amountName) {
    String result = "";
    if (Integer.parseInt(amountName.substring(4, 6)) == 1) {
      result = "amount12";
    } else {
      result = "amount" + SIUtil.sub(amountName.substring(4, 6), "1");
    }
    
    return result;
  }
  
  public static String getPreYearName(String season) {
    String result = "";
    if (Integer.parseInt(season.substring(4, 6)) == 1) {
      result = SIUtil.sub(season.substring(0, 4), "1");
    } else {
      result = season.substring(0, 4);
    }
    return result;
  }
  
  public static String getPreSeasonName(String season) {
    String result = "";
    if (Integer.parseInt(season.substring(4, 6)) == 1) {// 1月の場合
      result = SIUtil.sub(season.substring(0, 4), "1") + "12";
    } else if (Integer.parseInt(season.substring(4, 6)) > 11) {// 11月12月の場合
      result = season.substring(0, 4) + SIUtil.sub(season.substring(4, 6), "1");
    } else {// 2月〜10月の場合
      result = season.substring(0, 4) + "0" + SIUtil.sub(season.substring(4, 6), "1");
    }
    return result;
  }
  
  public static String getIntVal(String val) {
    double dval = 0.0;
    try {
      dval = Double.parseDouble(val);
      if (dval % 1 == 0.0) val = String.valueOf((int) dval);
    } catch (Exception e) {}
    return val;
  }
  
  public static Collection getAmountNumber(){
    SINameValue val = new SINameValue();
    Collection returnColl = new ArrayList();
    for (int i=1;i<100;i++){
      val = new SINameValue(String.valueOf(i),String.valueOf(i));
      returnColl.add(val);
    }
    return returnColl;
  }
  
  public static boolean isVariableCode(String code){
    for (int i=0;i<SIConfig.VARIABLE_CMDTY_CODE.length;i++){
      if (SIConfig.VARIABLE_CMDTY_CODE[i].equals(code)) return true;
    }
    return false;
  }
  
  public static String getPriceWithoutTax(String lPrice,String taxRate) {
    long num1 = 0;
    double num2 = 0;
    try {
      num1 = Long.parseLong(lPrice);
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + lPrice);
      num1 = 0;
    }
    try {
      num2 = Double.parseDouble(SIUtil.div_DL(taxRate, "100"));
    } catch (Exception e) {
      log.warn("not digit amount!!!lAmount=" + taxRate);
      num2 = 0;
    }
    // 端数切り上げ
    long ret = new Double(Math.ceil(num1 / (1+num2))).longValue();
    return String.valueOf(ret);
  }
}