Module bus.setting

Class AbstractSetting

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
    Modifier and Type
    Field
    Description
    static final String
    The default delimiter for array-type values.
    static final String
    The default group name for settings.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    <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)
     
    getStrs(CharSequence key, String[] defaultValue)
    Gets a value as a string array from the default group, split by the default delimiter (',').
    Gets a value as a string array from the default group, split by the default delimiter (',').
    Gets a value from a specific group as a string array, split by the default delimiter (',').
    Gets a value from a specific group as a string array, split by a custom delimiter.
    <T> T
    toBean(CharSequence group, Class<T> beanClass)
    Maps the settings from a specific group to a new Java Bean object.
    <T> T
    toBean(CharSequence group, T bean)
    Maps the settings from a specific group to an existing Java Bean object by calling its setters.
    <T> T
    toBean(Class<T> beanClass)
    Maps the settings from the default group to a new Java Bean object.
    <T> T
    toBean(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, wait

    Methods 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, getStringByGroup

    Methods 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

  • Constructor Details

    • AbstractSetting

      protected AbstractSetting()
      Default constructor.
  • Method Details

    • getObject

      public Object getObject(CharSequence key, Object defaultValue)
      Specified by:
      getObject in interface org.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

      public String getByGroupNotEmpty(String key, String group, String defaultValue)
      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

      public String[] getStrs(String key)
      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

      public String[] getStrs(CharSequence key, String[] defaultValue)
      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

      public String[] getStrsByGroup(CharSequence key, CharSequence group)
      Gets a value from a specific group as a string array, split by the default delimiter (','). For example, a setting like key = a,b,c would 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

      public String[] getStrsByGroup(CharSequence key, CharSequence group, CharSequence delimiter)
      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

      public <T> T toBean(CharSequence group, T bean)
      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

      public <T> T toBean(CharSequence group, Class<T> beanClass)
      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

      public <T> T toBean(Class<T> beanClass)
      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.