com.javadocking.util
Class PropertiesUtil

java.lang.Object
  extended by com.javadocking.util.PropertiesUtil

public class PropertiesUtil
extends java.lang.Object

This class contains a collection of static utility methods for creating, retrieving, saving and loading properties.

Author:
Heidi Rakels.

Field Summary
static java.lang.String FALSE
          The string representation for the boolean FALSE value.
static java.lang.String TRUE
          The string representation for the boolean TRUE value.
 
Method Summary
static boolean getBoolean(java.util.Properties properties, java.lang.String name, boolean defaultValue)
          Gets the boolean property with the given name.
static java.awt.Color getColor(java.util.Properties properties, java.lang.String name, java.awt.Color defaultValue)
          Gets the color property with the given name.
static double getDouble(java.util.Properties properties, java.lang.String name, double defaultValue)
          Gets the double property with the given name.
static double[] getDoubleArray(java.util.Properties properties, java.lang.String name, double[] defaultValue)
          Gets the double array property with the given name.
static int getInteger(java.util.Properties properties, java.lang.String name, int defaultValue)
          Gets the integer property with the given name.
static int[] getIntegerArray(java.util.Properties properties, java.lang.String name, int[] defaultValue)
          Gets the integer array property with the given name.
static java.lang.String getString(java.util.Properties properties, java.lang.String name, java.lang.String defaultValue)
          Gets the string property with the given name.
static java.lang.String[] getStringArray(java.util.Properties properties, java.lang.String name, java.lang.String[] defaultValue)
          Gets the string array property with the given name.
static java.util.Properties loadProperties(java.lang.String sourceName)
          Reads the file with the given name into a java.util.Properties object.
static void saveProperties(java.util.Properties properties, java.lang.String destinationName, java.lang.String comment)
          Saves the given java.util.Properties object in a destination file with the given name.
static void setBoolean(java.util.Properties properties, java.lang.String name, boolean value)
          Adds the boolean property with the given name and value to the given properties.
static void setColor(java.util.Properties properties, java.lang.String name, java.awt.Color value)
          Adds the color property with the given name and value to the given properties.
static void setDouble(java.util.Properties properties, java.lang.String name, double value)
          Adds the double property with the given name and value to the given properties.
static void setDoubleArray(java.util.Properties properties, java.lang.String name, double[] value)
          Adds the double array property with the given name and value to the given properties.
static void setInteger(java.util.Properties properties, java.lang.String name, int value)
          Adds the integer property with the given name and value to the given properties.
static void setIntegerArray(java.util.Properties properties, java.lang.String name, int[] value)
          Adds the integer array property with the given name and value to the given properties.
static void setString(java.util.Properties properties, java.lang.String name, java.lang.String value)
          Adds the string property with the given name and value to the given properties.
static void setStringArray(java.util.Properties properties, java.lang.String name, java.lang.String[] value)
          Adds the string array property with the given name and value to the given properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRUE

public static final java.lang.String TRUE
The string representation for the boolean TRUE value.

See Also:
Constant Field Values

FALSE

public static final java.lang.String FALSE
The string representation for the boolean FALSE value.

See Also:
Constant Field Values
Method Detail

loadProperties

public static java.util.Properties loadProperties(java.lang.String sourceName)
                                           throws java.io.IOException
Reads the file with the given name into a java.util.Properties object.

Parameters:
sourceName - The name of the source file for the properties.
Returns:
The properties that are retrieved from the source file.
Throws:
java.io.IOException - If creating the input stream, reading the property list from the input stream or closing the input stream throws an IOException.

saveProperties

public static void saveProperties(java.util.Properties properties,
                                  java.lang.String destinationName,
                                  java.lang.String comment)
                           throws java.io.IOException
Saves the given java.util.Properties object in a destination file with the given name.

Parameters:
properties - The properties that have to be saved in the destination file.
destinationName - The name of the destination file for the properties.
comment - The saved file will start with the given text as comment.
Throws:
java.lang.NullPointerException - If the given properties are null.
java.io.IOException - If creating the output stream, writing this property list to the output stream or closing the output stream throws an IOException.

getBoolean

public static boolean getBoolean(java.util.Properties properties,
                                 java.lang.String name,
                                 boolean defaultValue)
Gets the boolean property with the given name. If the property is not found, the default value is returned.

Parameters:
properties - The given properties where the property is searched.
name - The name of the property.
defaultValue - The default value of the property.
Returns:
The boolean property with the given name. If the property is not found, the default value is returned.

setBoolean

public static void setBoolean(java.util.Properties properties,
                              java.lang.String name,
                              boolean value)
Adds the boolean property with the given name and value to the given properties.

Parameters:
properties - The given properties to which the property is added.
name - The name of the property.
value - The default value of the property.

getString

public static java.lang.String getString(java.util.Properties properties,
                                         java.lang.String name,
                                         java.lang.String defaultValue)
Gets the string property with the given name. If the property is not found, the default value is returned.

Parameters:
properties - The given properties where the property is searched.
name - The name of the property.
defaultValue - The default value of the property.
Returns:
The string property with the given name. If the property is not found, the default value is returned.

setString

public static void setString(java.util.Properties properties,
                             java.lang.String name,
                             java.lang.String value)
Adds the string property with the given name and value to the given properties.

Parameters:
properties - The given properties to which the property is added.
name - The name of the property.
value - The default value of the property.

getInteger

public static int getInteger(java.util.Properties properties,
                             java.lang.String name,
                             int defaultValue)
Gets the integer property with the given name. If the property is not found, the default value is returned.

Parameters:
properties - The given properties where the property is searched.
name - The name of the property.
defaultValue - The default value of the property.
Returns:
The integer property with the given name. If the property is not found, the default value is returned.

setInteger

public static void setInteger(java.util.Properties properties,
                              java.lang.String name,
                              int value)
Adds the integer property with the given name and value to the given properties.

Parameters:
properties - The given properties to which the property is added.
name - The name of the property.
value - The default value of the property.

getDouble

public static double getDouble(java.util.Properties properties,
                               java.lang.String name,
                               double defaultValue)
Gets the double property with the given name. If the property is not found, the default value is returned.

Parameters:
properties - The given properties where the property is searched.
name - The name of the property.
defaultValue - The default value of the property.
Returns:
The double property with the given name. If the property is not found, the default value is returned.

setDouble

public static void setDouble(java.util.Properties properties,
                             java.lang.String name,
                             double value)
Adds the double property with the given name and value to the given properties.

Parameters:
properties - The given properties to which the property is added.
name - The name of the property.
value - The default value of the property.

getColor

public static java.awt.Color getColor(java.util.Properties properties,
                                      java.lang.String name,
                                      java.awt.Color defaultValue)
Gets the color property with the given name. If the property is not found, the default value is returned.

Parameters:
properties - The given properties where the property is searched.
name - The name of the property.
defaultValue - The default value of the property.
Returns:
The color property with the given name. If the property is not found, the default value is returned.

setColor

public static void setColor(java.util.Properties properties,
                            java.lang.String name,
                            java.awt.Color value)
Adds the color property with the given name and value to the given properties.

Parameters:
properties - The given properties to which the property is added.
name - The name of the property.
value - The default value of the property.

getStringArray

public static java.lang.String[] getStringArray(java.util.Properties properties,
                                                java.lang.String name,
                                                java.lang.String[] defaultValue)
Gets the string array property with the given name. If the property is not found, the default value is returned.

Parameters:
properties - The given properties where the property is searched.
name - The name of the property.
defaultValue - The default value of the property.
Returns:
The string array property with the given name. If the property is not found, the default value is returned.

setStringArray

public static void setStringArray(java.util.Properties properties,
                                  java.lang.String name,
                                  java.lang.String[] value)
Adds the string array property with the given name and value to the given properties.

Parameters:
properties - The given properties to which the property is added.
name - The name of the property.
value - The default value of the property.

getIntegerArray

public static int[] getIntegerArray(java.util.Properties properties,
                                    java.lang.String name,
                                    int[] defaultValue)
Gets the integer array property with the given name. If the property is not found, the default value is returned.

Parameters:
properties - The given properties where the property is searched.
name - The name of the property.
defaultValue - The default value of the property.
Returns:
The integer array property with the given name. If the property is not found, the default value is returned.

setIntegerArray

public static void setIntegerArray(java.util.Properties properties,
                                   java.lang.String name,
                                   int[] value)
Adds the integer array property with the given name and value to the given properties.

Parameters:
properties - The given properties to which the property is added.
name - The name of the property.
value - The default value of the property.

getDoubleArray

public static double[] getDoubleArray(java.util.Properties properties,
                                      java.lang.String name,
                                      double[] defaultValue)
Gets the double array property with the given name. If the property is not found, the default value is returned.

Parameters:
properties - The given properties where the property is searched.
name - The name of the property.
defaultValue - The default value of the property.
Returns:
The double array property with the given name. If the property is not found, the default value is returned.

setDoubleArray

public static void setDoubleArray(java.util.Properties properties,
                                  java.lang.String name,
                                  double[] value)
Adds the double array property with the given name and value to the given properties.

Parameters:
properties - The given properties to which the property is added.
name - The name of the property.
value - The default value of the property.