|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Dictionary
java.util.Hashtable
java.util.Properties
com.anji.util.Properties
Beefed up version of java.util.Properties used to manage configuration parameters. Adds convenience functions for converting String properties to various data types and logs all default and configured property settings.
Field Summary | |
static java.lang.String |
CLASS_SUFFIX
made public for unit tests |
Fields inherited from class java.util.Properties |
defaults |
Constructor Summary | |
Properties()
default constructor |
|
Properties(java.util.Properties values)
Initialize with values . |
|
Properties(java.lang.String resource)
initialize properties from file; also, initializes Logger |
Method Summary | |
boolean |
getBooleanProperty(java.lang.String key)
|
boolean |
getBooleanProperty(java.lang.String key,
boolean defaultVal)
|
java.lang.Class |
getClassProperty(java.lang.String key)
|
java.lang.Class |
getClassProperty(java.lang.String key,
java.lang.Class defaultVal)
|
java.io.File |
getDirProperty(java.lang.String key)
|
double |
getDoubleProperty(java.lang.String key)
|
double |
getDoubleProperty(java.lang.String key,
double defaultVal)
|
java.io.FileInputStream |
getFileInputProperty(java.lang.String key)
|
java.io.FileOutputStream |
getFileOutputProperty(java.lang.String key)
|
float |
getFloatProperty(java.lang.String key)
|
float |
getFloatProperty(java.lang.String key,
float defaultVal)
|
int |
getIntProperty(java.lang.String key)
|
int |
getIntProperty(java.lang.String key,
int defaultVal)
|
java.util.Set |
getKeysForPattern(java.lang.String pattern)
Returns property keys matching regular expression pattern. |
long |
getLongProperty(java.lang.String key)
|
long |
getLongProperty(java.lang.String key,
long defaultVal)
|
java.lang.String |
getName()
|
java.util.Set |
getPropertiesForPattern(java.lang.String pattern)
Returns property values for keys matching regular expression pattern. |
java.lang.String |
getProperty(java.lang.String key)
|
java.lang.String |
getProperty(java.lang.String key,
java.lang.String defaultVal)
|
java.io.InputStream |
getResourceProperty(java.lang.String key)
|
short |
getShortProperty(java.lang.String key)
|
short |
getShortProperty(java.lang.String key,
short defaultVal)
|
Properties |
getSubProperties(java.lang.String prefix)
Return properties filtered for a particular sub-component, based on prefix . |
static double[][] |
loadArrayFromFile(java.io.InputStream in)
|
static boolean[][] |
loadBooleanArrayFromFile(java.io.InputStream in)
TODO - better class for this? combine w/ getProperty |
static boolean[] |
loadBooleanRowFromString(java.lang.String line)
TODO - better class for this? combine w/ getProperty |
void |
loadFromResource(java.lang.String resource)
loads properties from file; also, initializes Logger |
void |
loadFromResourceWithoutLogging(java.lang.String resource)
loads properties from file |
protected static double[] |
loadRowFromString(java.lang.String line)
TODO - better class for this? combine w/ getProperty |
java.util.List |
newObjectListProperty(java.lang.String key)
Throws IllegalArgumentException exception if key not present. |
java.util.List |
newObjectListProperty(java.lang.String key,
java.util.List defaultList)
Return list of objects initialized from properties. |
java.lang.Object |
newObjectProperty(java.lang.Class aClass)
|
java.lang.Object |
newObjectProperty(java.lang.String key)
|
protected void |
setName(java.lang.String aName)
|
java.lang.Object |
singletonObjectProperty(java.lang.Class aClass)
|
java.lang.Object |
singletonObjectProperty(java.lang.String key)
|
java.lang.String |
toString()
|
Methods inherited from class java.util.Properties |
list, list, load, propertyNames, save, setProperty, store |
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, values |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String CLASS_SUFFIX
Constructor Detail |
public Properties()
public Properties(java.util.Properties values)
values
.
values
- public Properties(java.lang.String resource) throws java.io.IOException
Logger
resource
- a file in the application classpath
java.io.IOException
Method Detail |
public void loadFromResource(java.lang.String resource) throws java.io.IOException
Logger
resource
- a file in the application classpath
java.io.IOException
public void loadFromResourceWithoutLogging(java.lang.String resource) throws java.io.IOException
resource
- a file in the application classpath
java.io.IOException
public java.lang.String getProperty(java.lang.String key)
key
-
key
; throws runtime exception
if key not foundpublic boolean getBooleanProperty(java.lang.String key)
key
-
key
; throws runtime exception
if key not foundpublic long getLongProperty(java.lang.String key)
key
-
key
; throws runtime exception if
key not found or invalid longpublic int getIntProperty(java.lang.String key)
key
-
key
public short getShortProperty(java.lang.String key)
key
-
key
public float getFloatProperty(java.lang.String key)
key
-
key
; throws runtime exception
if key not found or invalid floatpublic double getDoubleProperty(java.lang.String key)
key
-
key
; throws runtime exception
if key not found or invalid doublepublic java.lang.String getProperty(java.lang.String key, java.lang.String defaultVal)
key
- defaultVal
-
key
., or
defaultVal
if key not foundpublic boolean getBooleanProperty(java.lang.String key, boolean defaultVal)
key
- defaultVal
-
key
., or
defaultVal
if key not foundpublic long getLongProperty(java.lang.String key, long defaultVal)
key
- defaultVal
-
key
., or defaultVal
if key not foundpublic int getIntProperty(java.lang.String key, int defaultVal)
key
- defaultVal
-
key
., or defaultVal
if key not foundpublic short getShortProperty(java.lang.String key, short defaultVal)
key
- defaultVal
-
key
., or
defaultVal
if key not foundpublic float getFloatProperty(java.lang.String key, float defaultVal)
key
- defaultVal
-
key
., or
defaultVal
if key not foundpublic double getDoubleProperty(java.lang.String key, double defaultVal)
key
- defaultVal
-
key
., or
defaultVal
if key not foundpublic java.util.Set getKeysForPattern(java.lang.String pattern)
pattern
- interpreted as regular expression
public java.util.Set getPropertiesForPattern(java.lang.String pattern)
pattern
- interpreted as regular expression
public Properties getSubProperties(java.lang.String prefix)
prefix
.
prefix
-
Properties
object properties contained in this object, but for those
cases where the property starts with prefix
, the property overrides another
property of the same key; e.g., if prefix
is "abc", and there is an
"abc.foo=bar" property and a "foo=bat" property, this method returns a properties object
containing "foo=bar"public java.io.File getDirProperty(java.lang.String key)
key
-
key
; throws runtime
exception if key not foundpublic java.io.FileInputStream getFileInputProperty(java.lang.String key) throws java.io.FileNotFoundException
key
-
key
; throws runtime
exception if key not found
java.io.FileNotFoundException
public java.io.FileOutputStream getFileOutputProperty(java.lang.String key) throws java.io.FileNotFoundException
key
-
key
; throws runtime
exception if key not found
java.io.FileNotFoundException
public java.io.InputStream getResourceProperty(java.lang.String key)
key
-
key
; throws runtime exception if key not foundpublic java.lang.Object singletonObjectProperty(java.lang.String key)
key
-
key
; throws runtime exception if key
not foundpublic java.lang.String toString()
Object.toString()
public java.lang.Object singletonObjectProperty(java.lang.Class aClass)
aClass
-
cl
initialized with properties if it is
Configurable
public java.lang.Object newObjectProperty(java.lang.String key)
key
- key
+CLASS_SUFFIX
references property with fully
qualified class name
key
; throws runtime exception if key
not foundpublic java.lang.Object newObjectProperty(java.lang.Class aClass)
aClass
-
cl
, initialized with properties if
Configurable
not foundpublic java.lang.Class getClassProperty(java.lang.String key)
key
-
Class
corresponding to full package specification in property value
associated with key
java.lang.IllegalArgumentException
- if key not foundpublic java.lang.Class getClassProperty(java.lang.String key, java.lang.Class defaultVal)
key
- defaultVal
-
Class
corresponding to full package specification in property value
associated with key
; returns defaultVal
if key not foundpublic static double[][] loadArrayFromFile(java.io.InputStream in) throws java.io.FileNotFoundException, java.io.IOException
in
-
double[][]
matrix generated by interpreting contents of
in
as a 2-dimensional array of values; columns separated by semi-colons, rows
separated by "\n"
java.io.FileNotFoundException
java.io.IOException
public static boolean[][] loadBooleanArrayFromFile(java.io.InputStream in) throws java.io.FileNotFoundException, java.io.IOException
in
-
boolean[][]
matrix generated by interpreting contents of
in
as a 2-dimensional array of values; columns separated by semi-colons, rows
separated by "\n"
java.io.FileNotFoundException
java.io.IOException
protected static double[] loadRowFromString(java.lang.String line)
line
-
double[]
generated by interpreting contents of line
as
a list of values separated by semi-colonspublic static boolean[] loadBooleanRowFromString(java.lang.String line)
line
-
boolean[]
generated by interpreting contents of line
as
a list of values separated by semi-colonspublic java.util.List newObjectListProperty(java.lang.String key, java.util.List defaultList)
key
. Each object, if it is
Configurable
, is initialized with properties prefixed with its name, plus
remainder of properties. The class of each object is determined by a property named object
name +CLASS_SUFFIX
key
- defaultList
- returns this if no property key
exists
List
contains initialized objectspublic java.util.List newObjectListProperty(java.lang.String key)
IllegalArgumentException
exception if key not present.
key
-
List
contains initialized objectsnewObjectListProperty(String, List)
public java.lang.String getName()
protected void setName(java.lang.String aName)
aName
- name of this property set
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |