java.lang.Object
org.miaixz.bus.setting.magic.AbstractSetting
- All Implemented Interfaces:
Serializable,org.miaixz.bus.core.lang.getter.GroupedTypeGetter<CharSequence,,CharSequence> org.miaixz.bus.core.lang.getter.TypeGetter<CharSequence>
- Direct Known Subclasses:
Setting
public abstract class AbstractSetting
extends Object
implements org.miaixz.bus.core.lang.getter.TypeGetter<CharSequence>, org.miaixz.bus.core.lang.getter.GroupedTypeGetter<CharSequence,CharSequence>, Serializable
An abstract base class for settings, providing common functionality for accessing configuration values. It implements
getter interfaces for retrieving typed and grouped values.
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<P,T> T get(org.miaixz.bus.core.center.function.FunctionX<P, T> func) Gets a value using a lambda method reference to resolve the property name and return type.getByGroupNotEmpty(String key, String group, String defaultValue) Gets a non-empty string value from a specific group.getObject(CharSequence key, Object defaultValue) String[]getStrs(CharSequence key, String[] defaultValue) Gets a value as a string array from the default group, split by the default delimiter (',').String[]Gets a value as a string array from the default group, split by the default delimiter (',').String[]getStrsByGroup(CharSequence key, CharSequence group) Gets a value from a specific group as a string array, split by the default delimiter (',').String[]getStrsByGroup(CharSequence key, CharSequence group, CharSequence delimiter) Gets a value from a specific group as a string array, split by a custom delimiter.<T> TtoBean(CharSequence group, Class<T> beanClass) Maps the settings from a specific group to a new Java Bean object.<T> TtoBean(CharSequence group, T bean) Maps the settings from a specific group to an existing Java Bean object by calling its setters.<T> TMaps the settings from the default group to a new Java Bean object.<T> TtoBean(T bean) Maps the settings from the default group to an existing Java Bean object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.core.lang.getter.GroupedTypeGetter
getBigDecimalByGroup, getBigDecimalByGroup, getBigIntegerByGroup, getBigIntegerByGroup, getBooleanByGroup, getBooleanByGroup, getByGroup, getByGroup, getByteByGroup, getByteByGroup, getCharByGroup, getCharByGroup, getDoubleByGroup, getDoubleByGroup, getIntByGroup, getIntByGroup, getLongByGroup, getLongByGroup, getObjectByGroup, getObjectByGroup, getShortByGroup, getShortByGroup, getStringByGroup, getStringByGroupMethods inherited from interface org.miaixz.bus.core.lang.getter.TypeGetter
get, get, get, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getByte, getByte, getBytes, getBytes, getChar, getChar, getDate, getDate, getDouble, getDouble, getEnum, getEnum, getFloat, getFloat, getInt, getInt, getLocalDate, getLocalDate, getLocalDateTime, getLocalDateTime, getLocalTime, getLocalTime, getLong, getLong, getNumber, getNumber, getObject, getShort, getShort, getSqlTime, getSqlTime, getSqlTimestamp, getSqlTimestamp, getString, getString
-
Field Details
-
DEFAULT_DELIMITER
The default delimiter for array-type values.- See Also:
-
DEFAULT_GROUP
The default group name for settings.- See Also:
-
-
Constructor Details
-
AbstractSetting
protected AbstractSetting()Default constructor.
-
-
Method Details
-
getObject
- Specified by:
getObjectin interfaceorg.miaixz.bus.core.lang.getter.TypeGetter<CharSequence>
-
get
public <P,T> T get(org.miaixz.bus.core.center.function.FunctionX<P, T> func) Gets a value using a lambda method reference to resolve the property name and return type.- Type Parameters:
P- The type of the class containing the method.T- The return type of the method.- Parameters:
func- The method reference (e.g.,User::getName).- Returns:
- The value of the property corresponding to the method name.
-
getByGroupNotEmpty
Gets a non-empty string value from a specific group.- Parameters:
key- The key of the setting.group- The group name.defaultValue- The default value to return if the setting is null or empty.- Returns:
- The setting value, or the default value.
-
getStrs
Gets a value as a string array from the default group, split by the default delimiter (',').- Parameters:
key- The key of the setting.- Returns:
- The value as a string array, or null if not found.
-
getStrs
Gets a value as a string array from the default group, split by the default delimiter (',').- Parameters:
key- The key of the setting.defaultValue- The default value to return if the setting is not found.- Returns:
- The value as a string array, or the default value.
-
getStrsByGroup
Gets a value from a specific group as a string array, split by the default delimiter (','). For example, a setting likekey = a,b,cwould result in["a", "b", "c"].- Parameters:
key- The key of the setting.group- The group name.- Returns:
- The value as a string array, or null if not found.
-
getStrsByGroup
Gets a value from a specific group as a string array, split by a custom delimiter.- Parameters:
key- The key of the setting.group- The group name.delimiter- The delimiter to split the string by.- Returns:
- The value as a string array, or null if not found or blank.
-
toBean
Maps the settings from a specific group to an existing Java Bean object by calling its setters. Only basic type conversions are supported.- Type Parameters:
T- The type of the bean.- Parameters:
group- The group name whose settings will be mapped.bean- The Java Bean object to populate.- Returns:
- The populated Java Bean object.
-
toBean
Maps the settings from a specific group to a new Java Bean object.- Type Parameters:
T- The type of the bean.- Parameters:
group- The group name whose settings will be mapped.beanClass- The class of the Java Bean to create and populate.- Returns:
- The newly created and populated Java Bean object.
-
toBean
public <T> T toBean(T bean) Maps the settings from the default group to an existing Java Bean object.- Type Parameters:
T- The type of the bean.- Parameters:
bean- The Java Bean object to populate.- Returns:
- The populated Java Bean object.
-
toBean
Maps the settings from the default group to a new Java Bean object.- Type Parameters:
T- The type of the bean.- Parameters:
beanClass- The class of the Java Bean to create and populate.- Returns:
- The newly created and populated Java Bean object.
-