Class SimpleConfig

java.lang.Object
eu.bandm.tools.util.SimpleConfig

public class SimpleConfig extends Object
Reads simple "key blank value linefeed" lines and decodes them to configuration parameters. Used for configuration purposes in all those cases when a fully fledged "tdom" etc. would be too heavy weight. This class is intendend to be sub-classed by application specific configuration handlers, which do further parsing on the values and offer them in typed and dedicated getter functions.
  • Field Details

  • Constructor Details

    • SimpleConfig

      public SimpleConfig()
  • Method Details

    • noEntry

      protected IllegalArgumentException noEntry(String key)
    • getObligate

      protected String getObligate(String key) throws IllegalArgumentException
      Throws IOException iff no entry with given key, else returns trimmed value (which may have zero length).
      Throws:
      IllegalArgumentException
    • getWithDefault

      protected String getWithDefault(String key, String def)
      Delivers the default if no entry with the given key.
    • getWithDefault

      protected Integer getWithDefault(String key, int def)
      Delivers the default if no entry with the given key.
    • getWithDefault

      protected Double getWithDefault(String key, double def)
      Delivers the default if no entry with the given key.
    • getNotEmpty

      protected String getNotEmpty(String key)
      Returns trimmed value, iff there is a key, and the value is not empty, else null.
    • getInteger

      protected int getInteger(String key)
      Returns integer value, throws exception if not parsable.
    • getDouble

      protected double getDouble(String key)
      Returns doublce value, throws exception if not parsable.
    • checkNotThere

      protected void checkNotThere(String key)
    • addKeyValuePair

      public void addKeyValuePair(String k, String v)
      For subsequent modification.
    • removeKey

      public void removeKey(String k)
      For subsequent modification.
    • getConfigurationDataFile

      public File getConfigurationDataFile()
    • init

      public void init(File initfile) throws IOException, FileNotFoundException, IllegalArgumentException
      Reads a file with key value pairs line per line and stores key/value pairs into the map keyValue.
      Every read line is first trimmed, see String.trim() and then further analysed as follows:
      1. every empty line or line starting with a hasmark HASH is ignored.
      2. the part of the line up to the first BLANK is taken as key.
      3. the part of the line after the first BLANK (which may be an empty string, or just blanks) is taken as value.