Class ApplicationSettings
Each application setting provides a name of a class, a name of a setting, and a default value to be used in case a setting is not explicitly set
A setting is searched by using both fully qualified class name and a class's simple name
By default, system properties are searched to find whether a setting is explicitly set. However, alternative properties may be used as a source. Individual settings may also be set programmatically.
After any setting has been looked up it is not allowed to change properties source or update individual settings. Hence, all configuration should preferably happen in a static initialization block before constants have been initialized.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TRetrieves a setting.static booleangetBoolean(Class<?> type, String name, boolean defValue) Retrieves abooleansettingstatic CharsetgetCharset(Class<?> type, String name, Charset defValue) Retrieves aCharsetsettingstatic doubleRetrieves adoublesettingstatic DurationgetDuration(Class<?> type, String name, Duration defValue) Retrieves aDurationsettingstatic <E extends Enum<E>>
ERetrieves aEnumsettingstatic InetSocketAddressgetInetSocketAddress(Class<?> type, String name, InetSocketAddress defValue) Retrieves aInetSocketAddresssettingstatic intRetrieves anintsettingstatic LocaleRetrieves aLocalesettingstatic longRetrieves alongsettingstatic MemSizegetMemSize(Class<?> type, String name, MemSize defValue) Retrieves aMemSizesettingstatic StringRetrieves aStringsettingstatic voidSets a custom settingstatic voiduseProperties(Properties properties) Uses alternative properties to look up settings
-
Constructor Details
-
ApplicationSettings
public ApplicationSettings()
-
-
Method Details
-
useProperties
Uses alternative properties to look up settingsThis method should not be called after any setting look up has been made
- Parameters:
properties- alternative properties
-
set
Sets a custom settingThis setting will override settings from properties
This method should not be called after any setting look up has been made
- Parameters:
type- a class referenced by a settingname- a name of a settingvalue- a value of a setting
-
get
Retrieves a setting. This is a base method that can be used to parse a setting string into an arbitrary value.A setting is searched by using both fully qualified class name and a class's simple name
- Parameters:
parser- function that transforms a setting string into a valuetype- a class referenced by a settingname- a name of a settingdefValue- default value that will be used if a setting property is not found
-
getString
Retrieves aStringsetting- See Also:
-
getInt
Retrieves anintsetting- See Also:
-
getLong
Retrieves alongsetting- See Also:
-
getBoolean
Retrieves abooleansetting- See Also:
-
getDouble
Retrieves adoublesetting- See Also:
-
getDuration
Retrieves aDurationsetting -
getMemSize
Retrieves aMemSizesetting- See Also:
-
getInetSocketAddress
public static InetSocketAddress getInetSocketAddress(Class<?> type, String name, InetSocketAddress defValue) Retrieves aInetSocketAddresssetting- See Also:
-
getCharset
Retrieves aCharsetsetting -
getLocale
Retrieves aLocalesetting -
getEnum
public static <E extends Enum<E>> E getEnum(Class<?> type, String name, Class<E> enumClass, E defValue) Retrieves aEnumsetting
-