package com.seeyon.apps.src_financing.util;

import java.util.HashMap;
import java.util.Map;

public class NumberUtil {

    private  static final Map<Character,Integer> numberMap = new HashMap<Character, Integer>() {{
        put('一',1);
        put('二',2);
        put('三',3);
        put('四',4);
        put('五',5);
        put('六',6);
        put('七',7);
        put('八',8);
        put('九',9);
        put('十',10);
        put('百',100);
        put('千',1000);
    }};
    public static int convertChineseNumberToArabic(String chineseNumber){
        int result = 0 ;
        int partiaResult = 0 ;
        for(int i = 0 ; i < chineseNumber.length() ; i++){
            char c = chineseNumber.charAt(i);
            int currentNumber = numberMap.get(c);
            if(currentNumber<10){
                partiaResult += currentNumber;
            }else{
                if(partiaResult == 0 ){
                    partiaResult = 1;
                }
                result += partiaResult*currentNumber;
                partiaResult = 0;
            }
        }
        return result + partiaResult;
    }

    public static void main(String[] arge){
        String chinsesNumber = "二十一";
        int arabicNumber = convertChineseNumberToArabic(chinsesNumber);
        System.out.println(chinsesNumber + "转换为阿拉伯数字是："+arabicNumber);
    }

}
