public abstract class EngineParameters extends Object
Parameter
annotation. The annotation also has an optional attribute
binaryLengthLimit
which marks the number of bits to consider
when tuning the parameter. When applied to floating point values, its effects are less intuitive as instead of ignoring bits of the
number's binary representation, it just sets a maximum for the values it can take on which will be equal to what this maximum would be
for integer numbers (2^[limit] - 1).
WARNING: No negative values are supported, thus the most significant bit of each signed primitive (all except boolean and char) field
will be ignored when generating the binary string or setting the values of the fields based on a binary string and negative values will
default to 0 when setting the fields based on a double array.Modifier | Constructor and Description |
---|---|
protected |
EngineParameters()
Constructs an instance and scans the fields of the (extending) class for ones annotated as
Parameter . |
Modifier and Type | Method and Description |
---|---|
void |
loadFrom(String filePath)
Reads the parameter values from an XML file and sets the instance's fields accordingly.
|
double[] |
maxValues()
Returns an array of doubles holding the maximum allowed values for all the fields declared as parameters by the
Parameter annotation. |
double[] |
maxValues(Set<ParameterType> types)
Returns an array of doubles holding the maximum allowed values for all the fields declared as parameters of the specified type by the
Parameter annotation. |
boolean |
set(double[] values)
Sets the values of the parameter fields of the instance.
|
boolean |
set(double[] values,
Set<ParameterType> types)
Sets the values of the parameter fields of the specified type.
|
boolean |
set(String binaryString)
Sets the values of the parameter fields based on the binaryString in which each character represents a bit in the string of the
individual gray code strings of the values of the parameter fields of the specified type in the order of declaration.
|
boolean |
set(String binaryString,
Set<ParameterType> types)
Sets the values of the parameter fields of the specified type based on the binaryString in which each character represents a bit in the
string of the individual gray code strings of the values of the parameter fields of the specified type in the order of declaration.
|
String |
toGrayCodeString()
Returns a binary string of all the bits of all the fields annotated as a
Parameter
concatenated field by field. |
String |
toGrayCodeString(Set<ParameterType> types)
Returns a binary string of all the bits of the fields annotated as a
Parameter of the
specified type concatenated field by field. |
String |
toString() |
double[] |
values()
Returns an array of doubles holding the values of all the fields declared as parameters by the
Parameter annotation. |
double[] |
values(Set<ParameterType> types)
Returns an array of doubles holding the values of all the fields declared as parameters of the specified type by the
Parameter annotation. |
double[] |
valuesFromMap(Map<String,Double> paramValues,
Set<ParameterType> types)
Builds an array of values based on the entries of the provided map.
|
boolean |
writeToFile(String filePath)
Writes the parameters to the specified file.
|
protected EngineParameters() throws ParameterException
Parameter
.ParameterException
- If a static or non-primitive field is annotated as Parameter
.public final void loadFrom(String filePath) throws Exception
filePath
- The path to the file.Exception
- If an error occurs from which it is not possible to recover.public final boolean writeToFile(String filePath)
filePath
- The path to the file.public final boolean set(double[] values)
Parameter
annotation's attribute would allow for, the field will be set to its maximum allowed value. If the array is longer than the number of
parameter fields, the extra elements will be ignored; if it is shorter, the fields indexed higher than the length of the array will not
be set. For boolean fields, a value greater than or equal to 1 will default to true, everything else will default to false.values
- An array of values for the parameter fields of the instance in the order of declaration.public final boolean set(double[] values, Set<ParameterType> types)
Parameter
annotation's attribute would allow for, the field will be set to its maximum allowed value. If the array is longer than the number of
parameter fields of the specified type, the extra elements will be ignored; if it is shorter, the fields indexed higher than the length
of the array will not be set. For boolean fields, a value greater than or equal to 1 will default to true, everything else will default
to false.values
- An array of values for the parameter fields of the specified type in the order of declaration.types
- A set of the types of parameter fields whose values should be set based on the input array. If it is null, the values will
be applied to the set of all parameter fields.public final boolean set(String binaryString)
binaryString
- A binary string of gray code such as the output of toGrayCodeString
.public final boolean set(String binaryString, Set<ParameterType> types)
binaryString
- A binary string of gray code such as the output of toGrayCodeString
.types
- A set of the types of parameter fields whose values should be derived from the binary string and set. If it is null, the
values derived will be applied to all parameter fields.public final double[] valuesFromMap(Map<String,Double> paramValues, Set<ParameterType> types)
paramValues
- A map of parameter names and their corresponding values.types
- The types of parameters to include.public final double[] values()
Parameter
annotation. Boolean values will be converted to either 1 or 0 depending on whether they
are true or false.public final double[] values(Set<ParameterType> types)
Parameter
annotation. Boolean values will be converted to either 1 or 0 depending on whether they
are true or false.types
- A set of the types of parameter fields whose max values are to be returned. If it is null the max values for all parameter
fields will be returned.public final double[] maxValues()
Parameter
annotation. The values are determined by the field type and the binaryLengthLimit
attribute of the annotation.public final double[] maxValues(Set<ParameterType> types)
Parameter
annotation. The values are determined by the field type and the
binaryLengthLimit attribute of the annotation.types
- A set of the types of parameter fields whose max values are to be returned. If it is null the max values for all parameter
fields will be returned.public final String toGrayCodeString()
Parameter
concatenated field by field. Floating point values will be cast to integer values (float to int, double to long) for their binary
representation which may result in information loss.public final String toGrayCodeString(Set<ParameterType> types)
Parameter
of the
specified type concatenated field by field. Floating point values will be cast to integer values (float to int, double to long) for
their binary representation which may result in information loss.types
- A set of the types of parameters whose values are to be included in the string. If it is null, all parameters' values will
be included.Copyright © 2020. All rights reserved.