Переглянути джерело

Merge remote-tracking branch 'origin/dev/formula_20220301' into dev/formula_20220301

zhoutg 3 роки тому
батько
коміт
4302ca1ade
2 змінених файлів з 18 додано та 15 видалено
  1. 0 1
      common/pom.xml
  2. 18 14
      common/src/main/java/com/diagbot/util/Cn2SpellUtil.java

+ 0 - 1
common/pom.xml

@@ -118,7 +118,6 @@
             <groupId>com.github.promeg</groupId>
             <artifactId>tinypinyin</artifactId>
             <version>2.0.3</version>
-            <scope>compile</scope>
         </dependency>
 
         <dependency>

+ 18 - 14
common/src/main/java/com/diagbot/util/Cn2SpellUtil.java

@@ -17,6 +17,12 @@ public class Cn2SpellUtil {
 
     }
 
+    //调用类时自动加载字典
+    static{
+        init();
+    }
+
+    //字典设置
     public static void init() {
         Pinyin.init(Pinyin.newConfig()
                 .with(new PinyinMapDict() {
@@ -39,7 +45,6 @@ public class Cn2SpellUtil {
      * @return 拼音
      */
     public static String converterToFirstSpell(String chines) {
-        init();
         String pinyinName = "";
         String pinyinRes = Pinyin.toPinyin(chines, "*××*");
         if (StringUtil.isNotBlank(pinyinRes)){
@@ -82,7 +87,6 @@ public class Cn2SpellUtil {
      * @return 拼音
      */
     private static String converterToSpellByCaseType(String chines, Integer caseType) {
-        init();
         String pinyinName = "";
         if (caseType.equals(2)) {
             pinyinName = Pinyin.toPinyin(chines, "").toLowerCase();
@@ -94,19 +98,19 @@ public class Cn2SpellUtil {
 
     public static void main(String[] args) {
         System.out.println("================首字母================");
-        System.out.println(converterToFirstSpell("欢迎来到Java世界"));
-        System.out.println(converterToFirstSpell("11β-羟化酶缺陷症#11-羟化酶缺陷"));
-        System.out.println(converterToFirstSpell("-"));
-        System.out.println(converterToFirstSpell("𬌗-𧿹"));
+        System.out.println(Cn2SpellUtil.converterToFirstSpell("欢迎来到Java世界"));
+        System.out.println(Cn2SpellUtil.converterToFirstSpell("11β-羟化酶缺陷症#11-羟化酶缺陷"));
+        System.out.println(Cn2SpellUtil.converterToFirstSpell("-"));
+        System.out.println(Cn2SpellUtil.converterToFirstSpell("𬌗-𧿹"));
         System.out.println("================大写全拼================");
-        System.out.println(converterToSpell("欢迎来到Java世界"));
-        System.out.println(converterToSpell("11β-羟化酶缺陷症#11-羟化酶缺陷"));
-        System.out.println(converterToSpell("-"));
-        System.out.println(converterToSpell("𬌗-𧿹"));
+        System.out.println(Cn2SpellUtil.converterToSpell("欢迎来到Java世界"));
+        System.out.println(Cn2SpellUtil.converterToSpell("11β-羟化酶缺陷症#11-羟化酶缺陷"));
+        System.out.println(Cn2SpellUtil.converterToSpell("-"));
+        System.out.println(Cn2SpellUtil.converterToSpell("𬌗-𧿹"));
         System.out.println("================小写全拼================");
-        System.out.println(converterToSpellLow("欢迎来到Java世界"));
-        System.out.println(converterToSpellLow("11β-羟化酶缺陷症#11-羟化酶缺陷"));
-        System.out.println(converterToSpellLow("-"));
-        System.out.println(converterToSpellLow("𬌗-𧿹"));
+        System.out.println(Cn2SpellUtil.converterToSpellLow("欢迎来到Java世界"));
+        System.out.println(Cn2SpellUtil.converterToSpellLow("11β-羟化酶缺陷症#11-羟化酶缺陷"));
+        System.out.println(Cn2SpellUtil.converterToSpellLow("-"));
+        System.out.println(Cn2SpellUtil.converterToSpellLow("𬌗-𧿹"));
     }
 }