Class Settings

java.lang.Object
fi.utu.vbingm.thesis.Settings

public class Settings extends Object
Loads application settings.

On first run the bundled defaults.properties resource (from src/main/resources/) is copied to ~/.mavenproject/settings.properties. On subsequent runs the user's copy is read instead, so any edits the user makes there are preserved.

The constructor accepting a Path makes this class easy to test — tests can pass a temporary directory instead of the real home folder.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a Settings instance using the default config directory (~/.mavenproject/).
    Settings(Path configDir)
    Creates a Settings instance that stores user config in the given directory.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(String key)
    Returns the value of a setting, or null if not found.
    Returns the path to the config directory.
    void
    Ensures the config directory and settings file exist (copying bundled defaults if needed), then loads the properties into memory.

    Methods inherited from class java.lang.Object

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

    • Settings

      public Settings(Path configDir)
      Creates a Settings instance that stores user config in the given directory.
      Parameters:
      configDir - directory where the user's settings file is kept
    • Settings

      public Settings()
      Creates a Settings instance using the default config directory (~/.mavenproject/).
  • Method Details

    • load

      public void load() throws IOException
      Ensures the config directory and settings file exist (copying bundled defaults if needed), then loads the properties into memory.
      Throws:
      IOException - if an I/O error occurs
    • get

      public String get(String key)
      Returns the value of a setting, or null if not found.
      Parameters:
      key - the property key
      Returns:
      the value, or null
    • getConfigDir

      public Path getConfigDir()
      Returns the path to the config directory.
      Returns:
      config directory path