mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
Merge branch 'v6-dev' of gitee.com:dromara/hutool into v6-dev
This commit is contained in:
commit
aa20cb3921
@ -156,8 +156,7 @@ public class BeanDesc implements Serializable {
|
||||
PropDesc prop;
|
||||
for (final Field field : FieldUtil.getFields(this.beanClass)) {
|
||||
// 排除静态属性和对象子类
|
||||
if (!ModifierUtil.isStatic(field) &&
|
||||
!FieldUtil.isOuterClassField(field)) {
|
||||
if (!ModifierUtil.isStatic(field) && !FieldUtil.isOuterClassField(field)) {
|
||||
prop = createProp(field, gettersAndSetters);
|
||||
// 只有不存在时才放入,防止父类属性覆盖子类属性
|
||||
this.propMap.putIfAbsent(prop.getFieldName(), prop);
|
||||
|
@ -13,8 +13,11 @@
|
||||
package org.dromara.hutool.core.text.placeholder;
|
||||
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.lang.mutable.MutableEntry;
|
||||
import org.dromara.hutool.core.map.WeakConcurrentMap;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.core.text.placeholder.template.NamedPlaceholderStrTemplate;
|
||||
import org.dromara.hutool.core.text.placeholder.template.SinglePlaceholderStrTemplate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -24,6 +27,7 @@ import java.util.Map;
|
||||
* @author Looly
|
||||
*/
|
||||
public class StrFormatter {
|
||||
private static final WeakConcurrentMap<Map.Entry<CharSequence, Object>, StrTemplate> CACHE = new WeakConcurrentMap<>();
|
||||
|
||||
/**
|
||||
* 格式化字符串<br>
|
||||
@ -61,9 +65,8 @@ public class StrFormatter {
|
||||
if (StrUtil.isBlank(strPattern) || StrUtil.isBlank(placeHolder) || ArrayUtil.isEmpty(argArray)) {
|
||||
return strPattern;
|
||||
}
|
||||
return StrTemplate.of(strPattern)
|
||||
.placeholder(placeHolder)
|
||||
.build()
|
||||
return ((SinglePlaceholderStrTemplate) CACHE.computeIfAbsent(MutableEntry.of(strPattern, placeHolder), k ->
|
||||
StrTemplate.of(strPattern).placeholder(placeHolder).build()))
|
||||
.format(argArray);
|
||||
}
|
||||
|
||||
@ -85,12 +88,21 @@ public class StrFormatter {
|
||||
return template.toString();
|
||||
}
|
||||
|
||||
final NamedPlaceholderStrTemplate.Builder builder = StrTemplate.ofNamed(template.toString());
|
||||
if (ignoreNull) {
|
||||
builder.addFeatures(StrTemplate.Feature.FORMAT_NULL_VALUE_TO_WHOLE_PLACEHOLDER);
|
||||
} else {
|
||||
builder.addFeatures(StrTemplate.Feature.FORMAT_NULL_VALUE_TO_EMPTY);
|
||||
}
|
||||
return builder.build().format(map);
|
||||
return ((NamedPlaceholderStrTemplate) CACHE.computeIfAbsent(MutableEntry.of(template, ignoreNull), k -> {
|
||||
final NamedPlaceholderStrTemplate.Builder builder = StrTemplate.ofNamed(template.toString());
|
||||
if (ignoreNull) {
|
||||
builder.addFeatures(StrTemplate.Feature.FORMAT_NULL_VALUE_TO_WHOLE_PLACEHOLDER);
|
||||
} else {
|
||||
builder.addFeatures(StrTemplate.Feature.FORMAT_NULL_VALUE_TO_EMPTY);
|
||||
}
|
||||
return builder.build();
|
||||
})).format(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
public static void clear() {
|
||||
CACHE.clear();
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,14 @@ public class BeanDescTest {
|
||||
Assertions.assertEquals("setIsSuper", desc.getSetter("isSuper").getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propDescOfBooleanTest3() {
|
||||
final BeanDesc desc = BeanUtil.getBeanDesc(User.class);
|
||||
|
||||
Assertions.assertEquals("setLastPage", desc.getSetter("lastPage").getName());
|
||||
Assertions.assertEquals("setIsLastPage", desc.getSetter("isLastPage").getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSetTest() {
|
||||
final BeanDesc desc = BeanUtil.getBeanDesc(User.class);
|
||||
@ -72,6 +80,8 @@ public class BeanDescTest {
|
||||
private boolean isAdmin;
|
||||
private boolean isSuper;
|
||||
private boolean gender;
|
||||
private Boolean lastPage;
|
||||
private Boolean isLastPage;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -118,6 +128,22 @@ public class BeanDescTest {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public Boolean getIsLastPage() {
|
||||
return this.isLastPage;
|
||||
}
|
||||
|
||||
public void setIsLastPage(final Boolean isLastPage) {
|
||||
this.isLastPage = isLastPage;
|
||||
}
|
||||
|
||||
public Boolean getLastPage() {
|
||||
return this.lastPage;
|
||||
}
|
||||
|
||||
public void setLastPage(final Boolean lastPage) {
|
||||
this.lastPage = lastPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User [name=" + name + ", age=" + age + ", isAdmin=" + isAdmin + ", gender=" + gender + "]";
|
||||
|
Loading…
Reference in New Issue
Block a user