Class JsonParameterSet
java.lang.Object
org.tudalgo.algoutils.tutor.general.json.JsonParameterSet
A set of test parameters that are stored in a json file.
-
Constructor Summary
ConstructorsConstructorDescriptionJsonParameterSet(com.fasterxml.jackson.databind.JsonNode rootNode, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Map<String, Function<com.fasterxml.jackson.databind.JsonNode, ?>> customConverters) Creates a newJsonParameterSet. -
Method Summary
Modifier and TypeMethodDescriptionReturns a list of all available keys in the json file.<T> TRetrieves the value of the given key from the json file.<T> TRetrieves the value of the given key from the json file and converts it to the given type.booleangetBoolean(String key) Retrieves the value of the given key from the json file and converts it to a boolean.byteRetrieves the value of the given key from the json file and converts it to a byte.charRetrieves the value of the given key from the json file and converts it to a char.doubleRetrieves the value of the given key from the json file and converts it to a double.floatRetrieves the value of the given key from the json file and converts it to a float.intRetrieves the value of the given key from the json file and converts it to an int.longRetrieves the value of the given key from the json file and converts it to a long.com.fasterxml.jackson.databind.ObjectMapperReturns theObjectMapperthat is used to convert the json nodes to java objects.com.fasterxml.jackson.databind.JsonNodeReturns the root node of the json file.shortRetrieves the value of the given key from the json file and converts it to a short.Retrieves the value of the given key from the json file and converts it to aString.Returns aContextcontaining all available keys and their values.
-
Constructor Details
-
JsonParameterSet
public JsonParameterSet(com.fasterxml.jackson.databind.JsonNode rootNode, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Map<String, Function<com.fasterxml.jackson.databind.JsonNode, ?>> customConverters) Creates a newJsonParameterSet.- Parameters:
rootNode- the root node of the json file.objectMapper- the object mapper that is used to convert the json nodes to java objects.customConverters- the custom converters that are used to convert the json nodes to java objects.
-
-
Method Details
-
getRootNode
public com.fasterxml.jackson.databind.JsonNode getRootNode()Returns the root node of the json file.- Returns:
- the root node of the json file.
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()Returns theObjectMapperthat is used to convert the json nodes to java objects.- Returns:
- the
ObjectMapperthat is used to convert the json nodes to java objects.
-
get
Retrieves the value of the given key from the json file and converts it to the given type.if the given type is null, it is assumed that a custom converter for the given key exists which maps the json node to the desired type.
- Type Parameters:
T- the type to which the value should be converted.- Parameters:
key- the key of the value.type- the class of the type to which the value should be converted.- Returns:
- the value of the given key from the json file converted to the given type.
- Throws:
IllegalArgumentException- if the given key does not exist in the json file.
-
get
Retrieves the value of the given key from the json file.- Type Parameters:
T- the type of the value.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file.
-
getBoolean
Retrieves the value of the given key from the json file and converts it to a boolean.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file converted to a boolean.
-
getByte
Retrieves the value of the given key from the json file and converts it to a byte.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file converted to a byte.
-
getShort
Retrieves the value of the given key from the json file and converts it to a short.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file converted to a short.
-
getInt
Retrieves the value of the given key from the json file and converts it to an int.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file converted to an int.
-
getLong
Retrieves the value of the given key from the json file and converts it to a long.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file converted to a long.
-
getFloat
Retrieves the value of the given key from the json file and converts it to a float.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file converted to a float.
-
getDouble
Retrieves the value of the given key from the json file and converts it to a double.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file converted to a double.
-
getChar
Retrieves the value of the given key from the json file and converts it to a char.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file converted to a char.
-
getString
Retrieves the value of the given key from the json file and converts it to aString.- Parameters:
key- the key of the value.- Returns:
- the value of the given key from the json file converted to a
String.
-
availableKeys
Returns a list of all available keys in the json file.- Returns:
- a list of all available keys in the json file.
-
toContext
Returns aContextcontaining all available keys and their values. Useful for writing Tests.If some keys should not be visible in the output, they can be ignored by passing them as parameters.
- Parameters:
ignoreKeys- keys to ignore for the output- Returns:
- a
Contextcontaining all available keys and their values.
-