Class Config

java.lang.Object
com.assemblyrobot.shared.config.Config

public abstract class Config
extends java.lang.Object
Central configuration loader and manager class.
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  Config.UserSetting  
  • Constructor Summary

    Constructors
    Constructor Description
    Config()  
  • Method Summary

    Modifier and Type Method Description
    static Configuration getConfig()
    Returns the configuration as defined in resources/config/config.json, or in an optional custom path if specified by the user.
    static java.lang.String getUserSetting​(Config.UserSetting setting)
    Gets a user setting as a string, or null if not defined.
    static boolean getUserSettingBoolean​(Config.UserSetting setting)
    Gets a user setting as a boolean.
    static boolean hasUserSetting​(Config.UserSetting setting)
    Checks if a user setting exists.
    static void load()
    (Re)loads the configuration file from either the default path (DEFAULT_CONFIG_PATH) or a custom path as specified by the user.
    static void putUserSetting​(Config.UserSetting setting, boolean value)
    Defines a user setting as a boolean value.
    static void putUserSetting​(Config.UserSetting setting, java.lang.String value)
    Defines a user setting as a string value.
    static void removeUserSetting​(Config.UserSetting setting)
    Removes a user setting.
    static void updateConfig​(Configuration newConfig)  

    Methods inherited from class java.lang.Object

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

    • Config

      public Config()
  • Method Details

    • getConfig

      public static Configuration getConfig()
      Returns the configuration as defined in resources/config/config.json, or in an optional custom path if specified by the user.
      Returns:
      Configuration
    • updateConfig

      public static void updateConfig​(Configuration newConfig)
    • load

      public static void load()
      (Re)loads the configuration file from either the default path (DEFAULT_CONFIG_PATH) or a custom path as specified by the user.

      An exception in the loading process of a custom config will cause an all-or-nothing fallback to the default configuration.

    • hasUserSetting

      public static boolean hasUserSetting​(Config.UserSetting setting)
      Checks if a user setting exists.
      Parameters:
      setting - Config.UserSetting
      Returns:
      Boolean indicating whether the setting exists.
    • getUserSetting

      public static java.lang.String getUserSetting​(Config.UserSetting setting)
      Gets a user setting as a string, or null if not defined.
      Parameters:
      setting - Config.UserSetting
      Returns:
      String or null if not found.
    • getUserSettingBoolean

      public static boolean getUserSettingBoolean​(Config.UserSetting setting)
      Gets a user setting as a boolean.

      IMPORTANT: Due to a combinatory poor design choice in the Preferences API and how Java handles primitive types, this method is forced to use a boolean (Not null) as a fallback value for undefined settings. As a result, it uses "false" as the better security choice. Subsequently, it's HIGHLY RECOMMENDED to use hasUserSetting(UserSetting) to check for the existence of any given setting before running this method, in order to avoid unexpected results.

      Parameters:
      setting - Config.UserSetting
      Returns:
      Boolean
    • putUserSetting

      public static void putUserSetting​(Config.UserSetting setting, java.lang.String value)
      Defines a user setting as a string value.
      Parameters:
      setting - Config.UserSetting
      value - String
    • putUserSetting

      public static void putUserSetting​(Config.UserSetting setting, boolean value)
      Defines a user setting as a boolean value.
      Parameters:
      setting - Config.UserSetting
      value - Boolean
    • removeUserSetting

      public static void removeUserSetting​(Config.UserSetting setting)
      Removes a user setting.
      Parameters:
      setting - Config.UserSetting