Class ParsedTemplateMap
java.lang.Object
io.nosqlbench.engine.api.templating.ParsedTemplateMap
- All Implemented Interfaces:
DynamicFieldReader,StaticFieldReader,LongFunction<Map<String,?>>
public class ParsedTemplateMap
extends Object
implements LongFunction<Map<String,?>>, StaticFieldReader, DynamicFieldReader
A parsed map template, which allows construction of extracted or projected functions related
to dynamic value templates. This is the backing implementation for ParsedOp which is map-based
at the root level, but which can have recursive structure and thus needed an inner value type.
This implementation supports parsing/restructuring around string, map, and list templates.
The provided map is interpreted as a map of string to object templates using these rules:
- If the value is a String and contains no binding points, it is interpreted as a literal
- If the value is a String and contains only a binding point with no leading nor trailing text, it is interpreted as an object binding
- If the value is a String and contains a binding point with any leading or trailing text, it is interpreted as a String template binding
- If the value is a map, list, or set, then each element is interpreted as above
NBTypeConverter only if needed and can-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(long value) create a map of op field names and values, containing all statically and dynamically defined fields, but not including auxilliary config like params or activity params.applyFull(long value) <T> TGet the named field value for a given long input.<V> LongFunction<V> getAsCachedFunctionOr(String fieldname, String defaultValue, Function<String, V> init) Get a LongFunction that first creates a LongFunction of String as ingetAsFunctionOr(String, Object))}, but then applies the result and cached it for subsequent access.<V> LongFunction<V> getAsFunctionOr(String name, V defaultValue) Get a LongFunction which returns either the static value, the dynamic value, or the default value, in that order, depending on where it is found first.<V extends Enum<V>>
Optional<LongFunction<V>> getAsOptionalEnumFunction(String name, Class<? extends V> type) <V> Optional<LongFunction<V>> getAsOptionalFunction(String name, Class<? extends V> type) Get the op field as aLongFunction, using statics, then dynamics, then config sources.LongFunction<? extends String> getAsRequiredFunction(String name) Get the op field as aLongFunctionof String.<V> LongFunction<V> getAsRequiredFunction(String name, Class<? extends V> type) getAsStringTemplate(String fieldname) <T> TgetConfigOr(String name, T defaultValue, long input) Works exactly likegetStaticConfigOr(String, Object), except that dynamic values at the op field level will be generated on a per-input basis.Map<String, LongFunction<?>> LongFunction<?> Get theLongFunctionwhich is used to resolve a dynamic field value.getOptionalEnumFromField(Class<E> enumclass, String fieldname) Map a named op field to an enum<T> Optional<T> getOptionalStaticConfig(String name, Class<T> type) <T> Optional<T> getOptionalStaticValue(String field, Class<T> classOfT) Return an optional value for the named field.<E extends Enum<E>,V>
Optional<TypeAndTarget<E, V>> getOptionalTargetEnum(Class<E> enumclass, Class<? extends V> valueClass) Given an enum of any type, return the enum value which is found in any of the field names of the op template, ignoring case and any non-word characters.<E extends Enum<E>,V>
Optional<TypeAndTarget<E, V>> getOptionalTargetEnum(Class<E> enumclass, Class<V> valueClass, String alternateTypeField, String alternateValueField) <E extends Enum<E>,V>
Optional<TypeAndTarget<E, V>> getOptionalTargetEnum(Class<E> enumclass, String typeFieldName, String valueFieldName, Class<V> valueClass) intgetSize()<T> TgetStaticConfig(String name, Class<T> clazz) <T> TgetStaticConfigOr(String name, T defaultValue) Get the specified parameter by the user using the defined field which is closest to the op template.<T> TgetStaticValue(String field) Get the static value for the provided name, cast to the required type, where the type is inferred from the calling context.<T> TgetStaticValue(String field, Class<T> classOfT) Get the static value for the provided name, cast to the required type.<T> TgetStaticValueOr(String name, T defaultValue) Get the named static field value, or return the provided default, but throw an exception if the named field is dynamic.<E extends Enum<E>,V>
TypeAndTarget<E, V> getTargetEnum(Class<E> enumclass, Class<V> valueClass) <E extends Enum<E>,V>
TypeAndTarget<E, V> getTargetEnum(Class<E> enumclass, Class<V> valueClass, String tname, String vname) Class<?> getValueType(String fieldname) booleanbooleanbooleanbooleanbooleanisDefinedAll(String... fields) convenience method for conjugatingisDefined(String)with ANDbooleanisDefinedExactly(String[] fields) booleanbooleanbooleanisStatic()booleanbooleanbooleanisUndefined(String field) Inverse ofisDefined(String), provided for clarify in some situationsnewArrayBinder(String... fields) newArrayBinder(List<String> fields) newArrayBinderFromBindPoints(List<BindPoint> bindPoints) newListBinder(String... fields) newListBinder(List<String> fields) newOrderedMapBinder(String... fields) parseStaticCmdMap(String taskname, String mainField) parseStaticCmdMaps(String key, String mainField) takeAsNamedTemplates(String fieldname) Take the value of the specified field from the dynamic or static layers, or reference it from the config layer without removal.<V> Optional<V> takeAsOptionalRawSpecifier(String field) takeOptionalEnumFromField(Class<E> enumClass, String fieldName) <T> TtakeStaticConfigOr(String name, T defaultValue) <T> TtakeStaticValue(String field, Class<T> classOfT) toString()
-
Constructor Details
-
ParsedTemplateMap
-
-
Method Details
-
getCaptures
-
isDynamic
public boolean isDynamic()- Returns:
- true if any field of this template map is dynamic
-
isStatic
public boolean isStatic() -
isConfig
-
getStaticPrototype
-
getDynamicPrototype
-
getConfigPrototype
-
apply
create a map of op field names and values, containing all statically and dynamically defined fields, but not including auxilliary config like params or activity params. -
applyFull
-
isDynamic
- Specified by:
isDynamicin interfaceDynamicFieldReader- Returns:
- true if the specified field is found in the dynamic op fields
-
isStatic
- Returns:
- true if and only if the named field is present in the static field map.
-
isStatic
-
isDefined
- Specified by:
isDefinedin interfaceStaticFieldReader- Parameters:
fields- Names of fields to look for in the static, dynamic, or config field maps.- Returns:
- true if and only if all provided field names are present in the static or dynamic or config field maps.
-
getStaticValue
Get the static value for the provided name, cast to the required type.- Specified by:
getStaticValuein interfaceStaticFieldReader- Type Parameters:
T- The parameter type of the return type, used at compile time only to qualify asserted return type- Parameters:
field- Name of the field to getclassOfT- The type of the field to return. If actual type is not compatible to a cast to this type, then a casting error will be thrown.- Returns:
- A value of type T, or null
-
takeStaticValue
-
getStaticValue
Get the static value for the provided name, cast to the required type, where the type is inferred from the calling context.- Specified by:
getStaticValuein interfaceStaticFieldReader- Type Parameters:
T- The parameter type of the return type. used at compile time only to quality return type.- Parameters:
field- Name of the field to get- Returns:
- A value of type T, or null
-
getStaticValueOr
Get the named static field value, or return the provided default, but throw an exception if the named field is dynamic.- Specified by:
getStaticValueOrin interfaceStaticFieldReader- Type Parameters:
T- The type of the field to return.- Parameters:
name- The name of the field value to return.defaultValue- A value to return if the named value is not present in static nor dynamic fields.- Returns:
- The value
- Throws:
RuntimeException- if the field name is only present in the dynamic fields.
-
getStaticConfigOr
Get the specified parameter by the user using the defined field which is closest to the op template. This is the standard way of getting parameter values which can be specified at the op template, op param, or activity level.- Type Parameters:
T- The type of the value to return- Parameters:
name- The name of the configuration paramdefaultValue- the default value to return if the value is not defined anywhere in (op fields, op params, activity params)- Returns:
- A configuration value
- Throws:
NBConfigError- if the named field is defined dynamically, as in this case, it is presumed that the parameter is not supported unless it is defined statically.
-
getStaticConfig
-
takeStaticConfigOr
-
getOptionalStaticConfig
-
getConfigOr
Works exactly likegetStaticConfigOr(String, Object), except that dynamic values at the op field level will be generated on a per-input basis. This is a shortcut method for allowing configuration values to be accessed dynamically where it makes sense. -
getOptionalStaticValue
Return an optional value for the named field. This is anOptionalform ofgetStaticValue(java.lang.String, java.lang.Class<T>).- Specified by:
getOptionalStaticValuein interfaceStaticFieldReader- Type Parameters:
T- The parameter type of the return- Parameters:
field- Name of the field to getclassOfT- The type of field to return. If the actual type is not compatible to a cast to this type, then a casting error will be thrown.- Returns:
- An optional value, empty unless the named value is defined in the static field map.
-
get
Get the named field value for a given long input. This uses parameter type inference -- The casting to the return type will be based on the type of any assignment or casting on the caller's side. Thus, if the actual type is not compatable to a cast to the needed return type, a casting error will be thrown.- Specified by:
getin interfaceDynamicFieldReader- Type Parameters:
T- The parameter type of the returned value. Inferred from usage context.- Parameters:
field- The name of the field to get.input- The seed value, or cycle value for which to generate the value.- Returns:
- The value.
-
getOpFieldNames
-
getAsRequiredFunction
Get the op field as aLongFunctionof String. This is a convenience form forgetAsRequiredFunction(String, Class)- Parameters:
name- The field name which must be defined as static or dynamic- Returns:
- A function which can provide the named field value
-
getAsOptionalEnumFunction
public <V extends Enum<V>> Optional<LongFunction<V>> getAsOptionalEnumFunction(String name, Class<? extends V> type) -
getAsOptionalFunction
Get the op field as aLongFunction, using statics, then dynamics, then config sources.- Parameters:
name- The field name which must be defined as static or dynamictype- The value type which the field must be assignable to- Returns:
- A function which can provide a value for the given name and type
-
getAsRequiredFunction
-
getAsFunctionOr
Get a LongFunction which returns either the static value, the dynamic value, or the default value, in that order, depending on where it is found first.- Specified by:
getAsFunctionOrin interfaceDynamicFieldReader- Type Parameters:
V- The type of value to return- Parameters:
name- The param name for the valuedefaultValue- The default value to provide the value is not defined for static nor dynamic- Returns:
- A
LongFunctionof type V
-
getAsCachedFunctionOr
public <V> LongFunction<V> getAsCachedFunctionOr(String fieldname, String defaultValue, Function<String, V> init) Get a LongFunction that first creates a LongFunction of String as ingetAsFunctionOr(String, Object))}, but then applies the result and cached it for subsequent access. This relies onObjectCacheinternally. The purpose of this is to avoid costly re-computation for mapped values over pure functions where the computation cost is significantly high. For trivial functions, the cost is generally lower than the hash lookup within the object cache..- Type Parameters:
V- The type of object to return- Parameters:
fieldname- The name of the field which could contain a static or dynamic valuedefaultValue- The default value to use in the init function if the fieldname is not defined as static nor dynamicinit- A function to apply to the value to produce the product type- Returns:
- A caching function which chains to the init function, with caching
-
isDefined
- Specified by:
isDefinedin interfaceStaticFieldReader- Parameters:
field- The requested field name- Returns:
- true if the named field is defined as static or dynamic or config (params and activity params)
-
isUndefined
Inverse ofisDefined(String), provided for clarify in some situations- Parameters:
field- The field name- Returns:
- true if the named field is defined neither as static nor as dynamic
-
isDefined
- Specified by:
isDefinedin interfaceStaticFieldReader- Parameters:
field- The requested field nametype- The required type of the field value- Returns:
- true if the named field is defined as static or dynamic and the value produced can be assigned to the specified type
-
takeAsOptionalStringTemplate
-
takeAsOptionalRawSpecifier
-
takeAsNamedTemplates
Take the value of the specified field from the dynamic or static layers, or reference it from the config layer without removal. Then, flatten any string, list, or map structures into a map of strings with names injected as needed. Then, convert the values to string templates and return that.- Parameters:
fieldname- the field to take the templates from- Returns:
- A map of templates, or an empty map if the field is not defined or is empty.
-
getAsStringTemplate
-
isDefinedAll
convenience method for conjugatingisDefined(String)with AND- Returns:
- true if all specified fields are defined as static or dynamic or config
-
newListBinder
- Parameters:
fields- The ordered field names for which theListBinderwill be created- Returns:
- a new
ListBinderwhich can produce aListof Objects from a long input.
-
newListBinder
- Parameters:
fields- The ordered field names for which theListBinderwill be created- Returns:
- a new
ListBinderwhich can produce aListof Objects from a long input.
-
newOrderedMapBinder
- Parameters:
fields- The ordered field names for which theOrderedMapBinderwill be created- Returns:
- a new
OrderedMapBinderwhich can produce aMapof String to Objects from a long input.
-
newArrayBinder
- Parameters:
fields- The ordered field names for which theArrayBinderwill be created- Returns:
- a new
ArrayBinderwhich can produce aObjectarray from a long input.
-
newArrayBinder
- Parameters:
fields- The ordered field names for which theArrayBinderwill be created- Returns:
- a new
ArrayBinderwhich can produce aObjectarray from a long input.
-
newArrayBinderFromBindPoints
- Parameters:
bindPoints- TheBindPoints for which theArrayBinderwill be created- Returns:
- a new
ArrayBinderwhich can produce aObjectarray from a long input.
-
getMapper
Get theLongFunctionwhich is used to resolve a dynamic field value.- Parameters:
field- The field name for a dynamic parameter- Returns:
- The mapping function
-
getSize
public int getSize()- Returns:
- the logical map size, including all static and dynamic fields
-
getValueType
-
getOptionalTargetEnum
-
getOptionalTargetEnum
-
getOptionalTargetEnum
public <E extends Enum<E>,V> Optional<TypeAndTarget<E,V>> getOptionalTargetEnum(Class<E> enumclass, Class<? extends V> valueClass) Given an enum of any type, return the enum value which is found in any of the field names of the op template, ignoring case and any non-word characters. This is useful for matching op templates to op types where the presence of a field determines the type. Further, if there are multiple matching names, anOpConfigErroris thrown to avoid possible ambiguity.- Type Parameters:
E- Generic type for the enum class- Parameters:
enumclass- The enum class for matching values- Returns:
- Optionally, an enum value which matches, or
Optional.empty() - Throws:
OpConfigError- if more than one field matches
-
getTargetEnum
-
getTargetEnum
public <E extends Enum<E>,V> TypeAndTarget<E,V> getTargetEnum(Class<E> enumclass, Class<V> valueClass) -
getOptionalEnumFromField
public <E extends Enum<E>> Optional<E> getOptionalEnumFromField(Class<E> enumclass, String fieldname) Map a named op field to an enum- Type Parameters:
E- The generic type of the enum- Parameters:
enumclass- The type of enum to look withinfieldname- The field name to look for- Returns:
- An optional enum value
-
takeOptionalEnumFromField
-
parseStaticCmdMap
-
parseStaticCmdMaps
-
toString
-
isDefinedExactly
-
getCombinedPrototype
-