Class UserPreferences

java.lang.Object
is.codion.common.model.preferences.UserPreferences

public final class UserPreferences extends Object
A utility class for working with user preferences
  • Method Details

    • get

      public static @Nullable String get(String key)
      Parameters:
      key - the key identifying the preference
      Returns:
      the user preference associated with the given key
    • get

      public static String get(String key, String defaultValue)
      Parameters:
      key - the key identifying the preference
      defaultValue - the default value if no preference is available
      Returns:
      the user preference associated with the given key
      Throws:
      NullPointerException - in case defaultValue is null
    • set

      public static void set(String key, String value)
      Parameters:
      key - the key to use to identify the preference
      value - the preference value to associate with the given key
    • remove

      public static void remove(String key)
      Removes the preference associated with the given key
      Parameters:
      key - the key to use to identify the preference to remove
    • flush

      public static void flush() throws BackingStoreException
      Flushes the preferences to disk, including all file based preferences initialized via file(String).
      Throws:
      BackingStoreException - in case of a backing store failure
    • file

      public static Preferences file(String filename)
      Parameters:
      filename - the preferences filename
      Returns:
      a file based Preferences instance using the given filename
    • delete

      public static void delete(String filename) throws IOException
      Deletes the preferences file with the given name.
      Parameters:
      filename - the name of the preferences file to delete
      Throws:
      IOException - in case of an exception
      IllegalArgumentException - in case the given preferences file does not exist