mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
add methods
This commit is contained in:
parent
62f851142b
commit
cf9d2f62c1
@ -6,6 +6,7 @@
|
|||||||
# 5.8.1.M1 (2022-05-09)
|
# 5.8.1.M1 (2022-05-09)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
|
* 【core 】 BooleanUtil增加toBooleanObject方法(issue#I56AG3@Gitee)
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 MapUtil.map对null友好,且修复了测试用例中分组问题(pr#614@Gitee)
|
* 【core 】 MapUtil.map对null友好,且修复了测试用例中分组问题(pr#614@Gitee)
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ public class BooleanUtil {
|
|||||||
|
|
||||||
/** 表示为真的字符串 */
|
/** 表示为真的字符串 */
|
||||||
private static final Set<String> TRUE_SET = CollUtil.newHashSet("true", "yes", "y", "t", "ok", "1", "on", "是", "对", "真", "對", "√");
|
private static final Set<String> TRUE_SET = CollUtil.newHashSet("true", "yes", "y", "t", "ok", "1", "on", "是", "对", "真", "對", "√");
|
||||||
|
/** 表示为假的字符串 */
|
||||||
|
private static final Set<String> FALSE_SET = CollUtil.newHashSet("false", "no", "n", "f", "0", "off", "否", "错", "假", "錯", "×");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取相反值
|
* 取相反值
|
||||||
@ -85,6 +87,28 @@ public class BooleanUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换字符串为boolean值<br>
|
||||||
|
* 如果为["true", "yes", "y", "t", "ok", "1", "on", "是", "对", "真", "對", "√"],返回{@code true}<br>
|
||||||
|
* 如果为["false", "no", "n", "f", "0", "off", "否", "错", "假", "錯", "×"],返回{@code false}<br>
|
||||||
|
* 其他情况返回{@code null}
|
||||||
|
*
|
||||||
|
* @param valueStr 字符串
|
||||||
|
* @return boolean值
|
||||||
|
* @since 5.8.1
|
||||||
|
*/
|
||||||
|
public static Boolean toBooleanObject(String valueStr) {
|
||||||
|
if (StrUtil.isNotBlank(valueStr)) {
|
||||||
|
valueStr = valueStr.trim().toLowerCase();
|
||||||
|
if(TRUE_SET.contains(valueStr)){
|
||||||
|
return true;
|
||||||
|
} else if(FALSE_SET.contains(valueStr)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* boolean值转为int
|
* boolean值转为int
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user