Package org.apache.jorphan.util
Class Converter
java.lang.Object
org.apache.jorphan.util.Converter
Converter utilities for TestBeans
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Convert the given value object to an object of the given typestatic String
formatCalendar
(Calendar date, String pattern) Format a calendar using a given patternstatic String
formatDate
(String date, String pattern) Format a date using a given patternstatic String
formatDate
(Date date, String pattern) Format a date using a given patternstatic String
formatDate
(Calendar date, String pattern) Format a date using a given patternstatic String
formatDate
(Date date, String pattern) Format a date using a given patternstatic boolean
getBoolean
(Object o) Convert object to boolean, orfalse
if conversion failedstatic boolean
getBoolean
(Object o, boolean defaultValue) Convert object to boolean, ordefaultValue
if conversion failedstatic Calendar
Converts the given object to a calendar object.static Calendar
getCalendar
(Object date, Calendar defaultValue) Converts the given object to a calendar object.static char
Convert object to char, or ' ' if no conversion can be appliedstatic char
Convert object to char, ordefaultValue
if no conversion can be appliedstatic Date
Converts the given object to aDate
object.static Date
Converts the given object to aDate
object.static double
Convert object to double, or0
if conversion failedstatic double
Convert object to double, ordefaultValue
if conversion failedstatic File
Converts an object to aFile
static float
Convert object to float, or0
if conversion failedstatic float
Convert object to float, ordefaultValue
if conversion failedstatic int
Converts object to an integer, defaults to0
if object is not convertible or isnull
.static int
Convert object to integer, returndefaultValue
if object is not convertible or isnull
.static long
Converts object to a long, defaults to0
if object is not convertible or isnull
static long
Converts object to a long, returndefaultValue
if object is not convertible or isnull
.static String
Converts object to a String, defaults to empty string if object is null.static String
Converts object to a String, returndefaultValue
if object isnull
.static String
insertLineBreaks
(String v, String insertion) Replace newlines "\n" withinsertion
-
Constructor Details
-
Converter
public Converter()
-
-
Method Details
-
convert
Convert the given value object to an object of the given type- Parameters:
value
- object to converttoType
- type to convert object to- Returns:
- converted object or original value if no conversion could be applied
-
getCalendar
Converts the given object to a calendar object. Defaults to thedefaultValue
if the given object can't be converted. -
getCalendar
Converts the given object to a calendar object. Defaults to a calendar using the current time if the given object can't be converted.- Parameters:
o
- object that should be converted to aCalendar
- Returns:
Calendar
representing the giveno
or a newGregorianCalendar
using the current time if conversion failed
-
getDate
Converts the given object to aDate
object. Defaults to the current time if the given object can't be converted. -
getDate
Converts the given object to aDate
object. Defaults to thedefaultValue
if the given object can't be converted. -
getFloat
Convert object to float, ordefaultValue
if conversion failed- Parameters:
o
- object to convertdefaultValue
- default value to use, when conversion failed- Returns:
- converted float or
defaultValue
if conversion failed
-
getFloat
Convert object to float, or0
if conversion failed- Parameters:
o
- object to convert- Returns:
- converted float or
0
if conversion failed
-
getDouble
Convert object to double, ordefaultValue
if conversion failed- Parameters:
o
- object to convertdefaultValue
- default value to use, when conversion failed- Returns:
- converted double or
defaultValue
if conversion failed
-
getDouble
Convert object to double, or0
if conversion failed- Parameters:
o
- object to convert- Returns:
- converted double or
0
if conversion failed
-
getBoolean
Convert object to boolean, orfalse
if conversion failed- Parameters:
o
- object to convert- Returns:
- converted boolean or
false
if conversion failed
-
getBoolean
Convert object to boolean, ordefaultValue
if conversion failed- Parameters:
o
- object to convertdefaultValue
- default value to use, when conversion failed- Returns:
- converted boolean or
defaultValue
if conversion failed
-
getInt
Convert object to integer, returndefaultValue
if object is not convertible or isnull
.- Parameters:
o
- object to convertdefaultValue
- default value to be used when no conversion can be done- Returns:
- converted int or default value if conversion failed
-
getChar
Convert object to char, or ' ' if no conversion can be applied- Parameters:
o
- object to convert- Returns:
- converted char or ' ' if conversion failed
-
getChar
Convert object to char, ordefaultValue
if no conversion can be applied- Parameters:
o
- object to convertdefaultValue
- default value to use, when conversion failed- Returns:
- converted char or
defaultValue
if conversion failed
-
getInt
Converts object to an integer, defaults to0
if object is not convertible or isnull
.- Parameters:
o
- object to convert- Returns:
- converted int, or
0
if conversion failed
-
getLong
Converts object to a long, returndefaultValue
if object is not convertible or isnull
.- Parameters:
o
- object to convertdefaultValue
- default value to use, when conversion failed- Returns:
- converted long or
defaultValue
when conversion failed
-
getLong
Converts object to a long, defaults to0
if object is not convertible or isnull
- Parameters:
o
- object to convert- Returns:
- converted long or
0
if conversion failed
-
formatDate
Format a date using a given pattern- Parameters:
date
- date to formatpattern
- pattern to use for formatting- Returns:
- formatted date, or empty string if date was
null
- Throws:
IllegalArgumentException
- whenpattern
is invalid
-
formatDate
Format a date using a given pattern- Parameters:
date
- date to formatpattern
- pattern to use for formatting- Returns:
- formatted date, or empty string if date was
null
- Throws:
IllegalArgumentException
- whenpattern
is invalid
-
formatDate
Format a date using a given pattern- Parameters:
date
- date to formatpattern
- pattern to use for formatting- Returns:
- formatted date, or empty string if date was
null
- Throws:
IllegalArgumentException
- whenpattern
is invalid
-
formatDate
Format a date using a given pattern- Parameters:
date
- date to formatpattern
- pattern to use for formatting- Returns:
- formatted date, or empty string if date was
null
- Throws:
IllegalArgumentException
- whenpattern
is invalid
-
formatCalendar
Format a calendar using a given pattern- Parameters:
date
- calendar to formatpattern
- pattern to use for formatting- Returns:
- formatted date, or empty string if date was
null
- Throws:
IllegalArgumentException
- whenpattern
is invalid
-
getString
Converts object to a String, returndefaultValue
if object isnull
.- Parameters:
o
- object to convertdefaultValue
- default value to use when conversion failed- Returns:
- converted String or
defaultValue
when conversion failed
-
insertLineBreaks
Replace newlines "\n" withinsertion
- Parameters:
v
- String in which the newlines should be replacedinsertion
- new string which should be used instead of "\n"- Returns:
- new string with newlines replaced by
insertion
-
getString
Converts object to a String, defaults to empty string if object is null.- Parameters:
o
- object to convert- Returns:
- converted String or empty string when conversion failed
-
getFile
Converts an object to aFile
- Parameters:
o
- object to convert (must be aString
or aFile
)- Returns:
- converted file
- Throws:
IllegalArgumentException
- when object can not be converted
-