Class Config


  • public class Config
    extends Object
    Structured representation of data read from a stack of .ini files, where each file can override values defined by the previous ones.
    • Field Detail

      • DEFAULT_PAIR_SEPARATOR

        public static final char DEFAULT_PAIR_SEPARATOR
        Used in a string representation of a map; separates pairs of value
        See Also:
        Constant Field Values
      • DEFAULT_KEY_VALUE_SEPARATOR

        public static final String DEFAULT_KEY_VALUE_SEPARATOR
        Used in a string representation of a map; separates keys from values
        See Also:
        Constant Field Values
    • Constructor Detail

      • Config

        public Config()
        Convenience constructor to create an empty config.
      • Config

        public Config​(RawConfig rawConfig)
      • Config

        public Config​(RawConfig rawConfig,
                      com.google.common.collect.ImmutableMap<Path,​RawConfig> configsMap)
    • Method Detail

      • get

        public com.google.common.collect.ImmutableMap<String,​String> get​(String sectionName)
      • getOrderIndependentHashCode

        public com.google.common.hash.HashCode getOrderIndependentHashCode()
        gets an order-independent HashCode of this Config's raw data.
      • getSectionToEntries

        public com.google.common.collect.ImmutableMap<String,​com.google.common.collect.ImmutableMap<String,​String>> getSectionToEntries()
      • getListWithoutComments

        public com.google.common.collect.ImmutableList<String> getListWithoutComments​(String sectionName,
                                                                                      String propertyName)
        Returns:
        An ImmutableList containing all entries that don't look like comments, or the empty list if the property is not defined or there are no values.
      • getListWithoutComments

        public com.google.common.collect.ImmutableList<String> getListWithoutComments​(String sectionName,
                                                                                      String propertyName,
                                                                                      char splitChar)
      • getOptionalListWithoutComments

        public Optional<com.google.common.collect.ImmutableList<String>> getOptionalListWithoutComments​(String sectionName,
                                                                                                        String propertyName)
        ini4j leaves things that look like comments in the values of entries in the file. Generally, we don't want to include these in our parameters, so filter them out where necessary. In an INI file, the comment separator is ";", but some parsers (ini4j included) use "#" too. This method handles both cases.
        Returns:
        an ImmutableList containing all entries that don't look like comments, the empty list if the property is defined but there are no values, or Optional.empty() if the property is not defined.
      • getOptionalListWithoutComments

        public Optional<com.google.common.collect.ImmutableList<String>> getOptionalListWithoutComments​(String sectionName,
                                                                                                        String propertyName,
                                                                                                        char splitChar)
      • getBooleanValue

        public boolean getBooleanValue​(String sectionName,
                                       String propertyName,
                                       boolean defaultValue)
      • getMap

        public com.google.common.collect.ImmutableMap<String,​String> getMap​(String section,
                                                                                  String field,
                                                                                  char pairSeparatorChar,
                                                                                  String keyValueSeparator)
        Convert a string representation of a map to a binary ImmutableMap<String, String>
        Parameters:
        section - Config file section name
        field - Config file value name
        pairSeparatorChar - Character that separates pairs of keys and values
        keyValueSeparator - String that separates keys and values
        Returns:
        An ImmutableMap
      • getMap

        public com.google.common.collect.ImmutableMap<String,​String> getMap​(String section,
                                                                                  String field)
        Convert a string representation of a map to a binary ImmutableMap<String, String>, using default separators
        Parameters:
        section - Config file section name
        field - Config file value name
        Returns:
        An ImmutableMap
      • hashCode

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

        public Config overrideWith​(Config other)
      • getRawConfig

        public RawConfig getRawConfig()
      • getConfigsMap

        public com.google.common.collect.ImmutableMap<Path,​RawConfig> getConfigsMap()
        A map of Paths to the RawConfig that came from that config file. When accessing this structure, bear in mind that it might have values that have been overriden in the merged rawConfig.
        Returns:
        A map of Paths to the RawConfig whose origin is that config file.