com.evanmclean.evlib.prefs
Class Prefs

java.lang.Object
  extended by com.evanmclean.evlib.prefs.Prefs

public final class Prefs
extends Object

Quick utilities for preferences (java.util.prefs.Preferences).

Author:
Evan McLean McLean Computer Services (see the overview for copyright and licensing.)

Method Summary
static File getFolder(Preferences pref, String key, File def)
          Gets an existing folder from the specified preference.
static boolean putFolder(Preferences pref, String key, File file)
          Save the part of the specified file path that represents an existing folder.
static boolean sync(Preferences pref)
          Performs the synchronisation and catches any backing store exceptions.
static Preferences systemNodeForClass(Class<?> cls)
          Returns a system node specific to the class, rather then at the package level.
static Preferences userNodeForClass(Class<?> cls)
          Returns a user node specific to the class, rather then at the package level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFolder

public static File getFolder(Preferences pref,
                             String key,
                             File def)
Gets an existing folder from the specified preference. If the preference points to a path that does not exist, or is a file and not a folder, it will try getting the first parent folder that does exist.

Parameters:
pref - The preference object.
key - Key for the preference.
def - Default to return if existing folder could not be found (null is okay).
Returns:
The existing folder, or the default.

putFolder

public static boolean putFolder(Preferences pref,
                                String key,
                                File file)
Save the part of the specified file path that represents an existing folder. If the specified file points to a path that does not exist, or is a file and not a folder, it will try getting the first parent folder that does exist.

Parameters:
pref - The preference object.
key - Key for the preference.
file - The path (or part there of) to save.
Returns:
True if it could find an existing folder to save.

sync

public static boolean sync(Preferences pref)
Performs the synchronisation and catches any backing store exceptions.

Parameters:
pref - The preference to sync.
Returns:
True if synced okay, false if there was a backing store exception.

systemNodeForClass

public static Preferences systemNodeForClass(Class<?> cls)
Returns a system node specific to the class, rather then at the package level.

Parameters:
cls - The class to get a node for.
Returns:
The class level node.

userNodeForClass

public static Preferences userNodeForClass(Class<?> cls)
Returns a user node specific to the class, rather then at the package level.

Parameters:
cls - The class to get a node for.
Returns:
The class level node.