Skip navigation links
Overview
Package
Class
Tree
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu.stanford.nlp.util
Class PropertiesUtils
java.lang.Object
edu.stanford.nlp.util.PropertiesUtils
public class PropertiesUtils
extends java.lang.Object
Utilities methods for standard (but woeful) Java Properties objects.
Author:
Sarah Spikes, David McClosky
Nested Class Summary
Nested Classes
Modifier and Type
Class and Description
static class
PropertiesUtils.Property
Method Summary
All Methods Static Methods Concrete Methods
Modifier and Type
Method and Description
static java.util.Map
asMap(java.util.Properties properties)
Tired of Properties not behaving like Maps? This method will solve that problem for you.
static java.util.Properties
asProperties(java.lang.String... args)
Create a Properties object from the passed in String arguments.
static java.lang.String
asString(java.util.Properties props)
Convert from Properties to String.
static void
checkProperties(java.util.Properties properties,
java.util.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 java.util.Properties
extractPrefixedProperties(java.util.Properties properties,
java.lang.String prefix)
Build a Properties object containing key-value pairs from
the given data where the keys are prefixed with the given
prefix.
static java.util.Properties
extractPrefixedProperties(java.util.Properties properties,
java.lang.String prefix,
boolean keepPrefix)
Build a Properties object containing key-value pairs from
the given data where the keys are prefixed with the given
prefix.
static java.util.Properties
extractSelectedProperties(java.util.Properties properties,
java.util.Set keptProperties)
Build a Properties object containing key-value pairs from
the given properties whose keys are in a list to keep.
static java.util.Properties
fromString(java.lang.String str)
Convert from String to Properties.
static E
get(java.util.Properties props,
java.lang.String key,
E defaultValue,
java.lang.reflect.Type type)
Get the value of a property and automatically cast it to a specific type.
static boolean
getBool(java.util.Properties props,
java.lang.String key)
Load a boolean property.
static boolean
getBool(java.util.Properties props,
java.lang.String key,
boolean defaultValue)
Load a boolean property.
static java.lang.String
getDirPath(java.util.Properties props,
java.lang.String key,
java.lang.String defaultValue)
Get the value of a property as a path to a directory.
static double
getDouble(java.util.Properties props,
java.lang.String key)
Load a double property.
static double
getDouble(java.util.Properties props,
java.lang.String key,
double defaultValue)
Load a double property.
static double[]
getDoubleArray(java.util.Properties props,
java.lang.String key)
Loads a comma-separated list of doubles from Properties.
static int
getInt(java.util.Properties props,
java.lang.String key)
Load an integer property.
static int
getInt(java.util.Properties props,
java.lang.String key,
int defaultValue)
Load an integer property.
static int[]
getIntArray(java.util.Properties props,
java.lang.String key)
Loads a comma-separated list of integers from Properties.
static long
getLong(java.util.Properties props,
java.lang.String key,
long defaultValue)
Load an integer property as a long.
static java.lang.String
getSignature(java.lang.String name,
java.util.Properties properties)
static java.lang.String
getSignature(java.lang.String name,
java.util.Properties properties,
PropertiesUtils.Property[] supportedProperties)
static java.util.List
getSortedEntries(java.util.Properties properties)
static java.lang.String
getString(java.util.Properties props,
java.lang.String key,
java.lang.String defaultValue)
Get the value of a property.
static java.lang.String[]
getStringArray(java.util.Properties props,
java.lang.String key)
Loads a comma-separated list of strings from Properties.
static java.lang.String[]
getStringArray(java.util.Properties props,
java.lang.String key,
java.lang.String[] defaults)
static boolean
hasProperty(java.util.Properties props,
java.lang.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 boolean
hasPropertyPrefix(java.util.Properties props,
java.lang.String prefix)
static java.util.Properties
noClobberWriteProperties(java.util.Properties bp,
java.util.Properties ovp)
static java.util.Properties
overWriteProperties(java.util.Properties bp,
java.util.Properties ovp)
static void
printProperties(java.lang.String message,
java.util.Properties properties)
static void
printProperties(java.lang.String message,
java.util.Properties properties,
java.io.PrintStream stream)
static java.lang.String
propsAsJsonString(java.util.Properties props)
Convert the given properties to a json string
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(java.util.Properties props,
java.lang.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".
hasPropertyPrefix
public static boolean hasPropertyPrefix(java.util.Properties props,
java.lang.String prefix)
asProperties
public static java.util.Properties asProperties(java.lang.String... args)
Create a Properties object from the passed in String arguments.
The odd numbered arguments are the names of keys, and the even
numbered arguments are the value of the preceding key
Parameters:
args - An even-length list of alternately key and value
asString
public static java.lang.String asString(java.util.Properties props)
Convert from Properties to String.
fromString
public static java.util.Properties fromString(java.lang.String str)
Convert from String to Properties.
printProperties
public static void printProperties(java.lang.String message,
java.util.Properties properties,
java.io.PrintStream stream)
printProperties
public static void printProperties(java.lang.String message,
java.util.Properties properties)
asMap
public static java.util.Map asMap(java.util.Properties properties)
Tired of Properties not behaving like Maps? This method will solve that problem for you.
getSortedEntries
public static java.util.List getSortedEntries(java.util.Properties properties)
checkProperties
public static void checkProperties(java.util.Properties properties,
java.util.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
extractPrefixedProperties
public static java.util.Properties extractPrefixedProperties(java.util.Properties properties,
java.lang.String prefix)
Build a Properties object containing key-value pairs from
the given data where the keys are prefixed with the given
prefix. The keys in the returned object will be stripped
of their common prefix.
Parameters:
properties - Key-value data from which to extract pairs
prefix - Key-value pairs where the key has this prefix will
be retained in the returned Properties object
Returns:
A Properties object containing those key-value pairs from
properties where the key was prefixed by
prefix. This prefix is removed from all keys in
the returned structure.
extractPrefixedProperties
public static java.util.Properties extractPrefixedProperties(java.util.Properties properties,
java.lang.String prefix,
boolean keepPrefix)
Build a Properties object containing key-value pairs from
the given data where the keys are prefixed with the given
prefix. The keys in the returned object will be stripped
of their common prefix.
Parameters:
properties - Key-value data from which to extract pairs
prefix - Key-value pairs where the key has this prefix will
be retained in the returned Properties object
keepPrefix - whether the prefix should be kept in the key
Returns:
A Properties object containing those key-value pairs from
properties where the key was prefixed by
prefix. If keepPrefix is false, the prefix is removed from all keys in
the returned structure.
extractSelectedProperties
public static java.util.Properties extractSelectedProperties(java.util.Properties properties,
java.util.Set keptProperties)
Build a Properties object containing key-value pairs from
the given properties whose keys are in a list to keep.
Parameters:
properties - Key-value data from which to extract pairs
keptProperties - Key names to keep (by exact match).
Returns:
A Properties object containing those key-value pairs from
properties where the key was in keptProperties
get
public static E get(java.util.Properties props,
java.lang.String key,
E defaultValue,
java.lang.reflect.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".
getDirPath
public static java.lang.String getDirPath(java.util.Properties props,
java.lang.String key,
java.lang.String defaultValue)
Get the value of a property as a path to a directory. If the key is not present, returns defaultValue.
If the path doesn't terminate with '/', append '/' to the string.
getString
public static java.lang.String getString(java.util.Properties props,
java.lang.String key,
java.lang.String defaultValue)
Get the value of a property. If the key is not present, returns defaultValue.
This is just equivalent to props.getProperty(key, defaultValue).
getInt
public static int getInt(java.util.Properties props,
java.lang.String key)
Load an integer property. If the key is not present, returns 0.
getInt
public static int getInt(java.util.Properties props,
java.lang.String key,
int defaultValue)
Load an integer property. If the key is not present, returns defaultValue.
getLong
public static long getLong(java.util.Properties props,
java.lang.String key,
long defaultValue)
Load an integer property as a long.
If the key is not present, returns defaultValue.
getDouble
public static double getDouble(java.util.Properties props,
java.lang.String key)
Load a double property. If the key is not present, returns 0.0.
getDouble
public static double getDouble(java.util.Properties props,
java.lang.String key,
double defaultValue)
Load a double property. If the key is not present, returns defaultValue.
getBool
public static boolean getBool(java.util.Properties props,
java.lang.String key)
Load a boolean property. If the key is not present, returns false.
getBool
public static boolean getBool(java.util.Properties props,
java.lang.String key,
boolean defaultValue)
Load a boolean property. If the key is not present, returns defaultValue.
getIntArray
public static int[] getIntArray(java.util.Properties props,
java.lang.String key)
Loads a comma-separated list of integers from Properties. The list cannot include any whitespace.
getDoubleArray
public static double[] getDoubleArray(java.util.Properties props,
java.lang.String key)
Loads a comma-separated list of doubles from Properties. The list cannot include any whitespace.
getStringArray
public static java.lang.String[] getStringArray(java.util.Properties props,
java.lang.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" };
Returns:
An array of Strings value for the given key in the Properties. May be empty. Never null.
getStringArray
public static java.lang.String[] getStringArray(java.util.Properties props,
java.lang.String key,
java.lang.String[] defaults)
overWriteProperties
public static java.util.Properties overWriteProperties(java.util.Properties bp,
java.util.Properties ovp)
noClobberWriteProperties
public static java.util.Properties noClobberWriteProperties(java.util.Properties bp,
java.util.Properties ovp)
getSignature
public static java.lang.String getSignature(java.lang.String name,
java.util.Properties properties,
PropertiesUtils.Property[] supportedProperties)
getSignature
public static java.lang.String getSignature(java.lang.String name,
java.util.Properties properties)
propsAsJsonString
public static java.lang.String propsAsJsonString(java.util.Properties props)
Convert the given properties to a json string
Skip navigation links
Overview
Package
Class
Tree
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
Stanford NLP Group
|