diff --git a/CHANGELOG.md b/CHANGELOG.md index 18b91a983..ec106e7fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * 【core 】 增加StrMatcher(issue#1379@Github) * 【core 】 NumberUtil增加factorial针对BigInterger方法(issue#1379@Github) * 【core 】 TreeNode增加equals方法(issue#1467@Github) +* 【core 】 增加汉字转阿拉伯数字Convert.chineseToNumber(pr#1469@Github) ### Bug修复 * 【socket 】 修复Client创建失败资源未释放问题。 diff --git a/hutool-core/src/main/java/cn/hutool/core/convert/ChineseNameValue.java b/hutool-core/src/main/java/cn/hutool/core/convert/ChineseNameValue.java deleted file mode 100644 index 61822624e..000000000 --- a/hutool-core/src/main/java/cn/hutool/core/convert/ChineseNameValue.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.hutool.core.convert; - -/** - * @author totalo - * @since 5.6.0 - * 中文转数字结构 - */ -public final class ChineseNameValue { - /** - * 中文权名称 - */ - String name; - /** - * 10的倍数值 - */ - int value; - - /** - * 是否为节权位 - */ - boolean secUnit; - - public ChineseNameValue(String name, int value, boolean secUnit) { - this.name = name; - this.value = value; - this.secUnit = secUnit; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getValue() { - return value; - } - - public void setValue(int value) { - this.value = value; - } - - public boolean isSecUnit() { - return secUnit; - } - - public void setSecUnit(boolean secUnit) { - this.secUnit = secUnit; - } -} diff --git a/hutool-core/src/main/java/cn/hutool/core/convert/Convert.java b/hutool-core/src/main/java/cn/hutool/core/convert/Convert.java index d31e70478..b3a45362c 100644 --- a/hutool-core/src/main/java/cn/hutool/core/convert/Convert.java +++ b/hutool-core/src/main/java/cn/hutool/core/convert/Convert.java @@ -982,12 +982,27 @@ public class Convert { * 将阿拉伯数字转为中文表达方式 * * @param number 数字 - * @param isUseTraditonal 是否使用繁体字(金额形式) + * @param isUseTraditional 是否使用繁体字(金额形式) * @return 中文 * @since 3.2.3 */ - public static String numberToChinese(double number, boolean isUseTraditonal) { - return NumberChineseFormatter.format(number, isUseTraditonal); + public static String numberToChinese(double number, boolean isUseTraditional) { + return NumberChineseFormatter.format(number, isUseTraditional); + } + + /** + * 数字中文表示形式转数字 + *
- * 1. 数字转中文大写形式,比如一百二十一 - * 2. 数字转金额用的大写形式,比如:壹佰贰拾壹 - * 3. 转金额形式,比如:壹佰贰拾壹整 - *- * - * @author fanqun, looly - * @deprecated 请使用 {@link NumberChineseFormatter} - **/ -@Deprecated -public class NumberChineseFormater extends NumberChineseFormatter{ -} diff --git a/hutool-core/src/main/java/cn/hutool/core/convert/NumberChineseFormatter.java b/hutool-core/src/main/java/cn/hutool/core/convert/NumberChineseFormatter.java index 7b18ecce8..87f9aebce 100644 --- a/hutool-core/src/main/java/cn/hutool/core/convert/NumberChineseFormatter.java +++ b/hutool-core/src/main/java/cn/hutool/core/convert/NumberChineseFormatter.java @@ -1,5 +1,6 @@ package cn.hutool.core.convert; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; /** @@ -37,11 +38,11 @@ public class NumberChineseFormatter { * 汉字转阿拉伯数字的 */ private static final ChineseNameValue[] CHINESE_NAME_VALUE = { - new ChineseNameValue("十", 10, false), - new ChineseNameValue("百", 100, false), - new ChineseNameValue("千", 1000, false), - new ChineseNameValue("万", 10000, true), - new ChineseNameValue("亿", 100000000, true), + new ChineseNameValue("十", 10, false), + new ChineseNameValue("百", 100, false), + new ChineseNameValue("千", 1000, false), + new ChineseNameValue("万", 10000, true), + new ChineseNameValue("亿", 100000000, true), }; @@ -178,10 +179,6 @@ public class NumberChineseFormatter { * @return 转换后的汉字 */ private static String toChinese(int amountPart, boolean isUseTraditional) { -// if (amountPart < 0 || amountPart > 10000) { -// throw new IllegalArgumentException("Number must 0 < num < 10000!"); -// } - String[] numArray = isUseTraditional ? TRADITIONAL_DIGITS : SIMPLE_DIGITS; String[] units = isUseTraditional ? TRADITIONAL_UNITS : SIMPLE_UNITS; @@ -207,10 +204,16 @@ public class NumberChineseFormatter { } /** - * 把中文转换为数字 如 二百二 220 - * @see
true
支持,false
不支持
+ *
+ * @param isMatchSecond {@code true}支持,{@code false}不支持
*/
public static void setMatchSecond(boolean isMatchSecond) {
scheduler.setMatchSecond(isMatchSecond);
@@ -63,7 +63,7 @@ public class CronUtil {
/**
* 加入定时任务
- *
+ *
* @param schedulingPattern 定时任务执行时间的crontab表达式
* @param task 任务
* @return 定时任务ID
@@ -74,7 +74,7 @@ public class CronUtil {
/**
* 加入定时任务
- *
+ *
* @param id 定时任务ID
* @param schedulingPattern 定时任务执行时间的crontab表达式
* @param task 任务
@@ -88,7 +88,7 @@ public class CronUtil {
/**
* 加入定时任务
- *
+ *
* @param schedulingPattern 定时任务执行时间的crontab表达式
* @param task 任务
* @return 定时任务ID
@@ -99,7 +99,7 @@ public class CronUtil {
/**
* 批量加入配置文件中的定时任务
- *
+ *
* @param cronSetting 定时任务设置文件
*/
public static void schedule(Setting cronSetting) {
@@ -108,7 +108,7 @@ public class CronUtil {
/**
* 移除任务
- *
+ *
* @param schedulerId 任务ID
*/
public static void remove(String schedulerId) {
@@ -117,7 +117,7 @@ public class CronUtil {
/**
* 更新Task的执行时间规则
- *
+ *
* @param id Task的ID
* @param pattern {@link CronPattern}
* @since 4.0.10
@@ -135,7 +135,7 @@ public class CronUtil {
/**
* 开始,非守护线程模式
- *
+ *
* @see #start(boolean)
*/
public static void start() {
@@ -144,14 +144,14 @@ public class CronUtil {
/**
* 开始
- *
+ *
* @param isDaemon 是否以守护线程方式启动,如果为true,则在调用{@link #stop()}方法后执行的定时任务立即结束,否则等待执行完毕才结束。
*/
synchronized public static void start(boolean isDaemon) {
if (scheduler.isStarted()) {
throw new UtilException("Scheduler has been started, please stop it first!");
}
-
+
lock.lock();
try {
if (null == crontabSetting) {
@@ -188,7 +188,7 @@ public class CronUtil {
} finally {
lock.unlock();
}
-
+
//重新加载任务
schedule(crontabSetting);
//重新启动