S
- type of subject@Beta
public abstract class Config<S>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Config.FieldPresence
Indicator of whether a configuration JSON field is required.
|
Modifier and Type | Field and Description |
---|---|
protected com.fasterxml.jackson.databind.node.ArrayNode |
array |
protected ConfigApplyDelegate |
delegate |
protected java.lang.String |
key |
protected com.fasterxml.jackson.databind.ObjectMapper |
mapper |
protected com.fasterxml.jackson.databind.JsonNode |
node |
protected com.fasterxml.jackson.databind.node.ObjectNode |
object |
protected S |
subject |
Constructor and Description |
---|
Config() |
Modifier and Type | Method and Description |
---|---|
void |
apply()
Applies any configuration changes made via this configuration.
|
protected Config<S> |
clear(java.lang.String name)
Clears the specified property.
|
protected boolean |
get(java.lang.String name,
boolean defaultValue)
Gets the specified property as a boolean.
|
protected double |
get(java.lang.String name,
double defaultValue)
Gets the specified property as a double.
|
protected <E extends java.lang.Enum<E>> |
get(java.lang.String name,
E defaultValue,
java.lang.Class<E> enumClass)
Gets the specified property as an enum.
|
protected int |
get(java.lang.String name,
int defaultValue)
Gets the specified property as an integer.
|
protected long |
get(java.lang.String name,
long defaultValue)
Gets the specified property as a long.
|
protected java.lang.String |
get(java.lang.String name,
java.lang.String defaultValue)
Gets the specified property as a string.
|
protected <T> java.util.List<T> |
getList(java.lang.String name,
java.util.function.Function<java.lang.String,T> function)
Gets the specified array property as a list of items.
|
protected <T> java.util.List<T> |
getList(java.lang.String name,
java.util.function.Function<java.lang.String,T> function,
java.util.List<T> defaultValue)
Gets the specified array property as a list of items.
|
protected boolean |
hasField(com.fasterxml.jackson.databind.node.ObjectNode node,
java.lang.String name)
Returns true if the given node contains a field with the given name.
|
protected boolean |
hasField(java.lang.String name)
Returns true if this config contains a field with the given name.
|
protected boolean |
hasFields(com.fasterxml.jackson.databind.node.ObjectNode node,
java.lang.String... mandatoryFields)
Indicates whether all specified fields are present in a particular
JSON object.
|
protected boolean |
hasFields(java.lang.String... mandatoryFields)
Indicates whether all specified fields are present in the backing JSON.
|
protected boolean |
hasOnlyFields(com.fasterxml.jackson.databind.node.ObjectNode node,
java.lang.String... allowedFields)
Indicates whether only the specified fields are present in a particular
JSON object.
|
protected boolean |
hasOnlyFields(java.lang.String... allowedFields)
Indicates whether only the specified fields are present in the backing JSON.
|
void |
init(S subject,
java.lang.String key,
com.fasterxml.jackson.databind.JsonNode node,
com.fasterxml.jackson.databind.ObjectMapper mapper,
ConfigApplyDelegate delegate)
Initializes the configuration behaviour with necessary context.
|
protected boolean |
isBoolean(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field of a particular node holds a valid
boolean value.
|
protected boolean |
isBoolean(java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field holds a valid boolean value.
|
protected boolean |
isConnectPoint(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field of a particular node holds a valid
connect point string.
|
protected boolean |
isConnectPoint(java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field holds a valid connect point string.
|
protected boolean |
isDecimal(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence,
double... minMax)
Indicates whether the specified field of a particular node holds a valid
decimal number.
|
protected boolean |
isDecimal(java.lang.String field,
Config.FieldPresence presence,
double... minMax)
Indicates whether the specified field holds a valid decimal number.
|
protected boolean |
isIntegralNumber(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence,
long... minMax)
Indicates whether the specified field of a particular node holds a valid
integer.
|
protected boolean |
isIntegralNumber(java.lang.String field,
Config.FieldPresence presence,
long... minMax)
Indicates whether the specified field holds a valid integer.
|
protected boolean |
isIpAddress(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field of a particular node holds a valid
IP address.
|
protected boolean |
isIpAddress(java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field holds a valid IP address.
|
protected boolean |
isIpPrefix(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field of a particular node holds a valid
IP prefix.
|
protected boolean |
isIpPrefix(java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field holds a valid IP prefix.
|
protected boolean |
isMacAddress(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field of a particular node holds a valid
MAC address.
|
protected boolean |
isMacAddress(java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field holds a valid MAC address.
|
protected boolean |
isNumber(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence,
long... minMax)
Indicates whether the specified field of a particular node holds a
valid number.
|
protected boolean |
isNumber(java.lang.String field,
Config.FieldPresence presence,
long... minMax)
Indicates whether the specified field holds a valid number.
|
protected boolean |
isString(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence,
java.lang.String... pattern)
Indicates whether the specified field on a particular node holds a valid
string value.
|
protected boolean |
isString(java.lang.String field,
Config.FieldPresence presence,
java.lang.String... pattern)
Indicates whether the specified field holds a valid string value.
|
protected boolean |
isTpPort(com.fasterxml.jackson.databind.node.ObjectNode objectNode,
java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field of a particular node holds a valid
transport layer port.
|
protected boolean |
isTpPort(java.lang.String field,
Config.FieldPresence presence)
Indicates whether the specified field holds a valid transport layer port.
|
boolean |
isValid()
Indicates whether or not the backing JSON node contains valid data.
|
protected boolean |
isValidLength(java.lang.String field,
int maxLength)
Indicates whether the specified field is of a valid length.
|
java.lang.String |
key()
Returns the configuration key.
|
com.fasterxml.jackson.databind.JsonNode |
node()
Returns the JSON node that contains the configuration data.
|
protected <T> Config<S> |
setList(java.lang.String name,
java.util.function.Function<? super T,java.lang.String> function,
java.util.List<T> value)
Sets the specified property as an array of items in a given collection
transformed into a String with supplied
function . |
protected Config<S> |
setOrClear(java.lang.String name,
java.lang.Boolean value)
Sets the specified property as a boolean or clears it if null value given.
|
protected <T> Config<S> |
setOrClear(java.lang.String name,
java.util.Collection<T> collection)
Sets the specified property as an array of items in a given collection or
clears it if null is given.
|
protected Config<S> |
setOrClear(java.lang.String name,
java.lang.Double value)
Sets the specified property as a double or clears it if null value given.
|
protected <E extends java.lang.Enum> |
setOrClear(java.lang.String name,
E value)
Sets the specified property as a double or clears it if null value given.
|
protected Config<S> |
setOrClear(java.lang.String name,
java.lang.Integer value)
Sets the specified property as an integer or clears it if null value given.
|
protected Config<S> |
setOrClear(java.lang.String name,
java.lang.Long value)
Sets the specified property as a long or clears it if null value given.
|
protected Config<S> |
setOrClear(java.lang.String name,
java.lang.String value)
Sets the specified property as a string or clears it if null value given.
|
S |
subject()
Returns the specific subject to which this configuration pertains.
|
java.lang.String |
toString() |
protected S subject
protected java.lang.String key
protected com.fasterxml.jackson.databind.JsonNode node
protected com.fasterxml.jackson.databind.node.ObjectNode object
protected com.fasterxml.jackson.databind.node.ArrayNode array
protected com.fasterxml.jackson.databind.ObjectMapper mapper
protected ConfigApplyDelegate delegate
public final void init(S subject, java.lang.String key, com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.ObjectMapper mapper, ConfigApplyDelegate delegate)
subject
- configuration subjectkey
- configuration keynode
- JSON node where configuration data is storedmapper
- JSON object mapperdelegate
- delegate context, or null for detached configs.public boolean isValid()
Default implementation returns true. Subclasses are expected to override this with their own validation. Implementations are free to throw a RuntimeException if data is invalid.
java.lang.RuntimeException
- if configuration is invalid or completely foobarpublic S subject()
public java.lang.String key()
public com.fasterxml.jackson.databind.JsonNode node()
public void apply()
Not effective for detached configs.
protected java.lang.String get(java.lang.String name, java.lang.String defaultValue)
name
- property namedefaultValue
- default value if property not setprotected Config<S> setOrClear(java.lang.String name, java.lang.String value)
name
- property namevalue
- new value or null to clear the propertyprotected boolean get(java.lang.String name, boolean defaultValue)
name
- property namedefaultValue
- default value if property not setprotected Config<S> clear(java.lang.String name)
name
- property nameprotected Config<S> setOrClear(java.lang.String name, java.lang.Boolean value)
name
- property namevalue
- new value or null to clear the propertyprotected int get(java.lang.String name, int defaultValue)
name
- property namedefaultValue
- default value if property not setprotected Config<S> setOrClear(java.lang.String name, java.lang.Integer value)
name
- property namevalue
- new value or null to clear the propertyprotected long get(java.lang.String name, long defaultValue)
name
- property namedefaultValue
- default value if property not setprotected Config<S> setOrClear(java.lang.String name, java.lang.Long value)
name
- property namevalue
- new value or null to clear the propertyprotected double get(java.lang.String name, double defaultValue)
name
- property namedefaultValue
- default value if property not setprotected Config<S> setOrClear(java.lang.String name, java.lang.Double value)
name
- property namevalue
- new value or null to clear the propertyprotected <E extends java.lang.Enum<E>> E get(java.lang.String name, E defaultValue, java.lang.Class<E> enumClass)
E
- type of enumname
- property namedefaultValue
- default value if property not setenumClass
- the enum classprotected <E extends java.lang.Enum> Config<S> setOrClear(java.lang.String name, E value)
E
- type of enumname
- property namevalue
- new value or null to clear the propertyprotected <T> java.util.List<T> getList(java.lang.String name, java.util.function.Function<java.lang.String,T> function)
T
- type of itemname
- property namefunction
- mapper from string to itemprotected <T> java.util.List<T> getList(java.lang.String name, java.util.function.Function<java.lang.String,T> function, java.util.List<T> defaultValue)
T
- type of itemname
- property namefunction
- mapper from string to itemdefaultValue
- default value if property not setprotected <T> Config<S> setList(java.lang.String name, java.util.function.Function<? super T,java.lang.String> function, java.util.List<T> value)
function
.T
- type of itemsname
- propertyNamefunction
- to transform item to a Stringvalue
- list of itemsprotected <T> Config<S> setOrClear(java.lang.String name, java.util.Collection<T> collection)
T
- type of itemsname
- propertyNamecollection
- collection of itemsprotected boolean isValidLength(java.lang.String field, int maxLength)
field
- the field to validatemaxLength
- the maximum allowed length of the fieldprotected boolean hasField(java.lang.String name)
name
- the field nameprotected boolean hasField(com.fasterxml.jackson.databind.node.ObjectNode node, java.lang.String name)
node
- the node to examinename
- the name to look forprotected boolean hasOnlyFields(java.lang.String... allowedFields)
allowedFields
- allowed field namesprotected boolean hasOnlyFields(com.fasterxml.jackson.databind.node.ObjectNode node, java.lang.String... allowedFields)
node
- node whose fields to checkallowedFields
- allowed field namesprotected boolean hasFields(java.lang.String... mandatoryFields)
mandatoryFields
- mandatory field namesprotected boolean hasFields(com.fasterxml.jackson.databind.node.ObjectNode node, java.lang.String... mandatoryFields)
node
- node whose fields to checkmandatoryFields
- mandatory field namesprotected boolean isMacAddress(java.lang.String field, Config.FieldPresence presence)
field
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isMacAddress(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence)
objectNode
- JSON nodefield
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isIpAddress(java.lang.String field, Config.FieldPresence presence)
field
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isIpAddress(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence)
objectNode
- node from whom to access the fieldfield
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isIpPrefix(java.lang.String field, Config.FieldPresence presence)
field
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isIpPrefix(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence)
objectNode
- node from whom to access the fieldfield
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isTpPort(java.lang.String field, Config.FieldPresence presence)
field
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isTpPort(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence)
objectNode
- node from whom to access the fieldfield
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isConnectPoint(java.lang.String field, Config.FieldPresence presence)
field
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isConnectPoint(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence)
objectNode
- JSON nodefield
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isString(java.lang.String field, Config.FieldPresence presence, java.lang.String... pattern)
field
- JSON field namepresence
- specifies if field is optional or mandatorypattern
- optional regex patternInvalidFieldException
- if the field is present but not validprotected boolean isString(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence, java.lang.String... pattern)
objectNode
- JSON nodefield
- JSON field namepresence
- specifies if field is optional or mandatorypattern
- optional regex patternInvalidFieldException
- if the field is present but not validprotected boolean isNumber(java.lang.String field, Config.FieldPresence presence, long... minMax)
field
- JSON field namepresence
- specifies if field is optional or mandatoryminMax
- optional min/max valuesInvalidFieldException
- if the field is present but not validprotected boolean isNumber(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence, long... minMax)
objectNode
- JSON objectfield
- JSON field namepresence
- specifies if field is optional or mandatoryminMax
- optional min/max valuesInvalidFieldException
- if the field is present but not validprotected boolean isIntegralNumber(java.lang.String field, Config.FieldPresence presence, long... minMax)
field
- JSON field namepresence
- specifies if field is optional or mandatoryminMax
- optional min/max valuesInvalidFieldException
- if the field is present but not validprotected boolean isIntegralNumber(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence, long... minMax)
objectNode
- JSON nodefield
- JSON field namepresence
- specifies if field is optional or mandatoryminMax
- optional min/max valuesInvalidFieldException
- if the field is present but not validprotected boolean isDecimal(java.lang.String field, Config.FieldPresence presence, double... minMax)
field
- JSON field namepresence
- specifies if field is optional or mandatoryminMax
- optional min/max valuesInvalidFieldException
- if the field is present but not validprotected boolean isDecimal(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence, double... minMax)
objectNode
- JSON nodefield
- JSON field namepresence
- specifies if field is optional or mandatoryminMax
- optional min/max valuesInvalidFieldException
- if the field is present but not validprotected boolean isBoolean(java.lang.String field, Config.FieldPresence presence)
field
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validprotected boolean isBoolean(com.fasterxml.jackson.databind.node.ObjectNode objectNode, java.lang.String field, Config.FieldPresence presence)
objectNode
- JSON object nodefield
- JSON field namepresence
- specifies if field is optional or mandatoryInvalidFieldException
- if the field is present but not validpublic java.lang.String toString()
toString
in class java.lang.Object