TagLib documentation

org.alweb.doff.util
Class Parameter

java.lang.Object
  extended by org.alweb.doff.util.Parameter
All Implemented Interfaces:
Serializable, Comparable<Object>

public class Parameter
extends Object
implements Serializable, Comparable<Object>

Represents an untyped parameter and provides a way to converts easily a string into primitive types. Value specified at constructor will be automatically trimmed (unless null).

Author:
Alexis Toulotte
See Also:
Serialized Form

Field Summary
static Parameter EMPTY_PARAMETER
          Represents an empty parameter, with null as value.
 
Constructor Summary
Parameter(String value)
          Constructs a new parameter from its value.
 
Method Summary
 int compareTo(Object other)
           
 boolean equals(Object other)
           
 boolean exists()
          Determines if this parameter exists (has a value).
static ParameterConverter getConverter()
          Returns the parameter converter.
static void setConverter(ParameterConverter converter)
          Sets the parameter converter for the entire application.
<T> T
to(Class<T> type)
          Tries to converts this parameter to specified type with null as default value.
<T> T
to(Class<T> type, T defaultValue)
           Tries to converts this parameter to specified type with specified default value.
 boolean toBoolean()
          Tries to convert this parameter value to a Boolean.
 Boolean toBoolean(Boolean defaultValue)
          Tries to convert this parameter value to a Boolean.
 Date toDate()
          Tries to convert this parameter value as a Date.
 Date toDate(DateFormat format)
          Tries to convert this parameter value as a Date.
 Date toDate(DateFormat format, Date defaultValue)
          Tries to convert this parameter value as a Date.
 double toDouble()
          Tries to convert this parameter value as Double format.
 Double toDouble(Double defaultValue)
          Tries to convert this parameter value as Double format.
<T extends Enum<T>>
T
toEnum(Class<T> enumType)
          Tries to convert this parameter value as an Enum.
<T extends Enum<T>>
T
toEnum(Class<T> enumType, T defaultValue)
          Tries to convert this parameter value as an Enum.
 int toInt()
          Tries to convert this parameter value as Integer format.
 Integer toInt(Integer defaultValue)
          Tries to convert this parameter value as Integer format.
 List<Parameter> toList()
          Tries to convert this parameter as a List of parameter with those delimiters: ,; \t\n
<T> List<T>
toList(Class<T> type)
          Tries to converts this parameter to a list of specified elements type.
<T> List<T>
toList(Class<T> type, String delimiters)
          Tries to converts this parameter to a list of specified elements type with specified delimiters.
 List<Parameter> toList(String delimiters)
          Tries to convert this parameter as a List of parameter with specified delimiters.
 long toLong()
          Tries to convert this parameter value as Long format.
 Long toLong(Long defaultValue)
          Tries to convert this parameter value as Long format.
 String toString()
          Provides a string representation of this parameter.
 String toString(boolean trimmed)
          Provides a string representation of this parameter.
 String toString(String defaultValue)
          Provides a String representation of this parameter.
 String toString(String defaultValue, boolean trimmed)
          Provides a string representation of this parameter.
 URL toURL()
          Tries to converts this parameter to an URL.
 URL toURL(URL defaultValue)
          Tries to converts this parameter to an URL.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_PARAMETER

public static final Parameter EMPTY_PARAMETER
Represents an empty parameter, with null as value. Use this constant instead of creating a new one.

Constructor Detail

Parameter

public Parameter(String value)
Constructs a new parameter from its value. A null value means that parameter doesn't exists.

See Also:
exists()
Method Detail

getConverter

public static final ParameterConverter getConverter()
Returns the parameter converter. Default value is false.

Since:
1.4.2
See Also:
setConverter(ParameterConverter)

setConverter

public static final void setConverter(ParameterConverter converter)
Sets the parameter converter for the entire application. Parameter converters are able to convert parameters into any class. This method is synchronized.

Since:
1.4.2

compareTo

public int compareTo(Object other)
Specified by:
compareTo in interface Comparable<Object>

equals

public boolean equals(Object other)
Overrides:
equals in class Object

exists

public boolean exists()
Determines if this parameter exists (has a value). This method returns false if value specified at the constructor is null, true otherwise.

See Also:
Parameter(String)

to

public <T> T to(Class<T> type)
Tries to converts this parameter to specified type with null as default value.

Throws:
IllegalArgumentException - if type is not supported.
Since:
1.4.2
See Also:
setConverter(ParameterConverter)

to

public <T> T to(Class<T> type,
                T defaultValue)

Tries to converts this parameter to specified type with specified default value.

Supported types are: Parameter, String, Integer, Long, Double, Boolean, Date, List, URL and Enum.

If specified type is not supported the converted is checked.

Throws:
IllegalArgumentException - if type is not supported.
Since:
1.4.2
See Also:
setConverter(ParameterConverter)

toBoolean

public boolean toBoolean()
Tries to convert this parameter value to a Boolean. The default value (if doesn't exists or malformed) is false. True texts are: "true", "yes", "on" and "1". False texts are: "false", "no", "off" and "0".

See Also:
toBoolean(Boolean)

toBoolean

public Boolean toBoolean(Boolean defaultValue)
Tries to convert this parameter value to a Boolean. True texts are: "true", "yes", "on" and "1". False texts are: "false", "no", "off" and "0".

Parameters:
defaultValue - The default value if parameter doesn't exists or doesn't represents a boolean.

toDate

public Date toDate()
Tries to convert this parameter value as a Date. The default value is null and the date format is "yyyy-MM-dd".

Since:
1.0
See Also:
toDate(DateFormat)

toDate

public Date toDate(DateFormat format)
Tries to convert this parameter value as a Date. The default value is null.

Parameters:
format - The format used for parsing the date.
Throws:
NullPointerException - if specified format is null.
Since:
1.0
See Also:
toDate(DateFormat, Date)

toDate

public Date toDate(DateFormat format,
                   Date defaultValue)
Tries to convert this parameter value as a Date.

Parameters:
format - The format used for parsing the date.
defaultValue - The default value if date is malformed.
Throws:
NullPointerException - if specified format is null.
Since:
1.0
See Also:
DateFormat.parse(String)

toDouble

public double toDouble()
Tries to convert this parameter value as Double format. The default value is 0.

See Also:
toDouble(Double)

toDouble

public Double toDouble(Double defaultValue)
Tries to convert this parameter value as Double format.

Parameters:
defaultValue - The default value if parameter doesn't exists or doesn't represents a double.
See Also:
Double.parseDouble(String)

toEnum

public <T extends Enum<T>> T toEnum(Class<T> enumType)
Tries to convert this parameter value as an Enum. Enumeration values must be in upper case. The default value (if missing or malformed) is null.

Parameters:
enumType - The type of the enum.
Throws:
NullPointerException - if specified type is null.
Since:
1.1

toEnum

public <T extends Enum<T>> T toEnum(Class<T> enumType,
                                    T defaultValue)
Tries to convert this parameter value as an Enum. Enumeration values must be in upper case.

Parameters:
enumType - The type of the enum.
defaultValue - The default value if malformed or missing.
Throws:
NullPointerException - if specified type is null.
Since:
1.1

toInt

public int toInt()
Tries to convert this parameter value as Integer format. The default value is 0.

See Also:
toInt(Integer)

toInt

public Integer toInt(Integer defaultValue)
Tries to convert this parameter value as Integer format.

Parameters:
defaultValue - The default value if parameter doesn't exists or doesn't represents an integer.
See Also:
Integer.parseInt(String)

toList

public List<Parameter> toList()
Tries to convert this parameter as a List of parameter with those delimiters: ,; \t\n

Since:
1.3.5
See Also:
toList(String)

toList

public <T> List<T> toList(Class<T> type)
Tries to converts this parameter to a list of specified elements type.

Throws:
NullPointerException - if specified type is null.
Since:
1.4.2
See Also:
toList(Class, String)

toList

public <T> List<T> toList(Class<T> type,
                          String delimiters)
Tries to converts this parameter to a list of specified elements type with specified delimiters.

Throws:
NullPointerException - if specified type is null.
Since:
1.4.2
See Also:
StringTokenizer

toList

public List<Parameter> toList(String delimiters)
Tries to convert this parameter as a List of parameter with specified delimiters.

Since:
1.3.5

toLong

public long toLong()
Tries to convert this parameter value as Long format. The default value is 0.

See Also:
toLong(Long)

toLong

public Long toLong(Long defaultValue)
Tries to convert this parameter value as Long format.

Parameters:
defaultValue - The default value if parameter doesn't exists or doesn't represents a long.
See Also:
Long.parseLong(String)

toString

public String toString()
Provides a string representation of this parameter.

Overrides:
toString in class Object
Returns:
The value specified at the constructor (trimmed) or an empty string if the value is null.
See Also:
toString(String, boolean)

toString

public String toString(boolean trimmed)
Provides a string representation of this parameter.

Parameters:
trimmed - true in order to trim the value, false otherwise.
Returns:
The value trimmed if specified or an empty string if paramter doesn't exists.
Since:
1.4
See Also:
toString(String, boolean)

toString

public String toString(String defaultValue)
Provides a String representation of this parameter.

Parameters:
defaultValue - The default value if this parameter doesn't exists.
Returns:
The value trimmed or the default value of if this paramter doesn't exists.
See Also:
toString(String, boolean)

toString

public String toString(String defaultValue,
                       boolean trimmed)
Provides a string representation of this parameter.

Parameters:
defaultValue - The default value if this parameter doesn't exists.
trimmed - true in order to trim the value, false otherwise.
Returns:
The value trimmed if specified or an empty string if paramter doesn't exists.
Since:
1.4
See Also:
exists()

toURL

public URL toURL()
Tries to converts this parameter to an URL. The default value if URL is malformed is null

Since:
1.4.2

toURL

public URL toURL(URL defaultValue)
Tries to converts this parameter to an URL. You can specify a default value if URL is malformed.

Since:
1.4.2

TagLib documentation