mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package cn.hutool.setting;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.bean.copier.ValueProvider;
|
||||
@@ -14,6 +11,9 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.log.Log;
|
||||
import cn.hutool.log.LogFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Setting抽象类
|
||||
*
|
||||
@@ -156,7 +156,7 @@ public abstract class AbsSetting implements OptNullBasicTypeFromStringGetter<Str
|
||||
if (StrUtil.isBlank(value)) {
|
||||
return null;
|
||||
}
|
||||
return StrUtil.split(value, delimiter);
|
||||
return StrUtil.splitToArray(value, delimiter);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------- Get int
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package cn.hutool.setting.dialect;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.getter.BasicTypeGetter;
|
||||
import cn.hutool.core.getter.OptBasicTypeGetter;
|
||||
@@ -17,6 +16,7 @@ import cn.hutool.core.io.watch.SimpleWatcher;
|
||||
import cn.hutool.core.io.watch.WatchMonitor;
|
||||
import cn.hutool.core.io.watch.WatchUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -39,7 +39,7 @@ import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Properties文件读取封装类
|
||||
*
|
||||
*
|
||||
* @author loolly
|
||||
*/
|
||||
public final class Props extends Properties implements BasicTypeGetter<String>, OptBasicTypeGetter<String> {
|
||||
@@ -70,7 +70,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 获得Classpath下的Properties文件
|
||||
*
|
||||
*
|
||||
* @param resource 资源(相对Classpath的路径)
|
||||
* @return Props
|
||||
*/
|
||||
@@ -80,7 +80,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 获得Classpath下的Properties文件
|
||||
*
|
||||
*
|
||||
* @param resource 资源(相对Classpath的路径)
|
||||
* @param charsetName 字符集
|
||||
* @return Properties
|
||||
@@ -91,7 +91,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 获得Classpath下的Properties文件
|
||||
*
|
||||
*
|
||||
* @param resource 资源(相对Classpath的路径)
|
||||
* @param charset 字符集
|
||||
* @return Properties
|
||||
@@ -109,7 +109,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,使用相对于Class文件根目录的相对路径
|
||||
*
|
||||
*
|
||||
* @param path 配置文件路径,相对于ClassPath,或者使用绝对路径
|
||||
*/
|
||||
public Props(String path) {
|
||||
@@ -118,7 +118,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,使用相对于Class文件根目录的相对路径
|
||||
*
|
||||
*
|
||||
* @param path 相对或绝对路径
|
||||
* @param charsetName 字符集
|
||||
*/
|
||||
@@ -128,7 +128,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,使用相对于Class文件根目录的相对路径
|
||||
*
|
||||
*
|
||||
* @param path 相对或绝对路径
|
||||
* @param charset 字符集
|
||||
*/
|
||||
@@ -142,7 +142,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param propertiesFile 配置文件对象
|
||||
*/
|
||||
public Props(File propertiesFile) {
|
||||
@@ -151,7 +151,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param propertiesFile 配置文件对象
|
||||
* @param charsetName 字符集
|
||||
*/
|
||||
@@ -161,7 +161,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param propertiesFile 配置文件对象
|
||||
* @param charset 字符集
|
||||
*/
|
||||
@@ -173,7 +173,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,相对于classes读取文件
|
||||
*
|
||||
*
|
||||
* @param path 相对路径
|
||||
* @param clazz 基准类
|
||||
*/
|
||||
@@ -183,7 +183,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,相对于classes读取文件
|
||||
*
|
||||
*
|
||||
* @param path 相对路径
|
||||
* @param clazz 基准类
|
||||
* @param charsetName 字符集
|
||||
@@ -194,7 +194,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,相对于classes读取文件
|
||||
*
|
||||
*
|
||||
* @param path 相对路径
|
||||
* @param clazz 基准类
|
||||
* @param charset 字符集
|
||||
@@ -209,7 +209,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,使用URL读取
|
||||
*
|
||||
*
|
||||
* @param propertiesUrl 属性文件路径
|
||||
*/
|
||||
public Props(URL propertiesUrl) {
|
||||
@@ -218,7 +218,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,使用URL读取
|
||||
*
|
||||
*
|
||||
* @param propertiesUrl 属性文件路径
|
||||
* @param charsetName 字符集
|
||||
*/
|
||||
@@ -228,7 +228,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,使用URL读取
|
||||
*
|
||||
*
|
||||
* @param propertiesUrl 属性文件路径
|
||||
* @param charset 字符集
|
||||
*/
|
||||
@@ -242,11 +242,11 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 构造,使用URL读取
|
||||
*
|
||||
*
|
||||
* @param properties 属性文件路径
|
||||
*/
|
||||
public Props(Properties properties) {
|
||||
if (CollectionUtil.isNotEmpty(properties)) {
|
||||
if (MapUtil.isNotEmpty(properties)) {
|
||||
this.putAll(properties);
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 初始化配置文件
|
||||
*
|
||||
*
|
||||
* @param resource {@link Resource}
|
||||
*/
|
||||
public void load(Resource resource) {
|
||||
@@ -290,7 +290,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 在配置文件变更时自动加载
|
||||
*
|
||||
*
|
||||
* @param autoReload 是否自动加载
|
||||
*/
|
||||
public void autoLoad(boolean autoReload) {
|
||||
@@ -478,7 +478,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 获取并删除键值对,当指定键对应值非空时,返回并删除这个值,后边的键对应的值不再查找
|
||||
*
|
||||
*
|
||||
* @param keys 键列表,常用于别名
|
||||
* @return 字符串值
|
||||
* @since 4.1.21
|
||||
@@ -493,11 +493,11 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
}
|
||||
return (String) value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将配置文件转换为Bean,支持嵌套Bean<br>
|
||||
* 支持的表达式:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* persion
|
||||
* persion.name
|
||||
@@ -518,7 +518,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
/**
|
||||
* 将配置文件转换为Bean,支持嵌套Bean<br>
|
||||
* 支持的表达式:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* persion
|
||||
* persion.name
|
||||
@@ -537,11 +537,11 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
final T bean = ReflectUtil.newInstanceIfPossible(beanClass);
|
||||
return fillBean(bean, prefix);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将配置文件转换为Bean,支持嵌套Bean<br>
|
||||
* 支持的表达式:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* persion
|
||||
* persion.name
|
||||
@@ -582,7 +582,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
// ----------------------------------------------------------------------- Set start
|
||||
/**
|
||||
* 设置值,无给定键创建之。设置后未持久化
|
||||
*
|
||||
*
|
||||
* @param key 属性键
|
||||
* @param value 属性值
|
||||
*/
|
||||
@@ -592,7 +592,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 持久化当前设置,会覆盖掉之前的设置
|
||||
*
|
||||
*
|
||||
* @param absolutePath 设置文件的绝对路径
|
||||
* @throws IORuntimeException IO异常,可能为文件未找到
|
||||
*/
|
||||
@@ -610,7 +610,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
|
||||
/**
|
||||
* 存储当前设置,会覆盖掉以前的设置
|
||||
*
|
||||
*
|
||||
* @param path 相对路径
|
||||
* @param clazz 相对的类
|
||||
*/
|
||||
|
@@ -47,9 +47,9 @@ public class SettingTest {
|
||||
public void settingTestForCustom() {
|
||||
Setting setting = new Setting();
|
||||
|
||||
setting.put("group1", "user", "root");
|
||||
setting.put("group2", "user", "root2");
|
||||
setting.put("group3", "user", "root3");
|
||||
setting.setByGroup("user", "group1", "root");
|
||||
setting.setByGroup("user", "group2", "root2");
|
||||
setting.setByGroup("user", "group3", "root3");
|
||||
setting.set("user", "root4");
|
||||
|
||||
Assert.assertEquals("root", setting.getByGroup("user", "group1"));
|
||||
|
Reference in New Issue
Block a user