Class Config

java.lang.Object
org.wildstang.framework.config.Config

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

    • Config

      public Config()
  • Method Details

    • load

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

      protected String stripComments(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:
      NullPointerException - True if the input String is null.
    • getKeyValuePair

      protected String[] getKeyValuePair(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:
      NullPointerException - True if the String passed in is null.
    • parseValue

      protected Object parseValue(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 Double parseDouble(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 Integer parseInt(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 Boolean parseBoolean(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 Object getValue(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 Object getValue(String p_key, 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(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(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(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 String getString(String p_key, 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.