public class Options extends java.lang.Object
Properties for details.Properties| Modifier and Type | Class and Description |
|---|---|
static class |
Options.ValueConversionException
Exception objects of this class are possibly returned by
getBooleanValue(String)and
getIntValue(String), if corresponding options don't have a
boolean respectively integer value. |
| Modifier and Type | Field and Description |
|---|---|
static int |
OPTION_NOT_PRESENT
Returned by
countValues when trying to count values of a
non-present option. |
| Constructor and Description |
|---|
Options()
Construct a new
Option object holding now options. |
| Modifier and Type | Method and Description |
|---|---|
int |
countValues(java.lang.String option)
Count the space separated values of an option.
|
boolean |
getBooleanValue(java.lang.String option)
Get the value for an option as
boolean. |
boolean |
getBooleanValue(java.lang.String option,
boolean defaultValue)
Same as
getBooleanValue(String)but allows to specify a default
value. |
<T extends java.lang.Enum<T>> |
getEnumValue(java.lang.String option,
java.lang.Class<T> enumType)
Get the value for an option as instance of an enumeration.
|
<T extends java.lang.Enum<T>> |
getEnumValue(java.lang.String option,
T defaultValue,
java.lang.Class<T> enumType)
Same as
getEnumValue(String, Class) but allows to specify default
value. |
float |
getFloatValue(java.lang.String option)
Get the value for an option as
float. |
int |
getIntValue(java.lang.String option)
Get the value for an option as
int. |
int |
getIntValue(java.lang.String option,
int defaultValue)
Same as
getIntValue(String)but allows to specify a default value. |
java.lang.String |
getValue(java.lang.String option)
Gets the value for a specified option.
|
java.lang.String |
getValue(java.lang.String option,
java.lang.String defaultValue)
Return the value for a specified option or a default value if option is not
present.
|
java.lang.String[] |
getValues(java.lang.String option)
Returns the space separated value of an option as array.
|
boolean |
hasBooleanValue(java.lang.String option)
Checks if the specified option is present and has a boolean value.
|
<T extends java.lang.Enum<T>> |
hasEnumValue(java.lang.String option,
java.lang.Class<T> enumType)
Checks if the specified option is present and has a legal value.
|
boolean |
hasFloatValue(java.lang.String option)
Checks if the specified option is present and has a float value.
|
boolean |
hasIntValue(java.lang.String option)
Checks if the specified option is present and has a
int value. |
boolean |
hasOption(java.lang.String option)
Checks if a specified option is present.
|
boolean |
hasValue(java.lang.String option)
Checks if specified option has a value.
|
void |
init()
Init empty
Options object. |
void |
init(java.lang.String filename)
This initalizes the
Options object by reading a properties file. |
boolean |
setOption(java.lang.String option,
java.lang.String value)
Sets and option.
|
java.lang.String |
toString()
Returns a list with key-value-pairs as string.
|
public static final int OPTION_NOT_PRESENT
countValues when trying to count values of a
non-present option.public Options()
Option object holding now options. Use methods
init(String)or setOption(String, String)to store options.public void init(java.lang.String filename) throws java.io.IOException
Options object by reading a properties file.filename - full-qualified name of the properties filejava.io.IOException - Thrown if an I/O problem is encountered while reading properties
file.public void init()
Options object. Existing options are cleared.public boolean setOption(java.lang.String option, java.lang.String value)
option - name of the optionvalue - option's value, must have same format as defined in the properties
filetrue if option was alreay present, false
otherwisepublic java.lang.String getValue(java.lang.String option)
option - the name of the optionnull value null is returned. If the option
has a space separated value list, the whole list is returned. Use
getValues(String)to access single values.public java.lang.String getValue(java.lang.String option, java.lang.String defaultValue)
option - name of the optiondefaultValue - default value to use, if option is not presentpublic java.lang.String[] getValues(java.lang.String option)
Example: For the following line in a properties file
option=value1 value2 "value 3" value4
the method returns this array
a[0] = "value1"
a[1] = "value2"
a[2] = "value 3"
a[3] = "value4"
option - name of the optionpublic boolean hasBooleanValue(java.lang.String option)
true,false, yes and
nooption - name of the optiontrue is
returned, otherwise falsepublic boolean getBooleanValue(java.lang.String option) throws Options.ValueConversionException
boolean.option - name of the optionOptions.ValueConversionException - if the option doesn't have a boolean value. Use
hasBooleanValue(String)method or default value enabled
version getBooleanValue(String, boolean)of this method
to avoid conversion problems.public <T extends java.lang.Enum<T>> T getEnumValue(java.lang.String option, java.lang.Class<T> enumType) throws Options.ValueConversionException
Typical usage is:
Colors color = options.getEnumValue("enum1", Colors.class);
where Colors is an enumeration.T - the enumerationoption - the name of the optionenumType - the enumeration typeOptions.ValueConversionException - if the option doesn't have a value of the specified enumeration.
Use hasEnumValue(String, Class)method or default value
enabled version getEnumValue(String, Enum, Class)of this
method to avoid conversion problems.public <T extends java.lang.Enum<T>> T getEnumValue(java.lang.String option, T defaultValue, java.lang.Class<T> enumType)
getEnumValue(String, Class) but allows to specify default
value.T - the enumerationoption - the name of the optionenumType - the enumeration typepublic <T extends java.lang.Enum<T>> boolean hasEnumValue(java.lang.String option, java.lang.Class<T> enumType)
option - name of the optiontrue is
returned, otherwise falsepublic int getIntValue(java.lang.String option) throws Options.ValueConversionException
int.option - name of the optionOptions.ValueConversionException - if the option doesn't have a int value. Use
hasIntValue(String)method or default value enabled
version getIntValue(String, int)of this method to avoid
conversion problems.public boolean hasIntValue(java.lang.String option)
int value.option - name of the optionint value
true is returned, otherwise falsepublic boolean getBooleanValue(java.lang.String option, boolean defaultValue)
getBooleanValue(String)but allows to specify a default
value.option - name of the optiondefaultValue - default valuepublic int getIntValue(java.lang.String option, int defaultValue)
getIntValue(String)but allows to specify a default value.option - name of the optiondefaultValue - default valuepublic boolean hasOption(java.lang.String option)
option - name of the optiontrue if option is present, false otherwisepublic boolean hasValue(java.lang.String option)
option - name of the optiontrue if option is present and has a value,
false otherwise (even if option is present but doesn't
have a value)public int countValues(java.lang.String option)
option - name of the optionpublic java.lang.String toString()
toString in class java.lang.Objectpublic float getFloatValue(java.lang.String option) throws Options.ValueConversionException
float.option - name of the optionOptions.ValueConversionException - if the option doesn't have a float value.public boolean hasFloatValue(java.lang.String option)
option - name of the optiontrue is
returned, otherwise false