public class Setting extends AbsSetting implements Map<String,String>
1、支持变量,默认变量命名为 ${变量名},变量只能识别读入行的变量,例如第6行的变量在第三行无法读取
2、支持分组,分组为中括号括起来的内容,中括号以下的行都为此分组的内容,无分组相当于空字符分组,若某个key是name,加上分组后的键相当于group.name
3、注释以#开头,但是空行和不带“=”的行也会被跳过,但是建议加#
4、store方法不会保存注释内容,慎重使用
| Modifier and Type | Field and Description |
|---|---|
protected Charset |
charset
本设置对象的字符集
|
static Charset |
DEFAULT_CHARSET
默认字符集
|
static String |
EXT_NAME
默认配置文件扩展名
|
protected boolean |
isUseVariable
是否使用变量
|
protected Resource |
resource
设定文件的资源
|
DEFAULT_DELIMITER, DEFAULT_GROUP| Constructor and Description |
|---|
Setting()
空构造
|
Setting(File configFile,
Charset charset,
boolean isUseVariable)
构造
|
Setting(Resource resource,
Charset charset,
boolean isUseVariable)
构造
|
Setting(String path)
构造
|
Setting(String path,
boolean isUseVariable)
构造
|
Setting(String path,
Charset charset,
boolean isUseVariable)
构造,使用相对于Class文件根目录的相对路径
|
Setting(String path,
Class<?> clazz,
Charset charset,
boolean isUseVariable)
构造,相对于classes读取文件
|
Setting(URL url,
Charset charset,
boolean isUseVariable)
构造
|
| Modifier and Type | Method and Description |
|---|---|
Setting |
addSetting(Setting setting)
添加一个Stting到主配置中
|
void |
autoLoad(boolean autoReload)
在配置文件变更时自动加载
|
void |
autoLoad(boolean autoReload,
Consumer<Boolean> callback)
在配置文件变更时自动加载
|
void |
clear()
清空默认分组(空分组)中的所有键值对
|
Setting |
clear(String group)
清除指定分组下的所有键值对
|
boolean |
containsKey(Object key)
默认分组(空分组)中是否包含指定key对应的值
|
boolean |
containsKey(String group,
String key)
指定分组中是否包含指定key
|
boolean |
containsValue(Object value)
默认分组(空分组)中是否包含指定值
|
boolean |
containsValue(String group,
String value)
指定分组中是否包含指定值
|
static Setting |
create()
构建一个空的Setting,用于手动加入参数
|
Set<Map.Entry<String,String>> |
entrySet()
获取默认分组(空分组)中的所有键值对列表
|
Set<Map.Entry<String,String>> |
entrySet(String group)
指定分组下所有键值对
|
boolean |
equals(Object obj) |
String |
get(Object key)
获取默认分组(空分组)中指定key对应的值
|
String |
get(String group,
String key)
获取分组对应的值,如果分组不存在或者值不存在则返回null
|
Object |
getAndRemove(String... keys)
获取并删除键值对,当指定键对应值非空时,返回并删除这个值,后边的键对应的值不再查找
|
String |
getAndRemoveStr(String... keys)
获取并删除键值对,当指定键对应值非空时,返回并删除这个值,后边的键对应的值不再查找
|
String |
getByGroup(String key,
String group)
获得指定分组的键对应值
|
GroupedMap |
getGroupedMap()
获取GroupedMap
|
List<String> |
getGroups()
获取所有分组
|
Map<String,String> |
getMap(String group)
获得指定分组的所有键值对,此方法获取的是原始键值对,获取的键值对可以被修改
|
Properties |
getProperties(String group)
获取group分组下所有配置键值对,组成新的
Properties |
Props |
getProps(String group)
获取group分组下所有配置键值对,组成新的
Props |
Setting |
getSetting(String group)
获取group分组下所有配置键值对,组成新的Setting
|
String |
getSettingPath()
获得设定文件的路径
|
URL |
getSettingUrl()
获得设定文件的URL
|
int |
hashCode() |
boolean |
init(Resource resource,
Charset charset,
boolean isUseVariable)
初始化设定文件
|
boolean |
isEmpty() |
boolean |
isEmpty(String group)
某个分组对应的键值对是否为空
|
Set<String> |
keySet()
获取默认分组(空分组)中的所有键列表
|
Set<String> |
keySet(String group)
指定分组所有键的Set
|
boolean |
load()
重新加载配置文件
|
String |
put(String key,
String value)
将指定键值对加入到默认分组(空分组)中
|
void |
putAll(Map<? extends String,? extends String> m)
将键值对Map加入默认分组(空分组)中
|
Setting |
putAll(String group,
Map<? extends String,? extends String> m)
加入多个键值对到某个分组下
|
String |
putByGroup(String key,
String group,
String value)
将键值对加入到对应分组中
|
String |
remove(Object key)
移除默认分组(空分组)中指定值
|
String |
remove(String group,
Object key)
从指定分组中删除指定值
|
Setting |
set(String key,
String value)
设置值
|
Setting |
setByGroup(String key,
String group,
String value)
将键值对加入到对应分组中
此方法用于与getXXX统一参数顺序 |
Setting |
setCharset(Charset charset)
自定义字符编码
|
Setting |
setVarRegex(String regex)
设置变量的正则
正则只能有一个group表示变量本身,剩余为字符 例如 \$\{(name)\}表示${name}变量名为name的一个变量表示 |
int |
size()
键值总数
|
void |
store()
持久化当前设置,会覆盖掉之前的设置
持久化不会保留之前的分组,注意如果配置文件在jar内部或者在exe中,此方法会报错。 |
void |
store(File file)
持久化当前设置,会覆盖掉之前的设置
持久化不会保留之前的分组 |
void |
store(String absolutePath)
持久化当前设置,会覆盖掉之前的设置
持久化不会保留之前的分组 |
Properties |
toProperties()
转换为Properties对象,原分组变为前缀
|
String |
toString() |
Collection<String> |
values()
获取默认分组(空分组)中的所有值列表
|
Collection<String> |
values(String group)
指定分组下所有值
|
getBool, getBool, getByGroupWithLog, getChar, getDouble, getDouble, getInt, getInt, getLong, getLong, getStr, getStr, getStrings, getStrings, getStrings, getStringsWithDefault, getStrNotEmpty, getWithLog, toBean, toBean, toBean, toBeanclone, finalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllgetBigDecimal, getBigInteger, getBool, getByte, getChar, getDate, getDouble, getEnum, getFloat, getInt, getLong, getObj, getShortgetBigDecimal, getBigInteger, getBool, getByte, getChar, getDate, getDouble, getEnum, getFloat, getInt, getLong, getObj, getShort, getStrpublic static final Charset DEFAULT_CHARSET
public static final String EXT_NAME
protected Charset charset
protected boolean isUseVariable
protected Resource resource
public Setting()
public Setting(String path)
path - 相对路径或绝对路径public Setting(String path, boolean isUseVariable)
path - 相对路径或绝对路径isUseVariable - 是否使用变量public Setting(String path, Charset charset, boolean isUseVariable)
path - 相对路径或绝对路径charset - 字符集isUseVariable - 是否使用变量public Setting(File configFile, Charset charset, boolean isUseVariable)
configFile - 配置文件对象charset - 字符集isUseVariable - 是否使用变量public Setting(String path, Class<?> clazz, Charset charset, boolean isUseVariable)
path - 相对ClassPath路径或绝对路径clazz - 基准类charset - 字符集isUseVariable - 是否使用变量public Setting(URL url, Charset charset, boolean isUseVariable)
url - 设定文件的URLcharset - 字符集isUseVariable - 是否使用变量public static Setting create()
public boolean init(Resource resource, Charset charset, boolean isUseVariable)
resource - Resourcecharset - 字符集isUseVariable - 是否使用变量public boolean load()
public void autoLoad(boolean autoReload)
autoReload - 是否自动加载public void autoLoad(boolean autoReload,
Consumer<Boolean> callback)
callback - 加载完成回调autoReload - 是否自动加载public URL getSettingUrl()
public String getSettingPath()
public String getByGroup(String key, String group)
AbsSettinggetByGroup in class AbsSettingkey - 键group - 分组public Object getAndRemove(String... keys)
keys - 键列表,常用于别名public String getAndRemoveStr(String... keys)
keys - 键列表,常用于别名public Map<String,String> getMap(String group)
group - 分组public Setting getSetting(String group)
group - 分组public Properties getProperties(String group)
Propertiesgroup - 分组public Props getProps(String group)
Propsgroup - 分组public void store()
public void store(String absolutePath)
absolutePath - 设置文件的绝对路径public void store(File file)
file - 设置文件public Properties toProperties()
public GroupedMap getGroupedMap()
public Setting setVarRegex(String regex)
regex - 正则public Setting setCharset(Charset charset)
charset - 字符编码public boolean isEmpty(String group)
group - 分组public boolean containsKey(String group, String key)
group - 分组key - 键public boolean containsValue(String group, String value)
group - 分组value - 值public String get(String group, String key)
group - 分组key - 键public String putByGroup(String key, String group, String value)
key - 键group - 分组value - 值public String remove(String group, Object key)
group - 分组key - 键public Setting putAll(String group, Map<? extends String,? extends String> m)
group - 分组m - 键值对public Setting addSetting(Setting setting)
setting - Setting配置public Collection<String> values(String group)
group - 分组public Set<Map.Entry<String,String>> entrySet(String group)
group - 分组public Setting set(String key, String value)
key - 键value - 值public Setting setByGroup(String key, String group, String value)
key - 键group - 分组value - 值public boolean containsKey(Object key)
containsKey in interface Map<String,String>key - 键public boolean containsValue(Object value)
containsValue in interface Map<String,String>value - 值public Collection<String> values()
public int hashCode()
public boolean equals(Object obj)
Copyright © 2025. All rights reserved.