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