org.aludratest.config
Class ValidatingPreferencesWrapper

java.lang.Object
  extended by org.aludratest.config.ValidatingPreferencesWrapper
All Implemented Interfaces:
Preferences

public final class ValidatingPreferencesWrapper
extends Object
implements Preferences

Helper class for Preferences consumers which can be used to have getter methods which validate the existence of a configuration property when trying to retrieve it. Clients can wrap an existing Preferences object with this class and use its methods.
Queried child nodes are automatically wrapped and returned as ValidatingPreferencesWrapper.

Author:
falbrech

Constructor Summary
ValidatingPreferencesWrapper(Preferences delegate)
          Creates a new ValidatingPreferencesWrapper object which wraps the given Preferences object.
 
Method Summary
 boolean getBooleanValue(String key)
          Returns the boolean representation of the given configuration key's value.
 boolean getBooleanValue(String key, boolean defaultValue)
          Returns the boolean representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.
 char getCharValue(String key)
          Returns the char representation of the given configuration key's value.
 char getCharValue(String key, char defaultValue)
          Returns the char representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.
 ValidatingPreferencesWrapper getChildNode(String name)
          Returns the configuration child node with the given name, or null if no such node exists on this configuration node.
 String[] getChildNodeNames()
          Returns the names of the available configuration child nodes on this configuration node.
 double getDoubleValue(String key)
          Returns the double representation of the given configuration key's value.
 double getDoubleValue(String key, double defaultValue)
          Returns the double representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.
 float getFloatValue(String key)
          Returns the float representation of the given configuration key's value.
 float getFloatValue(String key, float defaultValue)
          Returns the float representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.
 int getIntValue(String key)
          Returns the int representation of the given configuration key's value.
 int getIntValue(String key, int defaultValue)
          Returns the int representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.
 String[] getKeyNames()
          Returns the available configuration key names on this Preferences node.
 boolean getRequiredBooleanValue(String key)
          Returns the boolean representation of the given configuration key's value.
 char getRequiredCharValue(String key)
          Returns the char representation of the given configuration key's value.
 double getRequiredDoubleValue(String key)
          Returns the double representation of the given configuration key's value.
 float getRequiredFloatValue(String key)
          Returns the float representation of the given configuration key's value.
 int getRequiredIntValue(String key)
          Returns the int representation of the given configuration key's value.
 String getRequiredStringValue(String key)
          Returns the String representation of the given configuration key's value.
 String getStringValue(String key)
          Returns the String representation of the given configuration key's value.
 String getStringValue(String key, String defaultValue)
          Returns the String representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored value is null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValidatingPreferencesWrapper

public ValidatingPreferencesWrapper(Preferences delegate)
Creates a new ValidatingPreferencesWrapper object which wraps the given Preferences object.

Parameters:
delegate - Preferences node to wrap.
Method Detail

getRequiredStringValue

public String getRequiredStringValue(String key)
Returns the String representation of the given configuration key's value. If the configuration key does not exist on this Preferences node, or if its value is null, an AutomationException is thrown.

Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a String.

getRequiredIntValue

public int getRequiredIntValue(String key)
Returns the int representation of the given configuration key's value. If the configuration key does not exist on this Preferences node, or if its stored String value is null, an AutomationException is thrown.

Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as an int.

getRequiredDoubleValue

public double getRequiredDoubleValue(String key)
Returns the double representation of the given configuration key's value. If the configuration key does not exist on this Preferences node, or if its stored String value is null, an AutomationException is thrown.

Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a double.

getRequiredFloatValue

public float getRequiredFloatValue(String key)
Returns the float representation of the given configuration key's value. If the configuration key does not exist on this Preferences node, or if its stored String value is null, an AutomationException is thrown.

Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a float.

getRequiredBooleanValue

public boolean getRequiredBooleanValue(String key)
Returns the boolean representation of the given configuration key's value. If the configuration key does not exist on this Preferences node, or if its stored String value is null, an AutomationException is thrown.

Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a boolean.

getRequiredCharValue

public char getRequiredCharValue(String key)
Returns the char representation of the given configuration key's value. If the configuration key does not exist on this Preferences node, or if its stored String value is null, an AutomationException is thrown.

Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a char.

getStringValue

public String getStringValue(String key)
Description copied from interface: Preferences
Returns the String representation of the given configuration key's value.

Specified by:
getStringValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a String. null is returned if no value is stored.

getIntValue

public int getIntValue(String key)
Description copied from interface: Preferences
Returns the int representation of the given configuration key's value.

Specified by:
getIntValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as an int. 0 is returned if no value is stored, or the stored String is null.

getBooleanValue

public boolean getBooleanValue(String key)
Description copied from interface: Preferences
Returns the boolean representation of the given configuration key's value.

Specified by:
getBooleanValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a boolean. false is returned if no value is stored, or the stored String is null.

getFloatValue

public float getFloatValue(String key)
Description copied from interface: Preferences
Returns the float representation of the given configuration key's value.

Specified by:
getFloatValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a float. 0 is returned if no value is stored, or the stored String is null.

getDoubleValue

public double getDoubleValue(String key)
Description copied from interface: Preferences
Returns the double representation of the given configuration key's value.

Specified by:
getDoubleValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a double. 0 is returned if no value is stored, or the stored String is null.

getCharValue

public char getCharValue(String key)
Description copied from interface: Preferences
Returns the char representation of the given configuration key's value.

Specified by:
getCharValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
Returns:
The value of the configuration key, as a char. '\0' is returned if no value is stored, or the stored String is null. If a longer String is stored, only the first character is returned.

getStringValue

public String getStringValue(String key,
                             String defaultValue)
Description copied from interface: Preferences
Returns the String representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored value is null.

Specified by:
getStringValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
defaultValue - The default value to return if no value is stored for the given configuration key, or the stored value is null.
Returns:
The value of the configuration key, as a String, or the default value.

getIntValue

public int getIntValue(String key,
                       int defaultValue)
Description copied from interface: Preferences
Returns the int representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.

Specified by:
getIntValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
defaultValue - The default value to return if no value is stored for the given configuration key, or if the stored String form of the value is null.
Returns:
The value of the configuration key, as an int, or the default value.

getBooleanValue

public boolean getBooleanValue(String key,
                               boolean defaultValue)
Description copied from interface: Preferences
Returns the boolean representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.

Specified by:
getBooleanValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
defaultValue - The default value to return if no value is stored for the given configuration key, or if the stored String form of the value is null.
Returns:
The value of the configuration key, as a boolean, or the default value.

getFloatValue

public float getFloatValue(String key,
                           float defaultValue)
Description copied from interface: Preferences
Returns the float representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.

Specified by:
getFloatValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
defaultValue - The default value to return if no value is stored for the given configuration key, or if the stored String form of the value is null.
Returns:
The value of the configuration key, as a float, or the default value.

getDoubleValue

public double getDoubleValue(String key,
                             double defaultValue)
Description copied from interface: Preferences
Returns the double representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.

Specified by:
getDoubleValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
defaultValue - The default value to return if no value is stored for the given configuration key, or if the stored String form of the value is null.
Returns:
The value of the configuration key, as a double, or the default value.

getCharValue

public char getCharValue(String key,
                         char defaultValue)
Description copied from interface: Preferences
Returns the char representation of the given configuration key's value, or the given default value when no value is stored for this key, or the stored String form of the value is null.

Specified by:
getCharValue in interface Preferences
Parameters:
key - Configuration key to retrieve the value of.
defaultValue - The default value to return if no value is stored for the given configuration key, or if the stored String form of the value is null.
Returns:
The value of the configuration key, as a char, or the default value.

getKeyNames

public String[] getKeyNames()
Description copied from interface: Preferences
Returns the available configuration key names on this Preferences node.

Specified by:
getKeyNames in interface Preferences
Returns:
The available configuration key names on this Preferences node, possibly an empty array, but never null.

getChildNode

public ValidatingPreferencesWrapper getChildNode(String name)
Description copied from interface: Preferences
Returns the configuration child node with the given name, or null if no such node exists on this configuration node.

Specified by:
getChildNode in interface Preferences
Parameters:
name - Name of the configuration child node
Returns:
The configuration child node with the given name, or null if no such node exists on this configuration node.

getChildNodeNames

public String[] getChildNodeNames()
Description copied from interface: Preferences
Returns the names of the available configuration child nodes on this configuration node.

Specified by:
getChildNodeNames in interface Preferences
Returns:
The names of the available configuration child nodes on this configuration node, possibly an empty Array, but never null.


Copyright © 2015 aludratest.org. All rights reserved.