com.thetransactioncompany.util
Class PropertyRetriever

java.lang.Object
  extended by com.thetransactioncompany.util.PropertyRetriever

public class PropertyRetriever
extends Object

Provides typed retrieval of Properties as boolean, int, long, float, double, String, URL or enum values.

Author:
Vladimir Dzhuvinov

Constructor Summary
PropertyRetriever(Properties props)
          Creates a new retriever for the specified properties.
 
Method Summary
 boolean getBoolean(String key)
          Retrieves a boolean value.
 double getDouble(String key)
          Retrieves a double value.
<T extends Enum<T>>
T
getEnum(String key, Class<T> enumClass)
          Retrieves an enumerated constant.
 String getEnumString(String key, String[] enums)
          Retrieves an enumerated string value.
 float getFloat(String key)
          Retrieves a float value.
 int getInt(String key)
          Retrieves an integer value.
 long getLong(String key)
          Retrieves a long value.
 boolean getOptBoolean(String key, boolean def)
          Retrieves an optional boolean value.
 double getOptDouble(String key, double def)
          Retrieves an optional double value.
<T extends Enum<T>>
T
getOptEnum(String key, Class<T> enumClass, T def)
          Retrieves an optional enumerated constant.
 String getOptEnumString(String key, String[] enums, String def)
          Retrieves an enumerated string value.
 float getOptFloat(String key, float def)
          Retrieves an optional float value.
 int getOptInt(String key, int def)
          Retrieves an optional integer value.
 long getOptLong(String key, long def)
          Retrieves an optional long value.
 String getOptString(String key, String def)
          Retrieves an optional string value.
 URL getOptURL(String key, URL def)
          Retrieves an optional URL value.
 String getString(String key)
          Retrieves a string value.
 URL getURL(String key)
          Retrieves a URL value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyRetriever

public PropertyRetriever(Properties props)
Creates a new retriever for the specified properties.

Parameters:
props - The properties hasthtable.
Method Detail

getBoolean

public boolean getBoolean(String key)
                   throws PropertyParseException
Retrieves a boolean value.

Parameters:
key - The property name.
Returns:
The property as a boolean value.
Throws:
PropertyParseException - On a missing or invalid property.

getOptBoolean

public boolean getOptBoolean(String key,
                             boolean def)
                      throws PropertyParseException
Retrieves an optional boolean value.

Parameters:
key - The property name.
def - The default value if the property value is undefined.
Returns:
The property as a boolean.
Throws:
PropertyParseException - On an invalid property.

getInt

public int getInt(String key)
           throws PropertyParseException
Retrieves an integer value.

Parameters:
key - The property name.
Returns:
The property as an integer.
Throws:
PropertyParseException - On a missing or invalid property.

getOptInt

public int getOptInt(String key,
                     int def)
              throws PropertyParseException
Retrieves an optional integer value.

Parameters:
key - The property name.
def - The default value if the property value is undefined.
Returns:
The property as an integer.
Throws:
PropertyParseException - On an invalid property.

getLong

public long getLong(String key)
             throws PropertyParseException
Retrieves a long value.

Parameters:
key - The property name.
Returns:
The property as a long.
Throws:
PropertyParseException - On a missing or invalid property.

getOptLong

public long getOptLong(String key,
                       long def)
                throws PropertyParseException
Retrieves an optional long value.

Parameters:
key - The property name.
def - The default value if the property value is undefined.
Returns:
The property as a long.
Throws:
PropertyParseException - On an invalid property.

getFloat

public float getFloat(String key)
               throws PropertyParseException
Retrieves a float value.

Parameters:
key - The property name.
Returns:
The property as a float.
Throws:
PropertyParseException - On a missing or invalid property.

getOptFloat

public float getOptFloat(String key,
                         float def)
                  throws PropertyParseException
Retrieves an optional float value.

Parameters:
key - The property name.
def - The default value if the property value is undefined.
Returns:
The property as a float.
Throws:
PropertyParseException - On an invalid property.

getDouble

public double getDouble(String key)
                 throws PropertyParseException
Retrieves a double value.

Parameters:
key - The property name.
Returns:
The property as a double.
Throws:
PropertyParseException - On a missing or invalid property.

getOptDouble

public double getOptDouble(String key,
                           double def)
                    throws PropertyParseException
Retrieves an optional double value.

Parameters:
key - The property name.
def - The default value if the property value is undefined.
Returns:
The property as a double.
Throws:
PropertyParseException - On an invalid property.

getString

public String getString(String key)
                 throws PropertyParseException
Retrieves a string value.

Parameters:
key - The property name.
Returns:
The property as a string.
Throws:
PropertyParseException - On a missing or invalid property.

getOptString

public String getOptString(String key,
                           String def)
                    throws PropertyParseException
Retrieves an optional string value.

Parameters:
key - The property name.
def - The default value if the property value is undefined or empty.
Returns:
The property as a string.
Throws:
PropertyParseException - On an invalid property.

getEnumString

public String getEnumString(String key,
                            String[] enums)
                     throws PropertyParseException
Retrieves an enumerated string value. String case is ignored during comparison.

Parameters:
key - The property name.
enums - A string array defining the acceptable values.
Returns:
The property as a string.
Throws:
PropertyParseException - On a missing or invalid property.

getOptEnumString

public String getOptEnumString(String key,
                               String[] enums,
                               String def)
                        throws PropertyParseException
Retrieves an enumerated string value. String case is ignored during comparison.

Parameters:
key - The property name.
enums - A string array defining the acceptable values.
def - The default value if the property value is undefined.
Returns:
The property as a string.
Throws:
PropertyParseException - On an invalid property.

getEnum

public <T extends Enum<T>> T getEnum(String key,
                                     Class<T> enumClass)
                          throws PropertyParseException
Retrieves an enumerated constant. String case is ignored during comparison.

Parameters:
key - The property name.
enumClass - The enumeration class specifying the acceptable values.
Returns:
The matching enumerated constant.
Throws:
PropertyParseException - On a missing or invalid property.

getOptEnum

public <T extends Enum<T>> T getOptEnum(String key,
                                        Class<T> enumClass,
                                        T def)
                             throws PropertyParseException
Retrieves an optional enumerated constant. String case is ignored during comparison.

Parameters:
key - The property name.
enumClass - The enumeration class specifying the acceptable values.
def - The default value if the property value is undefined.
Returns:
The matching enumerated constant.
Throws:
PropertyParseException - On a missing or invalid property.

getURL

public URL getURL(String key)
           throws PropertyParseException
Retrieves a URL value.

Parameters:
key - The property name.
Returns:
The property as a URL.
Throws:
PropertyParseException - On a missing or invalid property.

getOptURL

public URL getOptURL(String key,
                     URL def)
              throws PropertyParseException
Retrieves an optional URL value.

Parameters:
key - The property name.
def - The default value if the property value is undefined.
Returns:
The property as a URL.
Throws:
PropertyParseException - On an invalid property.


Copyright © 2013 The Transaction Company. All Rights Reserved.