edu.stanford.nlp.util
Class PropertiesUtils

java.lang.Object
  extended by edu.stanford.nlp.util.PropertiesUtils

public class PropertiesUtils
extends Object


Method Summary
static Map<String,String> asMap(Properties properties)
          Tired of Properties not behaving like Maps? This method will solve that problem for you.
static void checkProperties(Properties properties, Properties defaults)
          Checks to make sure that all properties specified in properties are known to the program by checking that each simply overrides a default value
static
<E> E
get(Properties props, String key, E defaultValue, Type type)
          Get the value of a property and automatically cast it to a specific type.
static boolean getBool(Properties props, String key)
          Load a boolean property.
static boolean getBool(Properties props, String key, boolean defaultValue)
          Load a boolean property.
static double getDouble(Properties props, String key)
          Load a double property.
static double getDouble(Properties props, String key, double defaultValue)
          Load a double property.
static double[] getDoubleArray(Properties props, String key)
          Loads a comma-separated list of doubles from Properties.
static int getInt(Properties props, String key)
          Load an integer property.
static int getInt(Properties props, String key, int defaultValue)
          Load an integer property.
static int[] getIntArray(Properties props, String key)
          Loads a comma-separated list of integers from Properties.
static List<Map.Entry<String,String>> getSortedEntries(Properties properties)
           
static String[] getStringArray(Properties props, String key)
          Loads a comma-separated list of strings from Properties.
static boolean hasProperty(Properties props, String key)
          Returns true iff the given Properties contains a property with the given key (name), and its value is not "false" or "no" or "off".
static void printProperties(String message, Properties properties)
           
static void printProperties(String message, Properties properties, PrintStream stream)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hasProperty

public static boolean hasProperty(Properties props,
                                  String key)
Returns true iff the given Properties contains a property with the given key (name), and its value is not "false" or "no" or "off".

Parameters:
props - Properties object
key - The key to test
Returns:
true iff the given Properties contains a property with the given key (name), and its value is not "false" or "no" or "off".

printProperties

public static void printProperties(String message,
                                   Properties properties,
                                   PrintStream stream)

printProperties

public static void printProperties(String message,
                                   Properties properties)

asMap

public static Map<String,String> asMap(Properties properties)
Tired of Properties not behaving like Maps? This method will solve that problem for you.


getSortedEntries

public static List<Map.Entry<String,String>> getSortedEntries(Properties properties)

checkProperties

public static void checkProperties(Properties properties,
                                   Properties defaults)
Checks to make sure that all properties specified in properties are known to the program by checking that each simply overrides a default value

Parameters:
properties - Current properties
defaults - Default properties which lists all known keys

get

public static <E> E get(Properties props,
                        String key,
                        E defaultValue,
                        Type type)
Get the value of a property and automatically cast it to a specific type. This differs from the original Properties.getProperty() method in that you need to specify the desired type (e.g. Double.class) and the default value is an object of that type, i.e. a double 0.0 instead of the String "0.0".


getInt

public static int getInt(Properties props,
                         String key)
Load an integer property. If the key is not present, returns 0.


getInt

public static int getInt(Properties props,
                         String key,
                         int defaultValue)
Load an integer property. If the key is not present, returns defaultValue.


getDouble

public static double getDouble(Properties props,
                               String key)
Load a double property. If the key is not present, returns 0.0.


getDouble

public static double getDouble(Properties props,
                               String key,
                               double defaultValue)
Load a double property. If the key is not present, returns defaultValue.


getBool

public static boolean getBool(Properties props,
                              String key)
Load a boolean property. If the key is not present, returns false.


getBool

public static boolean getBool(Properties props,
                              String key,
                              boolean defaultValue)
Load a boolean property. If the key is not present, returns defaultValue.


getIntArray

public static int[] getIntArray(Properties props,
                                String key)
Loads a comma-separated list of integers from Properties. The list cannot include any whitespace.


getDoubleArray

public static double[] getDoubleArray(Properties props,
                                      String key)
Loads a comma-separated list of doubles from Properties. The list cannot include any whitespace.


getStringArray

public static String[] getStringArray(Properties props,
                                      String key)
Loads a comma-separated list of strings from Properties. Commas may be quoted if needed, e.g.: property1 = value1,value2,"a quoted value",'another quoted value' getStringArray(props, "property1") should return the same thing as new String[] { "value1", "value2", "a quoted value", "another quoted value" };



Stanford NLP Group