Class SystemPropertySupplier<T>
- java.lang.Object
-
- org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier<T>
-
- All Implemented Interfaces:
java.util.function.Supplier<T>
public class SystemPropertySupplier<T> extends java.lang.Object implements java.util.function.Supplier<T>
Utility class for consistent handling of system properties.It provides for:
- TRACE level logging of getting the system property
- ERROR level logging when value does not parse or is invalid (where
validity can be checked by a
Predicate
) - (default) INFO level logging when value differs from default (log level and message format can be overridden)
The supported types are:
Boolean
,Integer
,Long
,String
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <U> SystemPropertySupplier<U>
create(@NotNull java.lang.String propName, U defaultValue)
Create it for a given property name and default value.SystemPropertySupplier<T>
formatSetMessage(@NotNull java.util.function.BiFunction<java.lang.String,T,java.lang.String> setMessageFormatter)
Specify a formatter for the "success" log message to be used when the returned property value differs from the default.T
get()
Obtains the value of a system property, optionally generating diagnostics.SystemPropertySupplier<T>
loggingTo(@NotNull Logger log)
Specify theLogger
to log to (defaults to this classes logger otherwise).SystemPropertySupplier<T>
logSuccessAs(Level successLogLevel)
SpecifyLevel
to use for "success" message.protected SystemPropertySupplier<T>
usingSystemPropertyReader(@NotNull java.util.function.Function<java.lang.String,java.lang.String> sysPropReader)
For unit testing: specify a function to read system properties (overriding default ofSystem.getProperty(String
).SystemPropertySupplier<T>
validateWith(@NotNull java.util.function.Predicate<T> validator)
Specify a validation expression.
-
-
-
Method Detail
-
create
public static <U> SystemPropertySupplier<U> create(@NotNull @NotNull java.lang.String propName, @NotNull U defaultValue) throws java.lang.IllegalArgumentException
Create it for a given property name and default value.- Throws:
java.lang.IllegalArgumentException
-
loggingTo
public SystemPropertySupplier<T> loggingTo(@NotNull @NotNull Logger log)
Specify theLogger
to log to (defaults to this classes logger otherwise).
-
validateWith
public SystemPropertySupplier<T> validateWith(@NotNull @NotNull java.util.function.Predicate<T> validator)
Specify a validation expression.
-
formatSetMessage
public SystemPropertySupplier<T> formatSetMessage(@NotNull @NotNull java.util.function.BiFunction<java.lang.String,T,java.lang.String> setMessageFormatter)
Specify a formatter for the "success" log message to be used when the returned property value differs from the default.
-
logSuccessAs
public SystemPropertySupplier<T> logSuccessAs(Level successLogLevel)
SpecifyLevel
to use for "success" message.
-
usingSystemPropertyReader
protected SystemPropertySupplier<T> usingSystemPropertyReader(@NotNull @NotNull java.util.function.Function<java.lang.String,java.lang.String> sysPropReader)
For unit testing: specify a function to read system properties (overriding default ofSystem.getProperty(String
).
-
-