|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjodd.util.StringFlags
Parses string and sets bean boolean parameters (flags) depending on
exisiting characters. Class may be used when methods has many boolean
parameters. In this cases, a single string can replace all those
parameters, where chars represent if some boolean property should be
set to true
or false
.
Usually, this class is instanced and configured in static block of a
class that uses it:
private static StringFlags flags = new StringFlags();
static {
flags.addFlag('p', "fooP", true);
flags.addFlag('d', "fooD", false);
}
Flags boolean values are those that properties will be set to if
coresponding character exist in option string. This means that when such
character doesn't exist in options string, its parameter will be set to
inverse value. In above example, if option string contains char 'p' then
setFooP(true) will be performed, otherwise setFooP(false) will be
performed. For the 'd' flag is opposite: if it is present in the option
string, setFooD(false) will be executed, otherwise setFooD(true) will be
executed.
Constructor Summary | |
StringFlags()
|
Method Summary | |
void |
addFlag(char c,
java.lang.String bpname,
boolean val)
Add new flag to the buffer. |
void |
clearFlags()
Clears complete flags buffer. |
void |
parse(java.lang.String params,
java.lang.Object o)
Parses given string and sets the boolean properties of a bean. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StringFlags()
Method Detail |
public void addFlag(char c, java.lang.String bpname, boolean val)
c
- character flagbpname
- name of bean property (without set or get)val
- value that will be set if character exist in the string.public void clearFlags()
public void parse(java.lang.String params, java.lang.Object o)
params
- option string, contains char flagso
- object to populate
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |