Class RawConfigParser

java.lang.Object
uk.ac.manchester.spinnaker.utils.RawConfigParser

public class RawConfigParser
extends Object
A cut-down limited version of the parser used in Python.
Author:
Donal Fellows
  • Constructor Details

    • RawConfigParser

      protected RawConfigParser​(String delimiters, String comments)
      Create a basic configuration parser.
      Parameters:
      delimiters - the option/value delimiter characters.
      comments - the comment delimiter characters.
    • RawConfigParser

      public RawConfigParser()
      Create a configuration with no values defined in it.
    • RawConfigParser

      public RawConfigParser​(URL resource)
      Create a configuration from the given configuration file. This is designed to be used with Class.getResource(String).
      Parameters:
      resource - The handle to the configuration file.
      Throws:
      RuntimeException - If the file can't be read. (NB: not IOException.)
    • RawConfigParser

      public RawConfigParser​(File file)
      Create a configuration from the given configuration file.
      Parameters:
      file - The handle to the configuration file.
      Throws:
      RuntimeException - If the file can't be read. (NB: not IOException.)
  • Method Details

    • normaliseSectionName

      @ForOverride protected String normaliseSectionName​(String name)
      How to convert a section name into canonical form.
      Parameters:
      name - The raw section name.
      Returns:
      The canonicalised section name.
    • normaliseOptionName

      @ForOverride protected String normaliseOptionName​(String name)
      How to convert an option name into canonical form.
      Parameters:
      name - The raw option name.
      Returns:
      The canonicalised option name.
    • read

      public void read​(URL resource) throws IOException
      Read a configuration file.
      Parameters:
      resource - Where the file is.
      Throws:
      IOException - if the reading fails.
    • read

      public void read​(File file) throws IOException
      Read a configuration file.
      Parameters:
      file - Where the file is.
      Throws:
      IOException - if the reading fails.
    • isNone

      protected boolean isNone​(String value)
      How to decide if a value is to be treated as null.
      Parameters:
      value - The value to examine
      Returns:
      True iff the value is a null-equivalent.
    • getInt

      public Integer getInt​(String section, String option)
      Get a value from the config.
      Parameters:
      section - The section to look in.
      option - The option to look at.
      Returns:
      The option value, or null if it is absent.
    • getBoolean

      public Boolean getBoolean​(String section, String option)
      Get a value from the config.
      Parameters:
      section - The section to look in.
      option - The option to look at.
      Returns:
      The option value, or null if it is absent.
    • get

      public String get​(String section, String option)
      Get a value from the config.
      Parameters:
      section - The section to look in.
      option - The option to look at.
      Returns:
      The option value, or null if it is absent.