org.freehep.application
Class PropertyUtilities

java.lang.Object
  extended by org.freehep.application.PropertyUtilities

public abstract class PropertyUtilities
extends Object

A set of static methods for operating on a Properties set

Version:
$Id: PropertyUtilities.java 14082 2012-12-12 16:16:53Z tonyj $
Author:
tonyj
See Also:
Properties

Nested Class Summary
static class PropertyUtilities.PropertyTable
          Creates a TableModel from a property set
static class PropertyUtilities.TranslatedProperties
          A Properties object whose values and defaults are automatically translated if they contain {prop} tokens.
 
Constructor Summary
PropertyUtilities()
           
 
Method Summary
static boolean getBoolean(Properties prop, String key, boolean def)
           
static Color getColor(Properties prop, String key, Color def)
           
static double getDouble(Properties prop, String key, double def)
           
static float getFloat(Properties prop, String key, float def)
           
static int getInteger(Properties prop, String key)
           
static int getInteger(Properties prop, String key, int def)
           
static long getLong(Properties prop, String key, long def)
           
static Rectangle getRectangle(Properties prop, String key, Rectangle def)
           
static String getString(Properties prop, String key, String def)
           
static String[] getStringArray(Properties prop, String key, String[] def)
           
static Collection getStringCollection(Properties prop, String key, Collection def)
           
static URL getURL(Properties prop, String key, URL def)
          Load a URL from a properties file.
static void setBoolean(Properties prop, String key, boolean value)
           
static void setColor(Properties prop, String key, Color c)
           
static void setDouble(Properties prop, String key, double f)
           
static void setFloat(Properties prop, String key, float f)
           
static void setInteger(Properties prop, String key, int i)
           
static void setLong(Properties prop, String key, long i)
           
static void setRectangle(Properties prop, String key, Rectangle rect)
           
static void setString(Properties prop, String key, String s)
           
static void setStringArray(Properties prop, String key, String[] sa)
           
static void setStringCollection(Properties prop, String key, Collection sa)
           
static void setURL(Properties prop, String key, URL url)
           
static boolean touchBoolean(Properties prop, String key, boolean defaultValue)
          Returns boolean value stored in the specified properties set with the given key.
static Color touchColor(Properties prop, String key, Color defaultValue)
          Returns Color stored in the specified properties set with the given key.
static double touchDouble(Properties prop, String key, double defaultValue)
          Returns double value stored in the specified properties set with the given key.
static float touchFloat(Properties prop, String key, float defaultValue)
          Returns float value stored in the specified properties set with the given key.
static int touchInteger(Properties prop, String key, int defaultValue)
          Returns int value stored in the specified properties set with the given key.
static long touchLong(Properties prop, String key, long defaultValue)
          Returns long value stored in the specified properties set with the given key.
static Rectangle touchRectangle(Properties prop, String key, Rectangle defaultValue)
          Returns Rectangle stored in the specified properties set with the given key.
static String touchString(Properties prop, String key, String defaultValue)
          Returns String stored in the specified properties set with the given key.
static String[] touchStringArray(Properties prop, String key, String[] defaultValue)
          Returns String array stored in the specified properties set with the given key.
static Collection touchStringCollection(Properties prop, String key, Collection defaultValue)
          Returns String collection stored in the specified properties set with the given key.
static URL touchURL(Properties prop, String key, URL defaultValue)
          Returns URL value stored in the specified properties set with the given key.
static String translate(Properties prop, String in)
          Translates a string by substituting tokens of the form {name} to the value of property name in the properties set.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyUtilities

public PropertyUtilities()
Method Detail

getRectangle

public static Rectangle getRectangle(Properties prop,
                                     String key,
                                     Rectangle def)
Parameters:
prop - The Properties set
key - the key used to store this property
def - a default in case the property cannot be retrieved

touchRectangle

public static Rectangle touchRectangle(Properties prop,
                                       String key,
                                       Rectangle defaultValue)
Returns Rectangle stored in the specified properties set with the given key. If the Rectangle cannot be retrieved, stores the specified default value into the properties set, and returns it to the caller.


setRectangle

public static void setRectangle(Properties prop,
                                String key,
                                Rectangle rect)
Parameters:
prop - The Properties set
key - the key used to store this property
rect - the value to store

getColor

public static Color getColor(Properties prop,
                             String key,
                             Color def)
Parameters:
prop - The Properties set
key - the key used to store this property
def - a default in case the property cannot be retrieved

touchColor

public static Color touchColor(Properties prop,
                               String key,
                               Color defaultValue)
Returns Color stored in the specified properties set with the given key. If the Color cannot be retrieved, stores the specified default value into the properties set, and returns it to the caller.


setColor

public static void setColor(Properties prop,
                            String key,
                            Color c)
Parameters:
prop - The Properties set
key - the key used to store this property
c - the value to store

getStringCollection

public static Collection getStringCollection(Properties prop,
                                             String key,
                                             Collection def)
Parameters:
prop - The Properties set
key - the key used to store this property
def - a default in case the property cannot be retrieved

touchStringCollection

public static Collection touchStringCollection(Properties prop,
                                               String key,
                                               Collection defaultValue)
Returns String collection stored in the specified properties set with the given key. If the collection cannot be retrieved, stores the specified default value into the properties set, and returns it to the caller.


setStringCollection

public static void setStringCollection(Properties prop,
                                       String key,
                                       Collection sa)
Parameters:
prop - The Properties set
key - the key used to store this property
sa - the value to store

getStringArray

public static String[] getStringArray(Properties prop,
                                      String key,
                                      String[] def)
Parameters:
prop - The Properties set
key - the key used to store this property
def - a default in case the property cannot be retrieved

touchStringArray

public static String[] touchStringArray(Properties prop,
                                        String key,
                                        String[] defaultValue)
Returns String array stored in the specified properties set with the given key. If the array cannot be retrieved for any reason, stores the specified default value into the properties set, and returns it to the caller.


setStringArray

public static void setStringArray(Properties prop,
                                  String key,
                                  String[] sa)
Parameters:
prop - The Properties set
key - the key used to store this property
sa - the value to store

getString

public static String getString(Properties prop,
                               String key,
                               String def)
Parameters:
prop - The Properties set
key - the key used to store this property
defaultValue - a default in case the property cannot be retrieved

touchString

public static String touchString(Properties prop,
                                 String key,
                                 String defaultValue)
Returns String stored in the specified properties set with the given key. If the string cannot be retrieved for any reason, stores the specified default value into the properties set, and returns it to the caller.


setString

public static void setString(Properties prop,
                             String key,
                             String s)
Parameters:
prop - The Properties set
key - the key used to store this property
s - the value to store

getBoolean

public static boolean getBoolean(Properties prop,
                                 String key,
                                 boolean def)
Parameters:
prop - The Properties set
key - the key used to store this property
def - a default in case the property cannot be retrieved

touchBoolean

public static boolean touchBoolean(Properties prop,
                                   String key,
                                   boolean defaultValue)
Returns boolean value stored in the specified properties set with the given key. If the value cannot be retrieved, stores the specified default value into the properties set, and returns it to the caller.


setBoolean

public static void setBoolean(Properties prop,
                              String key,
                              boolean value)
Parameters:
prop - The Properties set
key - the key used to store this property
value - the value to store

getInteger

public static int getInteger(Properties prop,
                             String key)
                      throws NumberFormatException
Parameters:
prop - The Properties set
key - the key used to store this property
Throws:
NumberFormatException - if the property retrieved cannot be converted to int

getInteger

public static int getInteger(Properties prop,
                             String key,
                             int def)
Parameters:
prop - The Properties set
key - the key used to store this property
def - a default in case the property cannot be retrieved

touchInteger

public static int touchInteger(Properties prop,
                               String key,
                               int defaultValue)
Returns int value stored in the specified properties set with the given key. If the value cannot be retrieved for any reason, stores the specified default value into the properties set, and returns it to the caller.


setInteger

public static void setInteger(Properties prop,
                              String key,
                              int i)
Parameters:
prop - The Properties set
key - the key used to store this property
i - the value to store

getLong

public static long getLong(Properties prop,
                           String key,
                           long def)
Parameters:
prop - The Properties set
key - the key used to store this property
def - a default in case the property cannot be retrieved

touchLong

public static long touchLong(Properties prop,
                             String key,
                             long defaultValue)
Returns long value stored in the specified properties set with the given key. If the value cannot be retrieved for any reason, stores the specified default value into the properties set, and returns it to the caller.


setLong

public static void setLong(Properties prop,
                           String key,
                           long i)
Parameters:
prop - The Properties set
key - the key used to store this property
i - the value to store

getFloat

public static float getFloat(Properties prop,
                             String key,
                             float def)
Parameters:
prop - The Properties set
key - the key used to store this property
def - a default in case the property cannot be retrieved

touchFloat

public static float touchFloat(Properties prop,
                               String key,
                               float defaultValue)
Returns float value stored in the specified properties set with the given key. If the value cannot be retrieved for any reason, stores the specified default value into the properties set, and returns it to the caller.


setFloat

public static void setFloat(Properties prop,
                            String key,
                            float f)
Parameters:
prop - The Properties set
key - the key used to store this property
f - the value to store

getDouble

public static double getDouble(Properties prop,
                               String key,
                               double def)
Parameters:
prop - The Properties set
key - the key used to store this property
def - a default in case the property cannot be retrieved

touchDouble

public static double touchDouble(Properties prop,
                                 String key,
                                 double defaultValue)
Returns double value stored in the specified properties set with the given key. If the value cannot be retrieved for any reason, stores the specified default value into the properties set, and returns it to the caller.


setDouble

public static void setDouble(Properties prop,
                             String key,
                             double f)
Parameters:
prop - The Properties set
key - the key used to store this property
f - the value to store

getURL

public static URL getURL(Properties prop,
                         String key,
                         URL def)
Load a URL from a properties file. If the URL begins with / it is taken to be a system resource (i.e. on the classpath).


touchURL

public static URL touchURL(Properties prop,
                           String key,
                           URL defaultValue)
Returns URL value stored in the specified properties set with the given key. If the value cannot be retrieved for any reason, stores the specified default value into the properties set, and returns it to the caller.


setURL

public static void setURL(Properties prop,
                          String key,
                          URL url)

translate

public static String translate(Properties prop,
                               String in)
Translates a string by substituting tokens of the form {name} to the value of property name in the properties set.

Parameters:
prop - The properties set
in - The string to be translated
Returns:
The resulting string.


Copyright © 2000-2013 FreeHEP. All Rights Reserved.