Class PreferencesUtilities


  • public class PreferencesUtilities
    extends java.lang.Object
    Utilities methods for working with preferences.
    Author:
    Garret Wilson
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static char PATH_SEPARATOR
      The character used to separate elements in preference paths.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static java.lang.String getNodeName​(java.lang.Class<?> c)
      Deterines the absolute path name of the node corresponding to the specified class.
      static java.lang.String getPreferenceName​(java.lang.Class<?> c, java.lang.String name)
      Constructs a name for a preference based upon a given class and preference name, in the form "classname.name".
      static java.util.prefs.Preferences getUserNodeForClass​(java.lang.Class<?> c)
      Returns the preference node from the calling user's preference tree that is associated with this class relative to the package node (i.e.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PATH_SEPARATOR

        protected static final char PATH_SEPARATOR
        The character used to separate elements in preference paths.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PreferencesUtilities

        public PreferencesUtilities()
    • Method Detail

      • getPreferenceName

        public static final java.lang.String getPreferenceName​(java.lang.Class<?> c,
                                                               java.lang.String name)
        Constructs a name for a preference based upon a given class and preference name, in the form "classname.name".
        Parameters:
        c - The class the lowercase local name of which will be used in constructing the name.
        name - The locall name of the preference.
        Returns:
        A name suitable for storing the preference for the class.
      • getUserNodeForClass

        public static java.util.prefs.Preferences getUserNodeForClass​(java.lang.Class<?> c)
        Returns the preference node from the calling user's preference tree that is associated with this class relative to the package node (i.e. packageNode/classNode).
        Parameters:
        c - The class for which a user preference node is desired.
        Returns:
        The user preference node associated with the class.
        Throws:
        java.lang.NullPointerException - if c is null.
        java.lang.SecurityException - if a security manager is present and it denies RuntimePermission("preferences").
        See Also:
        RuntimePermission
      • getNodeName

        protected static java.lang.String getNodeName​(java.lang.Class<?> c)
        Deterines the absolute path name of the node corresponding to the specified class. This is implemented to use the entire class name with every occurence of '.' replaced with '/'. Implemented by consulting java.util.prefs.Preferences.java 1.25 04/06/21 by Josh Bloch.
        Parameters:
        c - The class for which a node name should be returned.
        Returns:
        The absolute path name of the node corresponding to the specified class.
        Throws:
        java.lang.IllegalArgumentException - if the package has no node preferences node associated with it.