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 @Nullable BooleangetBoolean(Class<?> type, String name, Boolean defValue) Retrieves abooleansettingstatic @Nullable CharsetgetCharset(Class<?> type, String name, @Nullable Charset defValue) Retrieves aCharsetsettingstatic @Nullable DoubleRetrieves adoublesettingstatic @Nullable DurationgetDuration(Class<?> type, String name, @Nullable Duration defValue) Retrieves aDurationsettingstatic <E extends Enum<E>>
ERetrieves aEnumsettingstatic @Nullable InetSocketAddressgetInetSocketAddress(Class<?> type, String name, @Nullable InetSocketAddress defValue) Retrieves aInetSocketAddresssettingstatic @Nullable IntegerRetrieves anintsettingstatic @Nullable LocaleRetrieves aLocalesettingstatic @Nullable LongRetrieves alongsettingstatic @Nullable MemSizegetMemSize(Class<?> type, String name, @Nullable MemSize defValue) Retrieves aMemSizesettingstatic @Nullable StringRetrieves aStringsettingstatic booleanstatic 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
@Contract("_, _, _, !null -> !null") @Nullable public static <T> T get(Function<String, T> parser, Class<?> type, String name, @Nullable T defValue) 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
@Contract("_, _, !null -> !null") @Nullable public static @Nullable String getString(Class<?> type, String name, @Nullable @Nullable String defValue) Retrieves aStringsetting- See Also:
-
getInt
@Contract("_, _, !null -> !null") @Nullable public static @Nullable Integer getInt(Class<?> type, String name, Integer defValue) Retrieves anintsetting- See Also:
-
getLong
@Contract("_, _, !null -> !null") @Nullable public static @Nullable Long getLong(Class<?> type, String name, Long defValue) Retrieves alongsetting- See Also:
-
getBoolean
@Contract("_, _, !null -> !null") @Nullable public static @Nullable Boolean getBoolean(Class<?> type, String name, Boolean defValue) Retrieves abooleansetting- See Also:
-
parseBoolean
-
getDouble
@Contract("_, _, !null -> !null") @Nullable public static @Nullable Double getDouble(Class<?> type, String name, Double defValue) Retrieves adoublesetting- See Also:
-
getDuration
@Contract("_, _, !null -> !null") @Nullable public static @Nullable Duration getDuration(Class<?> type, String name, @Nullable @Nullable Duration defValue) Retrieves aDurationsetting -
getMemSize
@Contract("_, _, !null -> !null") @Nullable public static @Nullable MemSize getMemSize(Class<?> type, String name, @Nullable @Nullable MemSize defValue) Retrieves aMemSizesetting- See Also:
-
getInetSocketAddress
@Contract("_, _, !null -> !null") @Nullable public static @Nullable InetSocketAddress getInetSocketAddress(Class<?> type, String name, @Nullable @Nullable InetSocketAddress defValue) Retrieves aInetSocketAddresssetting- See Also:
-
getCharset
@Contract("_, _, !null -> !null") @Nullable public static @Nullable Charset getCharset(Class<?> type, String name, @Nullable @Nullable Charset defValue) Retrieves aCharsetsetting -
getLocale
@Contract("_, _, !null -> !null") @Nullable public static @Nullable Locale getLocale(Class<?> type, String name, @Nullable @Nullable Locale defValue) Retrieves aLocalesetting -
getEnum
@Contract("_, _, _, !null -> !null") @Nullable public static <E extends Enum<E>> E getEnum(Class<?> type, String name, Class<E> enumClass, @Nullable E defValue) Retrieves aEnumsetting
-