/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.commons.lang3.StringUtils
 */
package com.hst.framework.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import org.apache.commons.lang3.StringUtils;

public class HstNumberUtil {
    public static final BigDecimal ZERO_BIGDECIMAL = new BigDecimal("0.00");
    private String[] saChnAmount = new String[50];
    private int iArrayLen = 0;
    private int iArrayPos = 0;

    public HstNumberUtil(String sAmount) {
        int iDecFrac = 0;
        if (sAmount.indexOf(".") != -1) {
            iDecFrac = sAmount.length() - sAmount.indexOf(".");
            if (iDecFrac > 3) {
                iDecFrac = 3;
            }
            sAmount = String.valueOf(sAmount.substring(0, sAmount.indexOf("."))) + sAmount.substring(sAmount.indexOf(".") + 1, sAmount.indexOf(".") + iDecFrac);
            while (iDecFrac < 3) {
                sAmount = String.valueOf(sAmount) + "0";
                ++iDecFrac;
            }
        } else {
            sAmount = String.valueOf(sAmount) + "00";
        }
        this.toChnAmt(sAmount, 2, false);
    }

    public HstNumberUtil(String sAmount, int iDec, boolean bDot) {
        if (bDot) {
            if (sAmount.indexOf(".") < 0) {
                sAmount = String.valueOf(sAmount) + ".";
                int iFor = iDec;
                while (iFor > 0) {
                    sAmount = String.valueOf(sAmount) + "0";
                    --iFor;
                }
            } else {
                int iDecLen = sAmount.length() - sAmount.indexOf(".") - 1;
                if (iDecLen > iDec) {
                    sAmount = sAmount.substring(0, sAmount.indexOf(".") + iDec + 1);
                } else if (iDecLen < iDec) {
                    int iFor = iDec - iDecLen;
                    while (iFor > 0) {
                        sAmount = String.valueOf(sAmount) + "0";
                        --iFor;
                    }
                }
            }
        }
        this.toChnAmt(sAmount, iDec, bDot);
    }

    public void toChnAmt(String sAmount, int iDec, boolean bDot) {
        String[] sUserCode = new String[]{"\u96f6", "\u58f9", "\u8d30", "\u53c1", "\u8086", "\u4f0d", "\u9646", "\u67d2", "\u634c", "\u7396"};
        String[] sChnUnit = new String[]{"\u5398", "\u5206", "\u89d2", "\u5143", "\u62fe", "\u4f70", "\u4edf", "\u4e07", "\u62fe", "\u4f70", "\u4edf", "\u4ebf", "\u62fe", "\u4f70", "\u4edf", "\u4e07"};
        byte[] byArray = new byte[16];
        byArray[3] = 3;
        byArray[4] = 9;
        byArray[7] = 1;
        byArray[8] = 9;
        byArray[11] = 3;
        byArray[12] = 9;
        byte[] byFlag = byArray;
        int byPreFlag = -1;
        int cPreDigit = 0;
        this.iArrayLen = 0;
        switch (iDec) {
            case 0: {
                sAmount = String.valueOf(sAmount) + "0";
            }
            case 1: {
                sAmount = String.valueOf(sAmount) + "0";
            }
            case 2: {
                sAmount = String.valueOf(sAmount) + "0";
            }
            case 3: {
                break;
            }
            default: {
                sAmount = sAmount.substring(0, sAmount.length() - iDec + 3);
            }
        }
        if (bDot) {
            sAmount = String.valueOf(sAmount.substring(0, sAmount.length() - 4)) + sAmount.substring(sAmount.length() - 3);
        }
        int iCounter = sAmount.length();
        while (iCounter > 0) {
            block20: {
                int cDigit;
                block19: {
                    block18: {
                        int iPos = sAmount.length() - iCounter;
                        cDigit = sAmount.charAt(iPos);
                        if (cDigit < 48 || cDigit > 57) {
                            cDigit = 48;
                        }
                        if (cDigit == 48) break block18;
                        if (cPreDigit == 48 && byPreFlag != 3 && byPreFlag != 1) {
                            this.saChnAmount[++this.iArrayLen] = sUserCode[0];
                        }
                        if (cDigit == 49 && byFlag[iCounter - 1] == 9 && this.iArrayLen == 0) {
                            this.saChnAmount[++this.iArrayLen] = sChnUnit[iCounter - 1];
                        } else {
                            this.saChnAmount[++this.iArrayLen] = sUserCode[Character.digit((char)cDigit, 10)];
                            this.saChnAmount[++this.iArrayLen] = sChnUnit[iCounter - 1];
                            byPreFlag = byFlag[iCounter - 1];
                        }
                        break block19;
                    }
                    if (this.iArrayLen == 0) break block20;
                    if (byFlag[iCounter - 1] == 3 || byFlag[iCounter - 1] == 1 && byPreFlag != 3 && !this.saChnAmount[this.iArrayLen].equals(sChnUnit[11])) {
                        this.saChnAmount[++this.iArrayLen] = sChnUnit[iCounter - 1];
                    }
                    byPreFlag = byFlag[iCounter - 1];
                }
                cPreDigit = cDigit;
            }
            --iCounter;
        }
        if (this.iArrayLen == 0) {
            this.saChnAmount[++this.iArrayLen] = sUserCode[0];
            this.saChnAmount[++this.iArrayLen] = sChnUnit[3];
            this.saChnAmount[++this.iArrayLen] = "\u6574";
        }
        if (this.saChnAmount[this.iArrayLen].equals(sChnUnit[2]) || this.saChnAmount[this.iArrayLen].equals(sChnUnit[3])) {
            this.saChnAmount[++this.iArrayLen] = "\u6574";
        }
    }

    public boolean next() {
        boolean bRtn = false;
        if (this.iArrayPos++ < this.iArrayLen) {
            bRtn = true;
        }
        return bRtn;
    }

    public String getCurResult() {
        String sRtn = "";
        sRtn = this.saChnAmount[this.iArrayPos];
        return sRtn;
    }

    public static String Double2String(double dMoney) {
        String sMoney = "";
        DecimalFormat df = new DecimalFormat("############.###");
        try {
            sMoney = df.format(dMoney);
        }
        catch (Exception exception) {
            sMoney = "";
        }
        return sMoney;
    }

    public static String BigDecimal2String(BigDecimal dMoney) {
        String sMoney = "";
        DecimalFormat df = new DecimalFormat("############.###");
        try {
            sMoney = df.format(dMoney);
        }
        catch (Exception exception) {
            sMoney = "";
        }
        return sMoney;
    }

    public static String getResult(String number) {
        HstNumberUtil numberEx = new HstNumberUtil(number);
        String result = "";
        while (numberEx.next()) {
            result = String.valueOf(result) + numberEx.getCurResult();
        }
        return result;
    }

    public static double parseDouble(String temp) {
        return StringUtils.isEmpty((CharSequence)temp) ? 0.0 : Double.parseDouble(temp);
    }

    public static BigDecimal parseBigDecimal(String temp) {
        return StringUtils.isEmpty((CharSequence)temp) ? ZERO_BIGDECIMAL : new BigDecimal(temp);
    }

    public static BigDecimal multiply(BigDecimal left, BigDecimal right) {
        return left.multiply(right).setScale(6, 4);
    }

    public static BigDecimal multiply(int scale, BigDecimal left, BigDecimal right) {
        return left.multiply(right).setScale(scale, 4);
    }
}
