add method

This commit is contained in:
Looly 2021-07-08 00:38:31 +08:00
parent ead5e1c13a
commit ba9bfee1b6
2 changed files with 43 additions and 24 deletions

View File

@ -3,7 +3,7 @@
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.7.4 (2021-07-06) # 5.7.4 (2021-07-08)
### 🐣新特性 ### 🐣新特性
* 【crypto 】 SmUtil.sm4统一返回类型issue#I3YKD4@Gitee * 【crypto 】 SmUtil.sm4统一返回类型issue#I3YKD4@Gitee
@ -12,6 +12,7 @@
* 【core 】 CsvWriter增加writer.write(csvData)的方法重载pr#353@Gitee * 【core 】 CsvWriter增加writer.write(csvData)的方法重载pr#353@Gitee
* 【core 】 新增AbsCollValueMapissue#I3YXF0@Gitee * 【core 】 新增AbsCollValueMapissue#I3YXF0@Gitee
* 【crypto 】 HOPT缓存改为8位新增方法pr#356@Gitee * 【crypto 】 HOPT缓存改为8位新增方法pr#356@Gitee
* 【setting】 Props增加toProperties方法issue#1701@Github
### 🐞Bug修复 ### 🐞Bug修复
* 【core 】 修复RadixUtil.decode非static问题issue#I3YPEH@Gitee * 【core 】 修复RadixUtil.decode非static问题issue#I3YPEH@Gitee

View File

@ -61,10 +61,14 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
} }
// ----------------------------------------------------------------------- 私有属性 start // ----------------------------------------------------------------------- 私有属性 start
/** 属性文件的URL */ /**
* 属性文件的URL
*/
private URL propertiesFileUrl; private URL propertiesFileUrl;
private WatchMonitor watchMonitor; private WatchMonitor watchMonitor;
/** properties文件编码 */ /**
* properties文件编码
*/
private Charset charset = CharsetUtil.CHARSET_ISO_8859_1; private Charset charset = CharsetUtil.CHARSET_ISO_8859_1;
// ----------------------------------------------------------------------- 私有属性 end // ----------------------------------------------------------------------- 私有属性 end
@ -81,7 +85,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
/** /**
* 获得Classpath下的Properties文件 * 获得Classpath下的Properties文件
* *
* @param resource 资源相对Classpath的路径 * @param resource 资源相对Classpath的路径
* @param charsetName 字符集 * @param charsetName 字符集
* @return Properties * @return Properties
*/ */
@ -93,7 +97,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
* 获得Classpath下的Properties文件 * 获得Classpath下的Properties文件
* *
* @param resource 资源相对Classpath的路径 * @param resource 资源相对Classpath的路径
* @param charset 字符集 * @param charset 字符集
* @return Properties * @return Properties
*/ */
public static Props getProp(String resource, Charset charset) { public static Props getProp(String resource, Charset charset) {
@ -101,6 +105,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
} }
// ----------------------------------------------------------------------- 构造方法 start // ----------------------------------------------------------------------- 构造方法 start
/** /**
* 构造 * 构造
*/ */
@ -119,7 +124,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
/** /**
* 构造使用相对于Class文件根目录的相对路径 * 构造使用相对于Class文件根目录的相对路径
* *
* @param path 相对或绝对路径 * @param path 相对或绝对路径
* @param charsetName 字符集 * @param charsetName 字符集
*/ */
public Props(String path, String charsetName) { public Props(String path, String charsetName) {
@ -129,7 +134,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
/** /**
* 构造使用相对于Class文件根目录的相对路径 * 构造使用相对于Class文件根目录的相对路径
* *
* @param path 相对或绝对路径 * @param path 相对或绝对路径
* @param charset 字符集 * @param charset 字符集
*/ */
public Props(String path, Charset charset) { public Props(String path, Charset charset) {
@ -153,7 +158,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
* 构造 * 构造
* *
* @param propertiesFile 配置文件对象 * @param propertiesFile 配置文件对象
* @param charsetName 字符集 * @param charsetName 字符集
*/ */
public Props(File propertiesFile, String charsetName) { public Props(File propertiesFile, String charsetName) {
this(propertiesFile, Charset.forName(charsetName)); this(propertiesFile, Charset.forName(charsetName));
@ -163,7 +168,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
* 构造 * 构造
* *
* @param propertiesFile 配置文件对象 * @param propertiesFile 配置文件对象
* @param charset 字符集 * @param charset 字符集
*/ */
public Props(File propertiesFile, Charset charset) { public Props(File propertiesFile, Charset charset) {
Assert.notNull(propertiesFile, "Null properties file!"); Assert.notNull(propertiesFile, "Null properties file!");
@ -174,7 +179,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
/** /**
* 构造相对于classes读取文件 * 构造相对于classes读取文件
* *
* @param path 相对路径 * @param path 相对路径
* @param clazz 基准类 * @param clazz 基准类
*/ */
public Props(String path, Class<?> clazz) { public Props(String path, Class<?> clazz) {
@ -184,8 +189,8 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
/** /**
* 构造相对于classes读取文件 * 构造相对于classes读取文件
* *
* @param path 相对路径 * @param path 相对路径
* @param clazz 基准类 * @param clazz 基准类
* @param charsetName 字符集 * @param charsetName 字符集
*/ */
public Props(String path, Class<?> clazz, String charsetName) { public Props(String path, Class<?> clazz, String charsetName) {
@ -195,8 +200,8 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
/** /**
* 构造相对于classes读取文件 * 构造相对于classes读取文件
* *
* @param path 相对路径 * @param path 相对路径
* @param clazz 基准类 * @param clazz 基准类
* @param charset 字符集 * @param charset 字符集
*/ */
public Props(String path, Class<?> clazz, Charset charset) { public Props(String path, Class<?> clazz, Charset charset) {
@ -220,7 +225,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
* 构造使用URL读取 * 构造使用URL读取
* *
* @param propertiesUrl 属性文件路径 * @param propertiesUrl 属性文件路径
* @param charsetName 字符集 * @param charsetName 字符集
*/ */
public Props(URL propertiesUrl, String charsetName) { public Props(URL propertiesUrl, String charsetName) {
this(propertiesUrl, CharsetUtil.charset(charsetName)); this(propertiesUrl, CharsetUtil.charset(charsetName));
@ -230,7 +235,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
* 构造使用URL读取 * 构造使用URL读取
* *
* @param propertiesUrl 属性文件路径 * @param propertiesUrl 属性文件路径
* @param charset 字符集 * @param charset 字符集
*/ */
public Props(URL propertiesUrl, Charset charset) { public Props(URL propertiesUrl, Charset charset) {
Assert.notNull(propertiesUrl, "Null properties URL !"); Assert.notNull(propertiesUrl, "Null properties URL !");
@ -494,6 +499,18 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
return (String) value; return (String) value;
} }
/**
* 转换为标准的{@link Properties}对象
*
* @return {@link Properties}对象
* @since 5.7.4
*/
public Properties toProperties() {
final Properties properties = new Properties();
properties.putAll(this);
return properties;
}
/** /**
* 将配置文件转换为Bean支持嵌套Bean<br> * 将配置文件转换为Bean支持嵌套Bean<br>
* 支持的表达式 * 支持的表达式
@ -506,7 +523,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
* ['person']['friends'][5]['name'] * ['person']['friends'][5]['name']
* </pre> * </pre>
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param beanClass Bean类 * @param beanClass Bean类
* @return Bean对象 * @return Bean对象
* @since 4.6.3 * @since 4.6.3
@ -527,9 +544,9 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
* ['person']['friends'][5]['name'] * ['person']['friends'][5]['name']
* </pre> * </pre>
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param beanClass Bean类 * @param beanClass Bean类
* @param prefix 公共前缀不指定前缀传null当指定前缀后非此前缀的属性被忽略 * @param prefix 公共前缀不指定前缀传null当指定前缀后非此前缀的属性被忽略
* @return Bean对象 * @return Bean对象
* @since 4.6.3 * @since 4.6.3
*/ */
@ -550,8 +567,8 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
* ['person']['friends'][5]['name'] * ['person']['friends'][5]['name']
* </pre> * </pre>
* *
* @param <T> Bean类型 * @param <T> Bean类型
* @param bean Bean对象 * @param bean Bean对象
* @param prefix 公共前缀不指定前缀传null当指定前缀后非此前缀的属性被忽略 * @param prefix 公共前缀不指定前缀传null当指定前缀后非此前缀的属性被忽略
* @return Bean对象 * @return Bean对象
* @since 4.6.3 * @since 4.6.3
@ -562,7 +579,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
String key; String key;
for (java.util.Map.Entry<Object, Object> entry : this.entrySet()) { for (java.util.Map.Entry<Object, Object> entry : this.entrySet()) {
key = (String) entry.getKey(); key = (String) entry.getKey();
if(false == StrUtil.startWith(key, prefix)) { if (false == StrUtil.startWith(key, prefix)) {
// 非指定开头的属性忽略掉 // 非指定开头的属性忽略掉
continue; continue;
} }
@ -580,10 +597,11 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
// ----------------------------------------------------------------------- Get end // ----------------------------------------------------------------------- Get end
// ----------------------------------------------------------------------- Set start // ----------------------------------------------------------------------- Set start
/** /**
* 设置值无给定键创建之设置后未持久化 * 设置值无给定键创建之设置后未持久化
* *
* @param key 属性键 * @param key 属性键
* @param value 属性值 * @param value 属性值
*/ */
public void setProperty(String key, Object value) { public void setProperty(String key, Object value) {
@ -611,7 +629,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
/** /**
* 存储当前设置会覆盖掉以前的设置 * 存储当前设置会覆盖掉以前的设置
* *
* @param path 相对路径 * @param path 相对路径
* @param clazz 相对的类 * @param clazz 相对的类
*/ */
public void store(String path, Class<?> clazz) { public void store(String path, Class<?> clazz) {