jodd.util
Class StringFlags

java.lang.Object
  extended byjodd.util.StringFlags

public class StringFlags
extends java.lang.Object

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

StringFlags

public StringFlags()
Method Detail

addFlag

public void addFlag(char c,
                    java.lang.String bpname,
                    boolean val)
Add new flag to the buffer.

Parameters:
c - character flag
bpname - name of bean property (without set or get)
val - value that will be set if character exist in the string.

clearFlags

public void clearFlags()
Clears complete flags buffer.


parse

public void parse(java.lang.String params,
                  java.lang.Object o)
Parses given string and sets the boolean properties of a bean.

Parameters:
params - option string, contains char flags
o - object to populate


Jodd v0.24.5 Javadoc