Class JsonParameterSet

java.lang.Object
org.tudalgo.algoutils.tutor.general.json.JsonParameterSet

public class JsonParameterSet extends Object
A set of test parameters that are stored in a json file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonParameterSet(com.fasterxml.jackson.databind.JsonNode rootNode, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Map<String,Function<com.fasterxml.jackson.databind.JsonNode,?>> customConverters)
    Creates a new JsonParameterSet.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a list of all available keys in the json file.
    <T> T
    get(String key)
    Retrieves the value of the given key from the json file.
    <T> T
    get(String key, Class<T> type)
    Retrieves the value of the given key from the json file and converts it to the given type.
    boolean
    Retrieves the value of the given key from the json file and converts it to a boolean.
    byte
    Retrieves the value of the given key from the json file and converts it to a byte.
    char
    Retrieves the value of the given key from the json file and converts it to a char.
    double
    Retrieves the value of the given key from the json file and converts it to a double.
    float
    Retrieves the value of the given key from the json file and converts it to a float.
    int
    Retrieves the value of the given key from the json file and converts it to an int.
    long
    Retrieves the value of the given key from the json file and converts it to a long.
    com.fasterxml.jackson.databind.ObjectMapper
    Returns the ObjectMapper that is used to convert the json nodes to java objects.
    com.fasterxml.jackson.databind.JsonNode
    Returns the root node of the json file.
    short
    Retrieves 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 a String.
    toContext(String... ignoreKeys)
    Returns a Context containing all available keys and their values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 new JsonParameterSet.
      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 the ObjectMapper that is used to convert the json nodes to java objects.
      Returns:
      the ObjectMapper that is used to convert the json nodes to java objects.
    • get

      public <T> T get(String key, Class<T> type)
      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

      public <T> T get(String key)
      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

      public boolean getBoolean(String key)
      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

      public byte getByte(String key)
      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

      public short getShort(String key)
      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

      public int getInt(String key)
      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

      public long getLong(String key)
      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

      public float getFloat(String key)
      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

      public double getDouble(String key)
      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

      public char getChar(String key)
      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

      public String getString(String key)
      Retrieves the value of the given key from the json file and converts it to a String.
      Parameters:
      key - the key of the value.
      Returns:
      the value of the given key from the json file converted to a String.
    • availableKeys

      public List<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

      public Context toContext(String... ignoreKeys)
      Returns a Context containing 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 Context containing all available keys and their values.