edu.toronto.psi.vincent.util
Class EasyProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by edu.toronto.psi.vincent.util.EasyProperties
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>

public class EasyProperties
extends java.util.Properties

Wrapper for the Properties class to make reading data from and writing data to a properties file easier. In particular, numbers and arrays can be parsed from and written to a properties file.

 Copyright (C) 2005  Vincent Cheung (vincent@psi.toronto.edu, http://www.psi.toronto.edu/~vincent/)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

Version:
1.3 12/02/05
Author:
Vincent Cheung
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
EasyProperties()
          Creates an empty property list with no default values.
EasyProperties(java.util.Properties defaults)
          Creates an empty property list with the specified defaults.
EasyProperties(java.lang.String filename)
          Creates a property list from the specified properties file.
 
Method Summary
 double[][] get2DDoubleArrayProperty(java.lang.String key)
          Returns the property as a two-dimensional double array.
 double[][] get2DDoubleArrayProperty(java.lang.String key, double[][] defaultValue)
          Returns the property as a two-dimensional double array.
 int[][] get2DIntArrayProperty(java.lang.String key)
          Returns the property as a two-dimensional integer array.
 int[][] get2DIntArrayProperty(java.lang.String key, int[][] defaultValue)
          Returns the property as a two-dimensional integer array.
 double[][][] get3DDoubleArrayProperty(java.lang.String key)
          Returns the property as a three-dimensional double array.
 double[][][] get3DDoubleArrayProperty(java.lang.String key, double[][][] defaultValue)
          Returns the property as a three-dimensional double array.
 int[][][] get3DIntArrayProperty(java.lang.String key)
          Returns the property as a three-dimensional integer array.
 int[][][] get3DIntArrayProperty(java.lang.String key, int[][][] defaultValue)
          Returns the property as a three-dimensional integer array.
 boolean getBooleanProperty(java.lang.String key)
          Returns the property as a boolean (property is true if != "0" or == "true").
 boolean getBooleanProperty(java.lang.String key, boolean defaultValue)
          Returns the property as a boolean (property is true if != "0" or == "true").
 double[] getDoubleArrayProperty(java.lang.String key)
          Returns the property as a double array.
 double[] getDoubleArrayProperty(java.lang.String key, double[] defaultValue)
          Returns the property as a double array.
 double getDoubleProperty(java.lang.String key)
          Returns the property as a double.
 double getDoubleProperty(java.lang.String key, double defaultValue)
          Returns the property as a double.
 int[] getIntArrayProperty(java.lang.String key)
          Returns the property as an integer array.
 int[] getIntArrayProperty(java.lang.String key, int[] defaultValue)
          Returns the property as an integer array.
 int getIntProperty(java.lang.String key)
          Returns the property as an integer.
 int getIntProperty(java.lang.String key, int defaultValue)
          Returns the property as an integer.
 java.lang.String[] getStringArrayProperty(java.lang.String key)
          Returns the property as a string array.
 java.lang.String[] getStringArrayProperty(java.lang.String key, java.lang.String[] defaultValue)
          Returns the property as a string array.
 void list()
          Prints this property list to the default output stream (System.out).
 void load(java.lang.String filename)
          Load the properties file.
 double[][] parse2DDoubleArray(java.lang.String s)
          Parses a comma delimited string to a two-dimensional double array.
 int[][] parse2DIntArray(java.lang.String s)
          Parses a comma delimited string to a two-dimensional integer array.
 double[][][] parse3DDoubleArray(java.lang.String s)
          Parses a comma delimited string to a three-dimensional double array.
 int[][][] parse3DIntArray(java.lang.String s)
          Parses a comma delimited string to a three-dimensional integer array.
 double[] parseDoubleArray(java.lang.String s)
          Parses a comma delimited string to a double array.
 int[] parseIntArray(java.lang.String s)
          Parses a comma delimited string to an integer array.
 java.lang.String[] parseStringArray(java.lang.String s)
          Parses a ", " delimited string to a string array.
 java.lang.Object setProperty(java.lang.String key, boolean value)
          Calls the Hashtable method put.
 java.lang.Object setProperty(java.lang.String key, double value)
          Calls the Hashtable method put.
 java.lang.Object setProperty(java.lang.String key, double[] value)
          Calls the Hashtable method put.
 java.lang.Object setProperty(java.lang.String key, double[][] value)
          Calls the Hashtable method put.
 java.lang.Object setProperty(java.lang.String key, double[][][] value)
          Calls the Hashtable method put.
 java.lang.Object setProperty(java.lang.String key, int value)
          Calls the Hashtable method put.
 java.lang.Object setProperty(java.lang.String key, int[] value)
          Calls the Hashtable method put.
 java.lang.Object setProperty(java.lang.String key, int[][] value)
          Calls the Hashtable method put.
 java.lang.Object setProperty(java.lang.String key, int[][][] value)
          Calls the Hashtable method put.
 java.lang.Object setProperty(java.lang.String key, java.lang.String[] value)
          Calls the Hashtable method put.
 void store(java.lang.String filename, java.lang.String header)
          Writes this property list (key and element pairs) in this Properties table to a file in a format suitable for loading into a Properties table using the load method.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, loadFromXML, propertyNames, save, setProperty, store, storeToXML, storeToXML
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EasyProperties

public EasyProperties()
Creates an empty property list with no default values.


EasyProperties

public EasyProperties(java.util.Properties defaults)
Creates an empty property list with the specified defaults.

Parameters:
defaults - the defaults.

EasyProperties

public EasyProperties(java.lang.String filename)
Creates a property list from the specified properties file.

Parameters:
filename - the name of the properties file.
Method Detail

load

public void load(java.lang.String filename)
Load the properties file.

Parameters:
filename - the name of the properties file.

store

public void store(java.lang.String filename,
                  java.lang.String header)
Writes this property list (key and element pairs) in this Properties table to a file in a format suitable for loading into a Properties table using the load method. If the file already exists, it will be overwritten. If the header argument is not null, then an ASCII # character, the header string, and a line separator are first written to the output stream. Thus, the header can serve as an identifying comment. Next, a comment line is always written, consisting of an ASCII # character, the current date and time (as if produced by the toString method of Date for the current time), and a line separator as generated by the Writer. Then every entry in this Properties table is written out, one per line. For each entry the key string is written, then an ASCII =, then the associated element string. Each character of the key and element strings is examined to see whether it should be rendered as an escape sequence.

Parameters:
filename - the name of the properties file.
header - a description of the property list.

list

public void list()
Prints this property list to the default output stream (System.out).


getBooleanProperty

public boolean getBooleanProperty(java.lang.String key)
Returns the property as a boolean (property is true if != "0" or == "true").

Parameters:
key - the property key.
Returns:
the property as a boolean.

getBooleanProperty

public boolean getBooleanProperty(java.lang.String key,
                                  boolean defaultValue)
Returns the property as a boolean (property is true if != "0" or == "true").

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as a boolean.

getIntProperty

public int getIntProperty(java.lang.String key)
Returns the property as an integer.

Parameters:
key - the property key.
Returns:
the property as an integer.

getIntProperty

public int getIntProperty(java.lang.String key,
                          int defaultValue)
Returns the property as an integer.

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as an integer.

getDoubleProperty

public double getDoubleProperty(java.lang.String key)
Returns the property as a double.

Parameters:
key - the property key.
Returns:
the property as a double.

getDoubleProperty

public double getDoubleProperty(java.lang.String key,
                                double defaultValue)
Returns the property as a double.

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as a double.

getIntArrayProperty

public int[] getIntArrayProperty(java.lang.String key)
Returns the property as an integer array. The property is in the form: {1, 2, 3, 4, 5}

Parameters:
key - the property key.
Returns:
the property as an integer array.

getIntArrayProperty

public int[] getIntArrayProperty(java.lang.String key,
                                 int[] defaultValue)
Returns the property as an integer array. The property is in the form: {1, 2, 3, 4, 5}

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as an integer array.

parseIntArray

public int[] parseIntArray(java.lang.String s)
Parses a comma delimited string to an integer array. The property is in the form: {1, 2, 3, 4, 5}

Parameters:
s - the comma delimited string.
Returns:
an integer array.

get2DIntArrayProperty

public int[][] get2DIntArrayProperty(java.lang.String key)
Returns the property as a two-dimensional integer array. The property is in the form: {{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}

Parameters:
key - the property key.
Returns:
the property as a two-dimensional integer array.

get2DIntArrayProperty

public int[][] get2DIntArrayProperty(java.lang.String key,
                                     int[][] defaultValue)
Returns the property as a two-dimensional integer array. The property is in the form: {{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as a two-dimensional integer array.

parse2DIntArray

public int[][] parse2DIntArray(java.lang.String s)
Parses a comma delimited string to a two-dimensional integer array. The property is in the form: {{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}

Parameters:
s - the comma delimited string.
Returns:
a two-dimensional integer array.

get3DIntArrayProperty

public int[][][] get3DIntArrayProperty(java.lang.String key)
Returns the property as a three-dimensional integer array. The property is in the form: {{{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}, {{-1, -2}, {-3, -4}}}

Parameters:
key - the property key.
Returns:
the property as a three-dimensional integer array.

get3DIntArrayProperty

public int[][][] get3DIntArrayProperty(java.lang.String key,
                                       int[][][] defaultValue)
Returns the property as a three-dimensional integer array. The property is in the form: {{{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}, {{-1, -2}, {-3, -4}}}

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as a three-dimensional integer array.

parse3DIntArray

public int[][][] parse3DIntArray(java.lang.String s)
Parses a comma delimited string to a three-dimensional integer array. The property is in the form: {{{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}, {{-1, -2}, {-3, -4}}}

Parameters:
s - the comma delimited string.
Returns:
a three-dimensional integer array.

getDoubleArrayProperty

public double[] getDoubleArrayProperty(java.lang.String key)
Returns the property as a double array. The property is in the form: {1, 2, 3, 4, 5}

Parameters:
key - the property key.
Returns:
the property as a double array.

getDoubleArrayProperty

public double[] getDoubleArrayProperty(java.lang.String key,
                                       double[] defaultValue)
Returns the property as a double array. The property is in the form: {1, 2, 3, 4, 5}

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as a double array.

parseDoubleArray

public double[] parseDoubleArray(java.lang.String s)
Parses a comma delimited string to a double array. The property is in the form: {1, 2, 3, 4, 5}

Parameters:
s - the comma delimited string.
Returns:
a double array.

get2DDoubleArrayProperty

public double[][] get2DDoubleArrayProperty(java.lang.String key)
Returns the property as a two-dimensional double array. The property is in the form: {{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}

Parameters:
key - the property key.
Returns:
the property as a two-dimensional double array.

get2DDoubleArrayProperty

public double[][] get2DDoubleArrayProperty(java.lang.String key,
                                           double[][] defaultValue)
Returns the property as a two-dimensional double array. The property is in the form: {{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as a two-dimensional double array.

parse2DDoubleArray

public double[][] parse2DDoubleArray(java.lang.String s)
Parses a comma delimited string to a two-dimensional double array. The property is in the form: {{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}

Parameters:
s - the comma delimited string.
Returns:
a two-dimensional double array.

get3DDoubleArrayProperty

public double[][][] get3DDoubleArrayProperty(java.lang.String key)
Returns the property as a three-dimensional double array. The property is in the form: {{{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}, {{-1, -2}, {-3, -4}}}

Parameters:
key - the property key.
Returns:
the property as a three-dimensional double array.

get3DDoubleArrayProperty

public double[][][] get3DDoubleArrayProperty(java.lang.String key,
                                             double[][][] defaultValue)
Returns the property as a three-dimensional double array. The property is in the form: {{{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}, {{-1, -2}, {-3, -4}}}

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as a three-dimensional double array.

parse3DDoubleArray

public double[][][] parse3DDoubleArray(java.lang.String s)
Parses a comma delimited string to a three-dimensional double array. The property is in the form: {{{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}, {{-1, -2}, {-3, -4}}}

Parameters:
s - the comma delimited string.
Returns:
a three-dimensional double array.

getStringArrayProperty

public java.lang.String[] getStringArrayProperty(java.lang.String key)
Returns the property as a string array. The property is in the form: {"one", "two", "three", "this has \\"quotes\\""}

Parameters:
key - the property key.
Returns:
the property as a string array.

getStringArrayProperty

public java.lang.String[] getStringArrayProperty(java.lang.String key,
                                                 java.lang.String[] defaultValue)
Returns the property as a string array. The property is in the form: {"one", "two", "three", "this has \\"quotes\\""}

Parameters:
key - the property key.
defaultValue - the default value.
Returns:
the property as a string array.

parseStringArray

public java.lang.String[] parseStringArray(java.lang.String s)
Parses a ", " delimited string to a string array. The property is in the form: {"one", "two", "three", "this has \\"quotes\\""}

Parameters:
s - the ", " delimited string.
Returns:
a string array.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    boolean value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put.

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    int value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put.

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    double value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put.

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    int[] value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put. The property is written in the form: {1, 2, 3, 4, 5}

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    int[][] value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put. The property is written in the form: {{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    int[][][] value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put. The property is written in the form: {{{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}, {{-1, -2}, {-3, -4}}}

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    double[] value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put. The property is written in the form: {1, 2, 3, 4, 5}

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    double[][] value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put. The property is written in the form: {{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    double[][][] value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put. The property is written in the form: {{{1, 2, 3, 4, 5}, {6, 7, 8}, {9, 10}}, {{-1, -2}, {-3, -4}}}

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.String[] value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Conversion to a string is performed. The value returned is the result of the Hashtable call to put. The property is written in the form: {"one", "two", "three", "this has \\"quotes\\""}

Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.