org.apache.jorphan.util

Class Converter


public class Converter
extends Object

Converter utilities for TestBeans

Method Summary

static Object
convert(Object value, Class toType)
Convert the given value object to an object of the given type
static String
formatCalendar(Calendar date, String pattern)
static String
formatDate(Calendar date, String pattern)
static String
formatDate(Date date, String pattern)
static String
formatDate(String date, String pattern)
static String
formatDate(Date date, String pattern)
String
formatNumber(float num, String pattern)
static boolean
getBoolean(Object o)
static boolean
getBoolean(Object o, boolean defaultValue)
static Calendar
getCalendar(Object o)
static Calendar
getCalendar(Object date, Calendar defaultValue)
Converts the given object to a calendar object.
static char
getChar(Object o)
static char
getChar(Object o, char defaultValue)
static Date
getDate(Object date)
static Date
getDate(Object date, Date defaultValue)
static double
getDouble(Object o)
static double
getDouble(Object o, double defaultValue)
static float
getFloat(Object o)
static float
getFloat(Object o, float defaultValue)
static int
getInt(Object o)
Converts object to an integer, defaults to 0 if object is not convertible or is null.
static int
getInt(Object o, int defaultValue)
Convert object to integer, return defaultValue if object is not convertible or is null.
static long
getLong(Object o)
Converts object to a long, defaults to 0 if object is not convertible or is null
static long
getLong(Object o, long defaultValue)
Converts object to a long, return defaultValue if object is not convertible or is null.
static String
getString(Object o)
Converts object to a String, defaults to empty string if object is null.
static String
getString(Object o, String defaultValue)
Converts object to a String, return defaultValue if object is null.
static String
insertLineBreaks(String v, String insertion)
static String
urlEncode(Object toEncode)

Method Details

convert

public static Object convert(Object value,
                             Class toType)
Convert the given value object to an object of the given type
Parameters:
value -
toType -
Returns:
Object

formatCalendar

public static String formatCalendar(Calendar date,
                                    String pattern)

formatDate

public static String formatDate(Calendar date,
                                String pattern)

formatDate

public static String formatDate(Date date,
                                String pattern)

formatDate

public static String formatDate(String date,
                                String pattern)

formatDate

public static String formatDate(Date date,
                                String pattern)

formatNumber

public String formatNumber(float num,
                           String pattern)

getBoolean

public static boolean getBoolean(Object o)

getBoolean

public static boolean getBoolean(Object o,
                                 boolean defaultValue)

getCalendar

public static Calendar getCalendar(Object o)

getCalendar

public static Calendar getCalendar(Object date,
                                   Calendar defaultValue)
Converts the given object to a calendar object. Defaults to the current date if the given object can't be converted.
Parameters:
date -
Returns:
Calendar

getChar

public static char getChar(Object o)

getChar

public static char getChar(Object o,
                           char defaultValue)

getDate

public static Date getDate(Object date)

getDate

public static Date getDate(Object date,
                           Date defaultValue)

getDouble

public static double getDouble(Object o)

getDouble

public static double getDouble(Object o,
                               double defaultValue)

getFloat

public static float getFloat(Object o)

getFloat

public static float getFloat(Object o,
                             float defaultValue)

getInt

public static int getInt(Object o)
Converts object to an integer, defaults to 0 if object is not convertible or is null.
Parameters:
o -
Returns:
int

getInt

public static int getInt(Object o,
                         int defaultValue)
Convert object to integer, return defaultValue if object is not convertible or is null.
Parameters:
o -
defaultValue -
Returns:
int

getLong

public static long getLong(Object o)
Converts object to a long, defaults to 0 if object is not convertible or is null
Parameters:
o -
Returns:
long

getLong

public static long getLong(Object o,
                           long defaultValue)
Converts object to a long, return defaultValue if object is not convertible or is null.
Parameters:
o -
defaultValue -
Returns:
long

getString

public static String getString(Object o)
Converts object to a String, defaults to empty string if object is null.
Parameters:
o -
Returns:
String

getString

public static String getString(Object o,
                               String defaultValue)
Converts object to a String, return defaultValue if object is null.
Parameters:
o -
defaultValue -
Returns:
String

insertLineBreaks

public static String insertLineBreaks(String v,
                                      String insertion)

urlEncode

public static String urlEncode(Object toEncode)

Copyright © 1998-2010 Apache Software Foundation. All Rights Reserved.