Class ConfigMap

java.lang.Object
java.util.AbstractMap<String,String>
org.bgerp.app.cfg.ConfigMap
All Implemented Interfaces:
Map<String,String>
Direct Known Subclasses:
Preferences, SimpleConfigMap

public abstract class ConfigMap extends AbstractMap<String,String>
Key - value strings map.
  • Field Details

  • Constructor Details

    • ConfigMap

      public ConfigMap()
  • Method Details

    • get

      public abstract String get(String key, String def)
    • entrySet

      public abstract Set<Map.Entry<String,String>> entrySet()
      Specified by:
      entrySet in interface Map<String,String>
      Specified by:
      entrySet in class AbstractMap<String,String>
    • get

      public String get(Object key)
      Specified by:
      get in interface Map<String,String>
      Overrides:
      get in class AbstractMap<String,String>
    • getSok

      public String getSok(String def, boolean validate, String... keys) throws BGMessageException
      Retrieves by key value with support of old keys.
      Parameters:
      def - default value.
      validate - throw an exception on using old keys.
      keys - first key is the actual one, after - olds.
      Returns:
      Throws:
      BGMessageException
    • getSok

      public String getSok(String... keys)
      Retrieves by key value with support of old keys.
      Parameters:
      keys - first key is the actual one, after - olds.
      Returns:
    • getInt

      public int getInt(String key, int def)
    • getInt

      public int getInt(String key)
    • getLong

      public long getLong(String key, long def)
    • getLong

      public long getLong(String key)
    • getSokLong

      public long getSokLong(long def, boolean validate, String... keys) throws BGMessageException
      Retrieves by key value with support of old keys.
      Parameters:
      def - default value.
      validate - throw an exception on using old keys.
      keys - first key is the actual one, after - olds.
      Returns:
      Throws:
      BGMessageException
    • getSokLong

      public long getSokLong(long def, String... keys)
      Retrieves by key value with support of old keys.
      Parameters:
      def - default value.
      keys - first key is the actual one, after - olds.
      Returns:
      Throws:
      BGMessageException
    • getBoolean

      public final boolean getBoolean(String key)
      Retrieves by key a boolean value with default false.
      Parameters:
      key - the key.
      Returns:
      See Also:
    • getBoolean

      public final boolean getBoolean(String key, boolean defaultValue)
      Retrieves by key a boolean value.
      Parameters:
      key - the key.
      defaultValue - default value.
      Returns:
      See Also:
    • getSokBoolean

      public boolean getSokBoolean(boolean def, boolean validate, String... keys) throws BGMessageException
      Retrieves by key value with support of old keys.
      Parameters:
      def - default value.
      validate - throw an exception on using old keys.
      keys - first key is the actual one, after - olds.
      Returns:
      Throws:
      BGMessageException
    • getSokBoolean

      public boolean getSokBoolean(boolean def, String... keys)
      Retrieves by key value with support of old keys.
      Parameters:
      def - default value.
      keys - first key is the actual one, after - olds.
      Returns:
      Throws:
      BGMessageException
    • getBigDecimal

      public BigDecimal getBigDecimal(String key, BigDecimal def)
    • sub

      public ConfigMap sub(String prefix)
      Creates a sub map by a key prefix
      prefixkey1=value1
      prefixkey2=value2
      ->
      map
      key1=value1
      key2=value2
      Parameters:
      prefix - the key prefix for extraction
      Returns:
      not null config map
    • subSok

      public ConfigMap subSok(String... prefixes)
      Creates a sub map by key prefixes
      prefixkey1=value1
      prefixkey2=value2
      ->
      config map
      key1=value1
      key2=value2
      Parameters:
      prefixes - key prefixes for extraction, the first one is the actual, the rest are deprecated prefixes
      Returns:
      not null config map
    • subIndexed

      public SortedMap<Integer, ConfigMap> subIndexed(String prefix)
      Creates a sorted map of maps by a key prefix
      prefix1.12=2
      prefix1.34=4
      prefix2.56=2
      prefix2.78=4
      ->
      sorted Map
      1={12=2,34=4}
      2={56=2,78=4}
      Parameters:
      prefix - the key prefix for extraction
      Returns:
      not null map
    • subSokIndexed

      public SortedMap<Integer, ConfigMap> subSokIndexed(String... prefixes)
      Creates a sorted map of maps by key prefixes
      prefix1.12=2
      prefix1.34=4
      prefix2.56=2
      prefix2.78=4
      ->
      sorted Map
      1={12=2,34=4}
      2={56=2,78=4}
      Parameters:
      prefixes - key prefixes for extraction, the first one is the actual, the rest are deprecated prefixes
      Returns:
      not null map
    • subKeyed

      public Map<String, ConfigMap> subKeyed(String prefix)
      Creates a map of maps by a key prefix
      prefixa.12=2
      prefixa.34=4
      prefixb.56=u
      prefixb.kk=4
      ->
      unsorted map
      a={12=2,34=4}
      b={56=u,kk=4}
      Parameters:
      prefix - the key prefix for extraction
      Returns:
      not null map
      See Also:
    • getConfig

      public final <K extends Config> K getConfig(Class<K> clazz)
      Creates if needed and gets pre parsed and cached configuration. Cache key - the class object of the configuration.
      Parameters:
      clazz - the configuration class.
      Returns:
    • getConfig

      public final Object getConfig(String className)
      Same with getConfig(Class), but with string parameter for calling from scripts. The method is less recommended as getConfig(Class), which is checked by compiler.
      Parameters:
      className - the full class name.
      Returns:
    • removeConfig

      public <K extends Config> void removeConfig(Class<K> clazz)
      Removes config from cache.
      Type Parameters:
      K -
      Parameters:
      clazz -
    • clearConfigs

      protected void clearConfigs()
      Clears all the parsed configurations from configMap.
    • validateConfig

      public final <K extends Config> void validateConfig(Class<K> clazz) throws BGMessageException
      Creates a configuration for validation purposes only..
      Parameters:
      clazz -
      Throws:
      BGMessageException
    • getDataString

      public String getDataString()
      Serializes the data to key=value string lines
      Returns:
      the string with pairs on lines