Class ConfigMap

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,Object>
de.qytera.qtaf.core.config.entity.ConfigMap
All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>

public class ConfigMap extends HashMap<String,Object>
Configuration entity.
See Also:
  • Constructor Details

    • ConfigMap

      public ConfigMap(com.jayway.jsonpath.DocumentContext documentContext, String location)
  • Method Details

    • getString

      public String getString(String key)
      Retrieves the value for the given key, interpreted as a String.
      Parameters:
      key - the key of the value to retrieve
      Returns:
      the key's value or null if there is no value or if the value cannot be interpreted as a String
    • getString

      public String getString(String key, String valueIfNull)
      Retrieves the value for the given key, interpreted as a String. Returns valueIfNull if the value does not exist, cannot be interpreted as a String or is null.
      Parameters:
      key - the key of the value to retrieve if possible
      valueIfNull - the value to return if retrieval was unsuccessful
      Returns:
      the key's value or the provided default value
    • getStringFromEnvironment

      public String getStringFromEnvironment(String key)
      Retrieves the value for the given key from environment variables.
      Parameters:
      key - configuration key
      Returns:
      the environment variable's value or null if the environment variable has not been set
    • getStringFromSystemProperty

      public String getStringFromSystemProperty(String key)
      Get value from system properties.
      Parameters:
      key - configuration key
      Returns:
      configuration value
    • setString

      public void setString(String key, String value)
      Set the value for the given key to the provided String.
      Parameters:
      key - the key of the value to set
      value - the value to set
    • getInt

      public Integer getInt(String key)
      Retrieves the value for the given key, interpreted as an Integer.
      Parameters:
      key - the key of the value to retrieve
      Returns:
      the key's value or null if there is no value or if the value cannot be interpreted as an Integer
    • getInt

      public Integer getInt(String key, Integer valueIfNull)
      Retrieves the value for the given key, interpreted as an Integer. Returns valueIfNull if the value does not exist, cannot be interpreted as an Integer or is null.
      Parameters:
      key - the key of the value to retrieve if possible
      valueIfNull - the value to return if retrieval was unsuccessful
      Returns:
      the key's value or the provided default value
    • setInt

      public void setInt(String key, Integer value)
      Set the value for the given key to the provided Integer.
      Parameters:
      key - the key of the value to set
      value - the value to set
    • getDouble

      public Double getDouble(String key)
      Retrieves the value for the given key, interpreted as a Double.
      Parameters:
      key - the key of the value to retrieve
      Returns:
      the key's value or null if there is no value or if the value cannot be interpreted as a Double
    • getDouble

      public Double getDouble(String key, Double valueIfNull)
      Retrieves the value for the given key, interpreted as a Double. Returns valueIfNull if the value does not exist, cannot be interpreted as a Double or is null.
      Parameters:
      key - the key of the value to retrieve if possible
      valueIfNull - the value to return if retrieval was unsuccessful
      Returns:
      the key's value or the provided default value
    • setDouble

      public void setDouble(String key, Double value)
      Set the value for the given key to the provided Double.
      Parameters:
      key - the key of the value to set
      value - the value to set
    • getBoolean

      public Boolean getBoolean(String key)
      Retrieves the value for the given key, interpreted as a Boolean.
      Parameters:
      key - the key of the value to retrieve
      Returns:
      the key's value or null if there is no value or if the value cannot be interpreted as a Boolean
    • getBoolean

      public Boolean getBoolean(String key, Boolean valueIfNull)
      Retrieves the value for the given key, interpreted as a Boolean. Returns valueIfNull if the value does not exist, cannot be interpreted as a Boolean or is null.
      Parameters:
      key - the key of the value to retrieve if possible
      valueIfNull - the value to return if retrieval was unsuccessful
      Returns:
      the key's value or the provided default value
    • setBoolean

      public void setBoolean(String key, Boolean value)
      Set the value for the given key to the provided Boolean.
      Parameters:
      key - the key of the value to set
      value - the value to set
    • getList

      public List<com.google.gson.JsonElement> getList(String key)
      Retrieves a list of values for the given key.
      Parameters:
      key - the key of the array to retrieve
      Returns:
      the list or null if there is no value or if the value cannot be interpreted as a list of JsonElement
    • logMissingValue

      public final <T> T logMissingValue(String key, T fallbackValue)
      Logs an error describing that a value was null (a missing key) and that a fallback value will be used instead.
      Type Parameters:
      T - the fallback value type
      Parameters:
      key - the missing key
      fallbackValue - the value that will be used instead
      Returns:
      the fallback value
    • logUnknownValue

      @SafeVarargs public final <T> T logUnknownValue(String key, T unknownValue, T fallbackValue, T... knownValues)
      Logs an error that an unknown value was encountered for the given key. An optional array of known values can be provided to provide more detail.
      Type Parameters:
      T - the value type
      Parameters:
      key - the key for which an unknown value was retrieved
      unknownValue - the unknown value
      fallbackValue - the value that will be used instead
      knownValues - the array of known values
      Returns:
      the fallback value
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map<String,Object>
      Overrides:
      equals in class AbstractMap<String,Object>
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<String,Object>
      Overrides:
      hashCode in class AbstractMap<String,Object>
    • getLocation

      public String getLocation()
      The path of the underlying document used to build the configuration map.