+ * Name =》name + * name =》name + * CPU =》CPU + *+ * + * @param name 字段名称 + * @return 转换后的名称 + * @see java.beans.Introspector#decapitalize(String) + */ + public static String decapitalize(final CharSequence name) { + return Introspector.decapitalize(StrUtil.toStringOrNull(name)); + } + + /** + * 获得set或get或is方法对应的标准属性名
+ * getName =》name + * setName =》name + * isName =》name + *+ *
+ * 需要注意的是,相比{@link java.beans.Introspector#decapitalize(String)},此方法始终小写第一个字符。
+ *
+ * @param getOrSetMethodName Get或Set方法名
+ * @return 如果是set或get方法名,返回field, 否则null
+ * @see java.beans.Introspector#decapitalize(String)
+ */
+ public static String getGeneralField(final CharSequence getOrSetMethodName) {
+ Assert.notBlank(getOrSetMethodName);
+ final String getOrSetMethodNameStr = getOrSetMethodName.toString();
+ if (getOrSetMethodNameStr.startsWith(GET_PREFIX) || getOrSetMethodNameStr.startsWith(SET_PREFIX)) {
+ return StrUtil.removePreAndLowerFirst(getOrSetMethodName, 3);
+ } else if (getOrSetMethodNameStr.startsWith(IS_PREFIX)) {
+ return StrUtil.removePreAndLowerFirst(getOrSetMethodName, 2);
+ }
+ return null;
+ }
+
+ /**
+ * 生成set方法名
+ * 例如:name 返回 setName
+ *
+ * @param fieldName 属性名
+ * @return setXxx
+ */
+ public static String genSetter(final CharSequence fieldName) {
+ return StrUtil.upperFirstAndAddPre(fieldName, SET_PREFIX);
+ }
+
+ /**
+ * 生成get方法名
+ *
+ * @param fieldName 属性名
+ * @return getXxx
+ */
+ public static String genGetter(final CharSequence fieldName) {
+ return StrUtil.upperFirstAndAddPre(fieldName, GET_PREFIX);
+ }
+}
diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodUtil.java
index a7dbcf157..0a84e8456 100644
--- a/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodUtil.java
+++ b/hutool-core/src/main/java/org/dromara/hutool/core/reflect/method/MethodUtil.java
@@ -482,14 +482,14 @@ public class MethodUtil {
String name = method.getName();
// 跳过set这类特殊方法
- if ("set".equals(name)) {
+ if (name.length() < 4) {
return false;
}
if (ignoreCase) {
name = name.toLowerCase();
}
- return name.startsWith("set");
+ return name.startsWith(MethodNameUtil.SET_PREFIX);
}
/**
@@ -511,14 +511,18 @@ public class MethodUtil {
}
// 参数个数必须为0或1
- final int parameterCount = method.getParameterCount();
- if (0 != parameterCount) {
+ if (0 != method.getParameterCount()) {
+ return false;
+ }
+
+ // 必须有返回值
+ if(Void.class == method.getReturnType()){
return false;
}
String name = method.getName();
// 跳过getClass、get、is这类特殊方法
- if ("getClass".equals(name) || "get".equals(name) || "is".equals(name)) {
+ if (name.length() < 3 || "getClass".equals(name) || MethodNameUtil.GET_PREFIX.equals(name)) {
return false;
}
@@ -526,11 +530,11 @@ public class MethodUtil {
name = name.toLowerCase();
}
- if (name.startsWith("is")) {
+ if (name.startsWith(MethodNameUtil.IS_PREFIX)) {
// 判断返回值是否为Boolean
return BooleanUtil.isBoolean(method.getReturnType());
}
- return name.startsWith("get");
+ return name.startsWith(MethodNameUtil.GET_PREFIX);
}
// region ----- invoke
diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/regex/ReUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/regex/ReUtil.java
index 5280c9d38..9e8f1cb55 100644
--- a/hutool-core/src/main/java/org/dromara/hutool/core/regex/ReUtil.java
+++ b/hutool-core/src/main/java/org/dromara/hutool/core/regex/ReUtil.java
@@ -12,7 +12,6 @@
package org.dromara.hutool.core.regex;
-import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.collection.set.SetUtil;
import org.dromara.hutool.core.comparator.CompareUtil;
import org.dromara.hutool.core.comparator.StrLengthComparator;
@@ -867,33 +866,42 @@ public class ReUtil {
*
* @param content 文本
* @param pattern {@link Pattern}
- * @param replacementTemplate 替换的文本模板,可以使用$1类似的变量提取正则匹配出的内容
+ * @param replacementTemplate 替换的文本模板,可以使用$1类似的变量提取正则匹配出的内容,null表示去除匹配
* @return 处理后的文本
* @since 3.0.4
*/
- public static String replaceAll(final CharSequence content, final Pattern pattern, final String replacementTemplate) {
- if(null != pattern && StrUtil.isNotEmpty(content) && StrUtil.isNotEmpty(replacementTemplate)){
- final Matcher matcher = pattern.matcher(content);
- boolean result = matcher.find();
- if (result) {
- final Set
- * 例如:setName 返回 name
- *
- *
- * getName =》name
- * setName =》name
- * isName =》name
- *
- *
- * @param getOrSetMethodName Get或Set方法名
- * @return 如果是set或get方法名,返回field, 否则null
- */
- public static String getGeneralField(final CharSequence getOrSetMethodName) {
- final String getOrSetMethodNameStr = getOrSetMethodName.toString();
- if (getOrSetMethodNameStr.startsWith("get") || getOrSetMethodNameStr.startsWith("set")) {
- return removePreAndLowerFirst(getOrSetMethodName, 3);
- } else if (getOrSetMethodNameStr.startsWith("is")) {
- return removePreAndLowerFirst(getOrSetMethodName, 2);
- }
- return null;
- }
-
- /**
- * 生成set方法名
- * 例如:name 返回 setName
- *
- * @param fieldName 属性名
- * @return setXxx
- */
- public static String genSetter(final CharSequence fieldName) {
- return upperFirstAndAddPre(fieldName, "set");
- }
-
- /**
- * 生成get方法名
- *
- * @param fieldName 属性名
- * @return getXxx
- */
- public static String genGetter(final CharSequence fieldName) {
- return upperFirstAndAddPre(fieldName, "get");
- }
-
// ------------------------------------------------------------------------ other
/**
diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/xml/XmlUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/xml/XmlUtil.java
index f6e7c8d53..5256b59c5 100644
--- a/hutool-core/src/main/java/org/dromara/hutool/core/xml/XmlUtil.java
+++ b/hutool-core/src/main/java/org/dromara/hutool/core/xml/XmlUtil.java
@@ -135,8 +135,9 @@ public class XmlUtil extends XmlConstants {
*/
public static Document parseXml(final String xmlStr) {
if (StrUtil.isBlank(xmlStr)) {
- throw new IllegalArgumentException("XML content string is empty !");
+ throw new IllegalArgumentException("XML content string is blank !");
}
+
return readXml(StrUtil.getReader(cleanInvalid(xmlStr)));
}
// endregion
diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/bean/BeanDescTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/bean/BeanDescTest.java
index eab6856b9..52b277510 100644
--- a/hutool-core/src/test/java/org/dromara/hutool/core/bean/BeanDescTest.java
+++ b/hutool-core/src/test/java/org/dromara/hutool/core/bean/BeanDescTest.java
@@ -89,6 +89,22 @@ public class BeanDescTest {
Assertions.assertEquals("张三", value);
}
+ @Test
+ void simpleBeanDescTest() {
+ final SimpleBeanDesc desc = new SimpleBeanDesc(User.class);
+
+ final User user = new User();
+ desc.getProp("name").setValue(user, "张三");
+ Assertions.assertEquals("张三", user.getName());
+ Object value = desc.getProp("name").getValue(user);
+ Assertions.assertEquals("张三", value);
+
+ desc.getProp("admin").setValue(user, true);
+ Assertions.assertTrue(user.isAdmin());
+ value = desc.getProp("admin").getValue(user);
+ Assertions.assertEquals(true, value);
+ }
+
public static class User {
private String name;
private int age;
diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/util/Issue3136Test.java b/hutool-core/src/test/java/org/dromara/hutool/core/util/Issue3136Test.java
index b4383bdbd..d98285a7e 100755
--- a/hutool-core/src/test/java/org/dromara/hutool/core/util/Issue3136Test.java
+++ b/hutool-core/src/test/java/org/dromara/hutool/core/util/Issue3136Test.java
@@ -16,6 +16,7 @@ import lombok.Data;
import org.dromara.hutool.core.xml.XmlUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.w3c.dom.Document;
import java.util.ArrayList;
import java.util.List;
@@ -31,7 +32,8 @@ public class Issue3136Test {
@Test
void xmlToBeanTest() {
final String xmlStr = "02