Class ConfigSection

java.lang.Object
nz.org.riskscape.config.ConfigSection

public abstract class ConfigSection extends Object

A named collection of somewhat ordered key/value pairs appearing as part of Config

  • Constructor Details

    • ConfigSection

      public ConfigSection(URI location, String name)
  • Method Details

    • wild

      public static Map<String,List<?>> wild(Map<String,List<String>> multiMap)

      Defeat Java's generics checking - it's safe to treat a list of strings as a list of wild things, but to do this with java's generics requires us to declare the receiver as ? extends List<?> which complicates the receiver a lot. I can't think of any cases where the use of this would cause a class cast exception, and it simplifies the use of APIs that accept a list of anything vs a list of strings (like binding)

    • hasKey

      public boolean hasKey(String key)
      Returns:
      true if this section contains at least one value for the given key
    • getOneRequired

      public ResultOrProblems<String> getOneRequired(String key)
      Returns:
      a value for the given key, or an error if it was missing or if there multiple values defined
    • getOne

      public Optional<ResultOrProblems<String>> getOne(String key)
      Returns:
      a value for the given key, or an error if multiple values were defined. Also wraps it in an optional (i know...) if the value is not defined.
    • getAll

      public List<String> getAll(String key)
      Returns:
      a list of all values defined for the given key, or an empty list if none are defined
    • toMap

      public Map<String,String> toMap()
      Returns:
      a map view of all the key value pairs, where repeated keys are ignored (last one wins)
    • toMultiMap

      public Map<String,List<String>> toMultiMap()

      Builds a multi-map view of all the key values, where repeated keys return a list of all the values for the key. This is a version of toConfigMap where the ConfigStrings are converted to strings for cases where the location metadata isn't wanted (or ConfigString isn't yet handled).

    • toConfigMap

      public abstract Map<ConfigString,List<ConfigString>> toConfigMap()
      Returns:
      a multi-map view of all the key values, where repeated keys return a list of all the values for the key
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getLocation

      public URI getLocation()
      Returns:
      the location that was the source of this configuration section
    • getName

      public String getName()
      Returns:
      a name that uniquely identifies this Config section among all others from the same Config object. This might have a prefix added for the type of thing this config identifies, e.g. "type flood_hazard"