package com.kcim.common.util;

/**
 * 通用工具类
 */
public class CommonUtil {

    /**
     * 校验字符串中括号是否闭合'[']'('')''{''}'
     *
     * @param str
     * @return
     */
    public static boolean whetherStringClose(String str) {
        int parenthesesNums = 0;//小括号数量
        int bracketsNums = 0;//中括号数量
        int bracesNums = 0;//大括号数量
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c == '{') {
                bracesNums += 1;
            }
            if (c == '[') {
                bracketsNums += 1;
            }
            if (c == '(') {
                parenthesesNums += 1;
            }
            if (c == '}') {
                bracesNums -= 1;
            }
            if (c == ']') {
                bracketsNums -= 1;
            }
            if (c == ')') {
                parenthesesNums -= 1;
            }
            if (parenthesesNums < 0 || bracesNums < 0 || bracketsNums < 0) {
                break;
            }
        }
        if (parenthesesNums != 0 || bracesNums != 0 || bracketsNums != 0) {
            return false;
        } else {
            return true;
        }

    }

    static Integer MAX_NUMBER = 500;

    public static Integer countStep(Integer size) {
        return (size + MAX_NUMBER - 1) / MAX_NUMBER;
    }


}
