org.base.apps.beans.prefs
Class BasePreferences

java.lang.Object
  extended by java.util.prefs.Preferences
      extended by org.base.apps.beans.prefs.BasePreferences

public class BasePreferences
extends Preferences

Extends Preferences to provide utility methods and key tracking.

Author:
Kevan Simpson

Field Summary
static String STRING_ARRAY_DELIMITER
           
 
Fields inherited from class java.util.prefs.Preferences
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH
 
Constructor Summary
BasePreferences(Preferences delegate)
           
 
Method Summary
 String absolutePath()
           
 void addNodeChangeListener(NodeChangeListener ncl)
           
 void addPreferenceChangeListener(PreferenceChangeListener pcl)
           
 String[] childrenNames()
           
 void clear()
           
 boolean equals(Object obj)
           
 void exportNode(OutputStream os)
           
 void exportSubtree(OutputStream os)
           
 void flush()
           
 String get(String key, String def)
           
 String[] getArray(String key, String... def)
          Returns the array associated with the specified key in this preference node.
 boolean getBoolean(String key, boolean def)
           
 byte[] getByteArray(String key, byte[] def)
           
 Collection<String> getCollection(String key, Collection<String> def)
          Returns the Collection associated with the specified key in this preference node.
protected  Preferences getDelegate()
           
 double getDouble(String key, double def)
           
 float getFloat(String key, float def)
           
 int getInt(String key, int def)
           
 long getLong(String key, long def)
           
 Map<String,String> getMap(String key, Map<String,String> def)
          Returns the Map associated with the specified key in this preference node.
 Class<?> getType(String key, Class<?> def)
          Returns the class associated with the specified key in this preference node.
 int hashCode()
           
 boolean isUserNode()
           
 String[] keys()
           
 String name()
           
 BasePreferences node(String pathName)
          Returns a BasePreferences instance of this node's child.
 boolean nodeExists(String pathName)
           
 BasePreferences parent()
          Returns a BasePreferences instance of this node's parent.
 void put(String key, String value)
           
 void putArray(String key, String[] value)
          Associates the array associated with the specified key in this preference node.
 void putBoolean(String key, boolean value)
           
 void putByteArray(String key, byte[] value)
           
 void putCollection(String key, Collection<String> value)
          Associates the Collection associated with the specified key in this preference node.
 void putDouble(String key, double value)
           
 void putFloat(String key, float value)
           
 void putInt(String key, int value)
           
 void putLong(String key, long value)
           
 void putMap(String key, Map<String,String> value)
          Associates the map associated with the specified key in this preference node.
 void putType(String key, Class<?> type)
          Associates the class associated with the specified key in this preference node.
 void remove(String key)
           
 void removeNode()
           
 void removeNodeChangeListener(NodeChangeListener ncl)
           
 void removePreferenceChangeListener(PreferenceChangeListener pcl)
           
protected  void setDelegate(Preferences delegate)
           
 void sync()
           
 String toString()
           
 
Methods inherited from class java.util.prefs.Preferences
importPreferences, systemNodeForPackage, systemRoot, userNodeForPackage, userRoot
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STRING_ARRAY_DELIMITER

public static String STRING_ARRAY_DELIMITER
Constructor Detail

BasePreferences

public BasePreferences(Preferences delegate)
Method Detail

putArray

public void putArray(String key,
                     String[] value)
Associates the array associated with the specified key in this preference node.

Parameters:
key - The specified key.
value - The given array.

getArray

public String[] getArray(String key,
                         String... def)
Returns the array associated with the specified key in this preference node.

Parameters:
key - The specified key.
def - The value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as an array, or the backing store is inaccessible.
Returns:
the array associated with the specified key or the default value.

putCollection

public void putCollection(String key,
                          Collection<String> value)
Associates the Collection associated with the specified key in this preference node.

Parameters:
key - The specified key.
value - The given Collection.

getCollection

public Collection<String> getCollection(String key,
                                        Collection<String> def)
Returns the Collection associated with the specified key in this preference node.

Parameters:
key - The specified key.
def - The value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as a Collection, or the backing store is inaccessible.
Returns:
the Collection associated with the specified key or the default value.

putMap

public void putMap(String key,
                   Map<String,String> value)
Associates the map associated with the specified key in this preference node.

Parameters:
key - The specified key.
value - The given map.

getMap

public Map<String,String> getMap(String key,
                                 Map<String,String> def)
Returns the Map associated with the specified key in this preference node.

Parameters:
key - The specified key.
def - The value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as a Map, or the backing store is inaccessible.
Returns:
the map associated with the specified key or the default value.

putType

public void putType(String key,
                    Class<?> type)
Associates the class associated with the specified key in this preference node.

Parameters:
key - The specified key.
type - The given class.

getType

public Class<?> getType(String key,
                        Class<?> def)
Returns the class associated with the specified key in this preference node.

Parameters:
key - The specified key.
def - The value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as a class, or the backing store is inaccessible.
Returns:
the class associated with the specified key or the default value.

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

put

public void put(String key,
                String value)
Specified by:
put in class Preferences
See Also:
Preferences.put(java.lang.String, java.lang.String)

get

public String get(String key,
                  String def)
Specified by:
get in class Preferences
See Also:
Preferences.get(java.lang.String, java.lang.String)

remove

public void remove(String key)
Specified by:
remove in class Preferences
See Also:
Preferences.remove(java.lang.String)

clear

public void clear()
           throws BackingStoreException
Specified by:
clear in class Preferences
Throws:
BackingStoreException
See Also:
Preferences.clear()

putInt

public void putInt(String key,
                   int value)
Specified by:
putInt in class Preferences
See Also:
Preferences.putInt(java.lang.String, int)

getInt

public int getInt(String key,
                  int def)
Specified by:
getInt in class Preferences
See Also:
Preferences.getInt(java.lang.String, int)

putLong

public void putLong(String key,
                    long value)
Specified by:
putLong in class Preferences
See Also:
Preferences.putLong(java.lang.String, long)

getLong

public long getLong(String key,
                    long def)
Specified by:
getLong in class Preferences
See Also:
Preferences.getLong(java.lang.String, long)

putBoolean

public void putBoolean(String key,
                       boolean value)
Specified by:
putBoolean in class Preferences
See Also:
Preferences.putBoolean(java.lang.String, boolean)

getBoolean

public boolean getBoolean(String key,
                          boolean def)
Specified by:
getBoolean in class Preferences
See Also:
Preferences.getBoolean(java.lang.String, boolean)

putFloat

public void putFloat(String key,
                     float value)
Specified by:
putFloat in class Preferences
See Also:
Preferences.putFloat(java.lang.String, float)

getFloat

public float getFloat(String key,
                      float def)
Specified by:
getFloat in class Preferences
See Also:
Preferences.getFloat(java.lang.String, float)

putDouble

public void putDouble(String key,
                      double value)
Specified by:
putDouble in class Preferences
See Also:
Preferences.putDouble(java.lang.String, double)

getDouble

public double getDouble(String key,
                        double def)
Specified by:
getDouble in class Preferences
See Also:
Preferences.getDouble(java.lang.String, double)

putByteArray

public void putByteArray(String key,
                         byte[] value)
Specified by:
putByteArray in class Preferences
See Also:
Preferences.putByteArray(java.lang.String, byte[])

getByteArray

public byte[] getByteArray(String key,
                           byte[] def)
Specified by:
getByteArray in class Preferences
See Also:
Preferences.getByteArray(java.lang.String, byte[])

keys

public String[] keys()
              throws BackingStoreException
Specified by:
keys in class Preferences
Throws:
BackingStoreException
See Also:
Preferences.keys()

childrenNames

public String[] childrenNames()
                       throws BackingStoreException
Specified by:
childrenNames in class Preferences
Throws:
BackingStoreException
See Also:
Preferences.childrenNames()

parent

public BasePreferences parent()
Returns a BasePreferences instance of this node's parent.

Specified by:
parent in class Preferences
Returns:
a BasePreferences instance of this node's parent.
See Also:
Preferences.parent()

node

public BasePreferences node(String pathName)
Returns a BasePreferences instance of this node's child.

Specified by:
node in class Preferences
Parameters:
pathName - The child's path.
Returns:
a BasePreferences instance of this node's child.
See Also:
Preferences.node(java.lang.String)

nodeExists

public boolean nodeExists(String pathName)
                   throws BackingStoreException
Specified by:
nodeExists in class Preferences
Throws:
BackingStoreException
See Also:
Preferences.nodeExists(java.lang.String)

removeNode

public void removeNode()
                throws BackingStoreException
Specified by:
removeNode in class Preferences
Throws:
BackingStoreException
See Also:
Preferences.removeNode()

name

public String name()
Specified by:
name in class Preferences
See Also:
Preferences.name()

absolutePath

public String absolutePath()
Specified by:
absolutePath in class Preferences
See Also:
Preferences.absolutePath()

isUserNode

public boolean isUserNode()
Specified by:
isUserNode in class Preferences
See Also:
Preferences.isUserNode()

toString

public String toString()
Specified by:
toString in class Preferences
See Also:
Preferences.toString()

flush

public void flush()
           throws BackingStoreException
Specified by:
flush in class Preferences
Throws:
BackingStoreException
See Also:
Preferences.flush()

sync

public void sync()
          throws BackingStoreException
Specified by:
sync in class Preferences
Throws:
BackingStoreException
See Also:
Preferences.sync()

addPreferenceChangeListener

public void addPreferenceChangeListener(PreferenceChangeListener pcl)
Specified by:
addPreferenceChangeListener in class Preferences
See Also:
Preferences.addPreferenceChangeListener(java.util.prefs.PreferenceChangeListener)

removePreferenceChangeListener

public void removePreferenceChangeListener(PreferenceChangeListener pcl)
Specified by:
removePreferenceChangeListener in class Preferences
See Also:
Preferences.removePreferenceChangeListener(java.util.prefs.PreferenceChangeListener)

addNodeChangeListener

public void addNodeChangeListener(NodeChangeListener ncl)
Specified by:
addNodeChangeListener in class Preferences
See Also:
Preferences.addNodeChangeListener(java.util.prefs.NodeChangeListener)

removeNodeChangeListener

public void removeNodeChangeListener(NodeChangeListener ncl)
Specified by:
removeNodeChangeListener in class Preferences
See Also:
Preferences.removeNodeChangeListener(java.util.prefs.NodeChangeListener)

exportNode

public void exportNode(OutputStream os)
                throws IOException,
                       BackingStoreException
Specified by:
exportNode in class Preferences
Throws:
IOException
BackingStoreException
See Also:
Preferences.exportNode(java.io.OutputStream)

exportSubtree

public void exportSubtree(OutputStream os)
                   throws IOException,
                          BackingStoreException
Specified by:
exportSubtree in class Preferences
Throws:
IOException
BackingStoreException
See Also:
Preferences.exportSubtree(java.io.OutputStream)

getDelegate

protected Preferences getDelegate()
Returns:
the delegate

setDelegate

protected void setDelegate(Preferences delegate)
Parameters:
delegate - the delegate to set

Please visit Base Apps, hosted on Sourceforge.net.

Copyright 2011, Blue Agate Software Entity (BASE)