|
TUM CCSM Commons | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.tum.cs.commons.options.Options
public class Options
This class offers a safe and flexible interface to Java properties files.
Property files must follow the format for Java properties files. See Javadoc
of Properties for details.
Properties| Nested Class Summary | |
|---|---|
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. |
| Field Summary | |
|---|---|
static int |
OPTION_NOT_PRESENT
Returned by countValues when trying to count values of a
non-present option. |
| Constructor Summary | |
|---|---|
Options()
Construct a new Option object holding now options. |
|
| Method Summary | ||
|---|---|---|
int |
countValues(String option)
Count the space separated values of an option. |
|
boolean |
getBooleanValue(String option)
Get the value for an option as boolean. |
|
boolean |
getBooleanValue(String option,
boolean defaultValue)
Same as getBooleanValue(String)but allows to specify a default
value. |
|
|
getEnumValue(String option,
Class<T> enumType)
Get the value for an option as instance of an enumeration. |
|
|
getEnumValue(String option,
T defaultValue,
Class<T> enumType)
Same as getEnumValue(String, Class) but allows to specify
default value. |
|
float |
getFloatValue(String option)
Get the value for an option as float. |
|
int |
getIntValue(String option)
Get the value for an option as int. |
|
int |
getIntValue(String option,
int defaultValue)
Same as getIntValue(String)but allows to specify a default
value. |
|
String |
getValue(String option)
Gets the value for a specified option. |
|
String |
getValue(String option,
String defaultValue)
Return the value for a specified option or a default value if option is not present. |
|
String[] |
getValues(String option)
Returns the space separated value of an option as array. |
|
boolean |
hasBooleanValue(String option)
Checks if the specified option is present and has a boolean value. |
|
|
hasEnumValue(String option,
Class<T> enumType)
Checks if the specified option is present and has a legal value. |
|
boolean |
hasFloatValue(String option)
Checks if the specified option is present and has a float value. |
|
boolean |
hasIntValue(String option)
Checks if the specified option is present and has a int
value. |
|
boolean |
hasOption(String option)
Checks if a specified option is present. |
|
boolean |
hasValue(String option)
Checks if specified option has a value. |
|
void |
init()
Init empty Options object. |
|
void |
init(String filename)
This initalizes the Options object by reading a properties
file. |
|
boolean |
setOption(String option,
String value)
Sets and option. |
|
String |
toString()
Returns a list with key-value-pairs as string. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int OPTION_NOT_PRESENT
countValues when trying to count values of a
non-present option.
| Constructor Detail |
|---|
public Options()
Option object holding now options. Use
methods init(String)or setOption(String, String)to
store options.
| Method Detail |
|---|
public void init(String filename)
throws IOException
Options object by reading a properties
file.
filename - full-qualified name of the properties file
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(String option,
String value)
option - name of the optionvalue - option's value, must have same format as defined in the
properties file
true if option was alreay present,
false otherwisepublic String getValue(String option)
option - the name of the option
null 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 String getValue(String option,
String defaultValue)
option - name of the optiondefaultValue - default value to use, if option is not present
public String[] getValues(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 option
public boolean hasBooleanValue(String option)
true,false,
yes and no
option - name of the option
true is returned, otherwise false
public boolean getBooleanValue(String option)
throws Options.ValueConversionException
boolean.
option - name of the option
Options.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 Enum<T>> T getEnumValue(String option,
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 type
Options.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 Enum<T>> T getEnumValue(String option,
T defaultValue,
Class<T> enumType)
getEnumValue(String, Class) but allows to specify
default value.
T - the enumerationoption - the name of the optionenumType - the enumeration type
public <T extends Enum<T>> boolean hasEnumValue(String option,
Class<T> enumType)
option - name of the option
true
is returned, otherwise false
public int getIntValue(String option)
throws Options.ValueConversionException
int.
option - name of the option
Options.ValueConversionException
Options.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(String option)
int
value.
option - name of the option
int value
true is returned, otherwise false
public boolean getBooleanValue(String option,
boolean defaultValue)
getBooleanValue(String)but allows to specify a default
value.
option - name of the optiondefaultValue - default value
public int getIntValue(String option,
int defaultValue)
getIntValue(String)but allows to specify a default
value.
option - name of the optiondefaultValue - default value
public boolean hasOption(String option)
option - name of the option
true if option is present, false
otherwisepublic boolean hasValue(String option)
option - name of the option
true if option is present and has a value,
false otherwise (even if option is present but
doesn't have a value)public int countValues(String option)
option - name of the option
public String toString()
toString in class Object
public float getFloatValue(String option)
throws Options.ValueConversionException
float.
option - name of the option
Options.ValueConversionException - if the option doesn't have a float value.public boolean hasFloatValue(String option)
option - name of the option
true
is returned, otherwise false
|
TUM CCSM Commons | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||