Package org.apache.jorphan.util
Class Converter
java.lang.Object
org.apache.jorphan.util.Converter
Converter utilities for TestBeans
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic ObjectConvert the given value object to an object of the given typestatic StringformatCalendar(Calendar date, String pattern) Format a calendar using a given patternstatic StringformatDate(String date, String pattern) Format a date using a given patternstatic StringformatDate(Date date, String pattern) Format a date using a given patternstatic StringformatDate(Calendar date, String pattern) Format a date using a given patternstatic StringformatDate(Date date, String pattern) Format a date using a given patternstatic booleangetBoolean(Object o) Convert object to boolean, orfalseif conversion failedstatic booleangetBoolean(Object o, boolean defaultValue) Convert object to boolean, ordefaultValueif conversion failedstatic CalendarConverts the given object to a calendar object.static CalendargetCalendar(Object date, Calendar defaultValue) Converts the given object to a calendar object.static charConvert object to char, or ' ' if no conversion can be appliedstatic charConvert object to char, ordefaultValueif no conversion can be appliedstatic DateConverts the given object to aDateobject.static DateConverts the given object to aDateobject.static doubleConvert object to double, or0if conversion failedstatic doubleConvert object to double, ordefaultValueif conversion failedstatic FileConverts an object to aFilestatic floatConvert object to float, or0if conversion failedstatic floatConvert object to float, ordefaultValueif conversion failedstatic intConverts object to an integer, defaults to0if object is not convertible or isnull.static intConvert object to integer, returndefaultValueif object is not convertible or isnull.static longConverts object to a long, defaults to0if object is not convertible or isnullstatic longConverts object to a long, returndefaultValueif object is not convertible or isnull.static StringConverts object to a String, defaults to empty string if object is null.static StringConverts object to a String, returndefaultValueif object isnull.static StringinsertLineBreaks(String v, String insertion) Replace newlines "\n" withinsertion
- 
Constructor Details- 
Converterpublic Converter()
 
- 
- 
Method Details- 
convertConvert the given value object to an object of the given type- Parameters:
- value- object to convert
- toType- type to convert object to
- Returns:
- converted object or original value if no conversion could be applied
 
- 
getCalendarConverts the given object to a calendar object. Defaults to thedefaultValueif the given object can't be converted.
- 
getCalendarConverts 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 a- Calendar
- Returns:
- Calendarrepresenting the given- oor a new- GregorianCalendarusing the current time if conversion failed
 
- 
getDateConverts the given object to aDateobject. Defaults to the current time if the given object can't be converted.
- 
getDateConverts the given object to aDateobject. Defaults to thedefaultValueif the given object can't be converted.
- 
getFloatConvert object to float, ordefaultValueif conversion failed- Parameters:
- o- object to convert
- defaultValue- default value to use, when conversion failed
- Returns:
- converted float or defaultValueif conversion failed
 
- 
getFloatConvert object to float, or0if conversion failed- Parameters:
- o- object to convert
- Returns:
- converted float or 0if conversion failed
 
- 
getDoubleConvert object to double, ordefaultValueif conversion failed- Parameters:
- o- object to convert
- defaultValue- default value to use, when conversion failed
- Returns:
- converted double or defaultValueif conversion failed
 
- 
getDoubleConvert object to double, or0if conversion failed- Parameters:
- o- object to convert
- Returns:
- converted double or 0if conversion failed
 
- 
getBooleanConvert object to boolean, orfalseif conversion failed- Parameters:
- o- object to convert
- Returns:
- converted boolean or falseif conversion failed
 
- 
getBooleanConvert object to boolean, ordefaultValueif conversion failed- Parameters:
- o- object to convert
- defaultValue- default value to use, when conversion failed
- Returns:
- converted boolean or defaultValueif conversion failed
 
- 
getIntConvert object to integer, returndefaultValueif object is not convertible or isnull.- Parameters:
- o- object to convert
- defaultValue- default value to be used when no conversion can be done
- Returns:
- converted int or default value if conversion failed
 
- 
getCharConvert object to char, or ' ' if no conversion can be applied- Parameters:
- o- object to convert
- Returns:
- converted char or ' ' if conversion failed
 
- 
getCharConvert object to char, ordefaultValueif no conversion can be applied- Parameters:
- o- object to convert
- defaultValue- default value to use, when conversion failed
- Returns:
- converted char or defaultValueif conversion failed
 
- 
getIntConverts object to an integer, defaults to0if object is not convertible or isnull.- Parameters:
- o- object to convert
- Returns:
- converted int, or 0if conversion failed
 
- 
getLongConverts object to a long, returndefaultValueif object is not convertible or isnull.- Parameters:
- o- object to convert
- defaultValue- default value to use, when conversion failed
- Returns:
- converted long or defaultValuewhen conversion failed
 
- 
getLongConverts object to a long, defaults to0if object is not convertible or isnull- Parameters:
- o- object to convert
- Returns:
- converted long or 0if conversion failed
 
- 
formatDateFormat a date using a given pattern- Parameters:
- date- date to format
- pattern- pattern to use for formatting
- Returns:
- formatted date, or empty string if date was null
- Throws:
- IllegalArgumentException- when- patternis invalid
 
- 
formatDateFormat a date using a given pattern- Parameters:
- date- date to format
- pattern- pattern to use for formatting
- Returns:
- formatted date, or empty string if date was null
- Throws:
- IllegalArgumentException- when- patternis invalid
 
- 
formatDateFormat a date using a given pattern- Parameters:
- date- date to format
- pattern- pattern to use for formatting
- Returns:
- formatted date, or empty string if date was null
- Throws:
- IllegalArgumentException- when- patternis invalid
 
- 
formatDateFormat a date using a given pattern- Parameters:
- date- date to format
- pattern- pattern to use for formatting
- Returns:
- formatted date, or empty string if date was null
- Throws:
- IllegalArgumentException- when- patternis invalid
 
- 
formatCalendarFormat a calendar using a given pattern- Parameters:
- date- calendar to format
- pattern- pattern to use for formatting
- Returns:
- formatted date, or empty string if date was null
- Throws:
- IllegalArgumentException- when- patternis invalid
 
- 
getStringConverts object to a String, returndefaultValueif object isnull.- Parameters:
- o- object to convert
- defaultValue- default value to use when conversion failed
- Returns:
- converted String or defaultValuewhen conversion failed
 
- 
insertLineBreaksReplace newlines "\n" withinsertion- Parameters:
- v- String in which the newlines should be replaced
- insertion- new string which should be used instead of "\n"
- Returns:
- new string with newlines replaced by insertion
 
- 
getStringConverts 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
 
- 
getFileConverts an object to aFile- Parameters:
- o- object to convert (must be a- Stringor a- File)
- Returns:
- converted file
- Throws:
- IllegalArgumentException- when object can not be converted
 
 
-