Package io.virtdata.core
Class Bindings
- java.lang.Object
-
- io.virtdata.core.Bindings
-
public class Bindings extends java.lang.ObjectMaps a template with named bind points and specifiers onto a set of data mapping function instances. Allows for streamlined calling of mapper functions as a set.There are several ways to get generated data via this class. You must always provide a base input value. Fields can be accessed by parameter position or name. In some cases, you can provide an iterator stride in order to get data in bulk. In other cases, you can have setters called directly on your provided objects. See the detailed method docs for more information.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBindings.FieldSetter
-
Constructor Summary
Constructors Constructor Description Bindings(BindingsTemplate template, java.util.List<DataMapper<?>> dataMappers)
-
Method Summary
Modifier and Type Method Description java.lang.Objectget(int i, long input)Get a value for the data mapper in slot ijava.lang.Objectget(java.lang.String name, long input)Get a value for the cached mapper name, using the name to mapper index cache.java.lang.Object[]getAll(long input)Get a value from each data mapper in the bindings listjava.util.Map<java.lang.String,java.lang.Object>getAllMap(long input)java.util.List<java.util.Map<java.lang.String,java.lang.Object>>getIteratedMaps(long input, int count)Generate a list of maps over a range of inputs.java.util.Map<java.lang.String,java.lang.Object>getIteratedSuffixMap(long input, int count)Generate a map containing the results from multiple iterations, suffixing the keys in the map with the iterations from 0 to count-1.java.util.Map<java.lang.String,java.lang.Object>getIteratedSuffixMap(long input, int count, java.lang.String... fieldNames)This is a version of thesetIteratedSuffixMap(Map, long, int, String[])which creates a new map for each call.LazyValuesMapgetLazyMap(long input)BindingsTemplategetTemplate()voidsetAllFields(Bindings.FieldSetter fieldSetter, long input)Generate all the values named in the bind point names, then call the user-provided field setter for each name and object generated.voidsetAllFieldsIterated(Bindings.FieldSetter fieldSetter, long input, int count)Generate all the values named in the bindings for a number of iterations, calling a user-provided field setter for each name and object generated, with the iteration number appended to the fieldName.voidsetIteratedSuffixMap(java.util.Map<java.lang.String,java.lang.Object> donorMap, long input, long count)Set the values in a provided map, with the bound names suffixed with an internal iteration value.voidsetMap(java.util.Map<java.lang.String,java.lang.Object> donorMap, long cycle)Generate all values in the bindings template, and set each of them in the map according to their bind point name.voidsetNamedFields(Bindings.FieldSetter fieldSetter, long input, java.lang.String... fieldName)Generate only the values named in fieldNames, and then call the user-provided field setter for each name and object generated.voidsetNamedFieldsIterated(Bindings.FieldSetter fieldSetter, long input, int count, java.lang.String... fieldName)Generate all the values named in the bindings for a number of iterations, calling a user-provided field setter for each name and object generated, with the iteration number appended to the fieldName, but only for the named bindings.voidsetSuffixedMap(java.util.Map<java.lang.String,java.lang.Object> donorMap, long cycle, java.lang.String suffix)Set the values in a provided map, with bound names suffixed with some value.java.lang.StringtoString()voidupdateMap(java.util.Map<java.lang.String,java.lang.Object> donorMap, long input)Generate only the values which have matching keys in the provided map according to their bind point names, and assign them to the map under that name.
-
-
-
Constructor Detail
-
Bindings
public Bindings(BindingsTemplate template, java.util.List<DataMapper<?>> dataMappers)
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getAll
public java.lang.Object[] getAll(long input)
Get a value from each data mapper in the bindings list- Parameters:
input- The long value which the bound data mappers will use as in input- Returns:
- An array of objects, the values yielded from each data mapper in the bindings list
-
getTemplate
public BindingsTemplate getTemplate()
- Returns:
BindingsTemplateassociated with this set of bindings
-
getAllMap
public java.util.Map<java.lang.String,java.lang.Object> getAllMap(long input)
- Parameters:
input- The input value for which the values should be generated.- Returns:
MapofStringtoObject
-
getIteratedMaps
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> getIteratedMaps(long input, int count)Generate a list of maps over a range of inputs.For example, calling getIteratedMaps(5,3) with bindings named alpha and gamma might produce something like:
-
- alpha -> val1
- gamma -> val2
-
- alpha -> val3
- gamma -> val4
-
- alpha -> val5
- gamma -> val6
- Parameters:
input- The base value for which the values should be generated.count- The number of iterations, starting at input, to be generated- Returns:
ListofMapofStringtoObject
-
-
getIteratedSuffixMap
public java.util.Map<java.lang.String,java.lang.Object> getIteratedSuffixMap(long input, int count)Generate a map containing the results from multiple iterations, suffixing the keys in the map with the iterations from 0 to count-1.For example, calling getIteratedSuffixMap(5, 3) with generators named alpha and gamma might yield results like
- alpha0 -> val1
- gamma0 -> val2
- alpha1 -> val3
- gamma1 -> val4
- alpha2 -> val5
- gamma2 -> val6
- Parameters:
input- The base input value for which the values should be generatedcount- The count of maps that should be added to the final map- Returns:
MapofStringtoObject
-
getIteratedSuffixMap
public java.util.Map<java.lang.String,java.lang.Object> getIteratedSuffixMap(long input, int count, java.lang.String... fieldNames)This is a version of thesetIteratedSuffixMap(Map, long, int, String[])which creates a new map for each call.- Parameters:
input- The base input value for which the values should be generatedcount- The count of maps that should be added to the final mapfieldNames- The field names which are used to look up the functions in the binding- Returns:
- A newly created map with the generated names and values.
-
get
public java.lang.Object get(int i, long input)Get a value for the data mapper in slot i- Parameters:
i- the data mapper slot, 0-indexedinput- the long input value which the bound data mapper will use as input- Returns:
- a single object, the value yielded from the indexed data mapper in the bindings list
-
get
public java.lang.Object get(java.lang.String name, long input)Get a value for the cached mapper name, using the name to mapper index cache.- Parameters:
name- The field name in the data mapperinput- the long input value which the bound data mapper will use as an input- Returns:
- a single object, the value yielded from the named and indexed data mapper in the bindings list.
-
setMap
public void setMap(java.util.Map<java.lang.String,java.lang.Object> donorMap, long cycle)Generate all values in the bindings template, and set each of them in the map according to their bind point name.- Parameters:
donorMap- - a user-provided Map<String,Object>cycle- - the cycle for which to generate the values
-
setSuffixedMap
public void setSuffixedMap(java.util.Map<java.lang.String,java.lang.Object> donorMap, long cycle, java.lang.String suffix)Set the values in a provided map, with bound names suffixed with some value. No non-overlapping keys in the map will be affected.- Parameters:
donorMap- an existingMapofStringtoObjectcycle- the cycle for which values should be generatedsuffix- a string suffix to be appended to any map keys
-
setIteratedSuffixMap
public void setIteratedSuffixMap(java.util.Map<java.lang.String,java.lang.Object> donorMap, long input, long count)Set the values in a provided map, with the bound names suffixed with an internal iteration value.- Parameters:
donorMap- an existingMapofStringtoObjectinput- the base cycle for which values should be generatedcount- the number of iterations to to generate values and keynames for
-
updateMap
public void updateMap(java.util.Map<java.lang.String,java.lang.Object> donorMap, long input)Generate only the values which have matching keys in the provided map according to their bind point names, and assign them to the map under that name. It is an error for a key name to be defined in the map for which there is no mapper.- Parameters:
donorMap- - a user-provided Map<String,Object>input- - the input for which to generate the values
-
setNamedFields
public void setNamedFields(Bindings.FieldSetter fieldSetter, long input, java.lang.String... fieldName)
Generate only the values named in fieldNames, and then call the user-provided field setter for each name and object generated.- Parameters:
fieldSetter- user-provided object that implementsBindings.FieldSetter.input- the input for which to generate valuesfieldName- A varargs list of field names, or a String[] of names to set
-
setNamedFieldsIterated
public void setNamedFieldsIterated(Bindings.FieldSetter fieldSetter, long input, int count, java.lang.String... fieldName)
Generate all the values named in the bindings for a number of iterations, calling a user-provided field setter for each name and object generated, with the iteration number appended to the fieldName, but only for the named bindings.- Parameters:
fieldSetter- user-provided object that implementsBindings.FieldSetterinput- the base input value for which the objects should be generatedcount- the number of iterations to generate values and names forfieldName- the field names for which to generate values and names
-
setAllFields
public void setAllFields(Bindings.FieldSetter fieldSetter, long input)
Generate all the values named in the bind point names, then call the user-provided field setter for each name and object generated.- Parameters:
fieldSetter- user-provided object that implementsBindings.FieldSetterinput- the input for which to generate values
-
setAllFieldsIterated
public void setAllFieldsIterated(Bindings.FieldSetter fieldSetter, long input, int count)
Generate all the values named in the bindings for a number of iterations, calling a user-provided field setter for each name and object generated, with the iteration number appended to the fieldName.- Parameters:
fieldSetter- user-provided object that implementsBindings.FieldSetterinput- the base input value for which the objects should be generatedcount- the number of iterations to generate values and names for
-
getLazyMap
public LazyValuesMap getLazyMap(long input)
-
-