Class Config


  • public class Config
    extends java.lang.Object
    This class represents the config parameters. It is a map of key/value pairs.
    • Constructor Summary

      Constructors 
      Constructor Description
      Config()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean getBoolean​(java.lang.String p_key, boolean p_default)
      Gets the boolean corresponding to a key in the config, with default.
      double getDouble​(java.lang.String p_key, double p_default)
      Gets the double corresponding to a key in the config, with default.
      int getInt​(java.lang.String p_key, int p_default)
      Gets the int corresponding to a key in the config, with default.
      protected java.lang.String[] getKeyValuePair​(java.lang.String p_line)
      Splits the input String on an equals (=) character, and returns the two parts as an array of two Strings.
      java.lang.String getString​(java.lang.String p_key, java.lang.String p_default)
      Gets the String corresponding to a key in the config, with default.
      java.lang.Object getValue​(java.lang.String p_key)
      Gets the value corresponding to a key in the config.
      java.lang.Object getValue​(java.lang.String p_key, java.lang.Object p_default)
      Gets the value corresponding to a key in the config, with default.
      protected void load​(java.io.BufferedReader p_reader)
      Load in a config from file.
      protected java.lang.Boolean parseBoolean​(java.lang.String p_valueStr)
      Converts a String containing a boolean to a Boolean.
      protected java.lang.Double parseDouble​(java.lang.String p_valueStr)
      Converts a String containing a double to a Double.
      protected java.lang.Integer parseInt​(java.lang.String p_valueStr)
      Converts a String containing a int to a Int.
      protected java.lang.Object parseValue​(java.lang.String p_valueStr)
      Parses the value from a String.
      int size()
      Returns the size of the total config map.
      protected java.lang.String stripComments​(java.lang.String p_line)
      Removes any part of a line following a hash character - '#'.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Config

        public Config()
    • Method Detail

      • load

        protected void load​(java.io.BufferedReader p_reader)
        Load in a config from file.
        Parameters:
        p_reader - BufferedReader on a config file.
      • stripComments

        protected java.lang.String stripComments​(java.lang.String p_line)
        Removes any part of a line following a hash character - '#'. Returns any part of the line that comes before that character, which will be an empty string if the line starts with a '#'. If a null string is passed in, a NullPointerException is thrown. The String is trimmed before being returned to remove any whitespace on either end.
        Parameters:
        p_line - a String representing a line of text
        Returns:
        the String, minus any present # character, and any characters that follow it, if any. May return an empty String, but will never return null.
        Throws:
        java.lang.NullPointerException - True if the input String is null.
      • getKeyValuePair

        protected java.lang.String[] getKeyValuePair​(java.lang.String p_line)
        Splits the input String on an equals (=) character, and returns the two parts as an array of two Strings.
        Parameters:
        p_line - String containing an '='.
        Returns:
        Array of p_line split by '='.
        Throws:
        java.lang.NullPointerException - True if the String passed in is null.
      • parseValue

        protected java.lang.Object parseValue​(java.lang.String p_valueStr)
        Parses the value from a String. It attempts to parse it into a primitive type, returns as its wrapper class. The order it attempts is: double, int, boolean, String.
        Parameters:
        p_valueStr - String containing a value.
        Returns:
        Value as type object.
      • parseDouble

        protected java.lang.Double parseDouble​(java.lang.String p_valueStr)
        Converts a String containing a double to a Double.
        Parameters:
        p_valueStr - String representation of a double.
        Returns:
        Parsed Double or null if not a double.
      • parseInt

        protected java.lang.Integer parseInt​(java.lang.String p_valueStr)
        Converts a String containing a int to a Int.
        Parameters:
        p_valueStr - String representation of a int.
        Returns:
        Parsed Int or null if not a int.
      • parseBoolean

        protected java.lang.Boolean parseBoolean​(java.lang.String p_valueStr)
        Converts a String containing a boolean to a Boolean.
        Parameters:
        p_valueStr - String representation of a boolean.
        Returns:
        Parsed Boolean or null if not a boolean.
      • getValue

        public java.lang.Object getValue​(java.lang.String p_key)
        Gets the value corresponding to a key in the config.
        Parameters:
        p_key - Key to find corresponding value to.
        Returns:
        Value corresponding to key.
      • getValue

        public java.lang.Object getValue​(java.lang.String p_key,
                                         java.lang.Object p_default)
        Gets the value corresponding to a key in the config, with default.
        Parameters:
        p_key - Key to find corresponding value to.
        p_default - Default value if p_key doesn't exist.
        Returns:
        Value corresponding to key, or default value.
      • getDouble

        public double getDouble​(java.lang.String p_key,
                                double p_default)
        Gets the double corresponding to a key in the config, with default.
        Parameters:
        p_key - Key to find corresponding double to.
        p_default - Default double if p_key doesn't exist.
        Returns:
        double corresponding to key, or default double.
      • getInt

        public int getInt​(java.lang.String p_key,
                          int p_default)
        Gets the int corresponding to a key in the config, with default.
        Parameters:
        p_key - Key to find corresponding int to.
        p_default - Default int if p_key doesn't exist.
        Returns:
        int corresponding to key, or default int.
      • getBoolean

        public boolean getBoolean​(java.lang.String p_key,
                                  boolean p_default)
        Gets the boolean corresponding to a key in the config, with default.
        Parameters:
        p_key - Key to find corresponding boolean to.
        p_default - Default boolean if p_key doesn't exist.
        Returns:
        boolean corresponding to key, or default boolean.
      • getString

        public java.lang.String getString​(java.lang.String p_key,
                                          java.lang.String p_default)
        Gets the String corresponding to a key in the config, with default.
        Parameters:
        p_key - Key to find corresponding String to.
        p_default - Default String if p_key doesn't exist.
        Returns:
        String corresponding to key, or default String.
      • size

        public int size()
        Returns the size of the total config map.
        Returns:
        Size of config map.