package znx.utils;

import java.util.Random;

public class StringUtils {



    /**
     * 判断字符串为null或者为""或者由空白组成,返回true;否则返回false
     *
     * @param instr
     * @return
     */
    public static Boolean isNullOrWhiteSpace(String instr)
    {
        if (instr == null || instr.trim().length() == 0)
        {
            return true;
        }
        return false;
    }

    /***
     *
     * @Title: getRandomString
     * @Description: 随机产生字符串
     * @author 准女婿
     * @param length 位数
     * @param type 1-大小写+数字；2-小写+数字；3-大写+数字；4-小写；5-大写；其它-数字
     * @return
     * @throws
     */
    public static String getRandomString(int length, int type) {
        String str = "";
        switch(type){
            case 1 : str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; break;
            case 2 : str = "abcdefghijklmnopqrstuvwxyz1234567890"; break;
            case 3 : str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; break;
            case 4 : str = "abcdefghijklmnopqrstuvwxyz"; break;
            case 5 : str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; break;
            default : str = "1234567890"; break;
        }
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; ++i) {
            sb.append(str.charAt(random.nextInt(str.length())));
        }
        return sb.toString();
    }
}
