package com.energy.manage.service.util;

import net.sourceforge.pinyin4j.PinyinHelper;
import org.apache.commons.lang3.StringUtils;

import java.util.Locale;

/**
 * @author chy
 * @date 2024/7/4 11:19
 * @desc
 */
public class PinYinUtils {

    /**
     * 获取汉字首字母
     * @param sourceStr
     * @return
     */
    public static String getPinYinHeadChar(String sourceStr) {
        if (StringUtils.isBlank(sourceStr)) {
            return "";
        }
        StringBuffer headChar = new StringBuffer();
        sourceStr.chars().mapToObj(c -> (char)c).forEach(item ->{
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(item);
            headChar.append(pinyinArray != null ? pinyinArray[0].charAt(0) : item);
        });
        return headChar.toString().toUpperCase();
    }

    public static void main(String[] args) {
        String a = "aaaa";
        a.toUpperCase();
        System.out.println(a);
    }
}
