public class Converter extends Object
Constructor and Description |
---|
Converter() |
Modifier and Type | Method and Description |
---|---|
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)
Format a calendar using a given pattern
|
static String |
formatDate(Calendar date,
String pattern)
Format a date using a given pattern
|
static String |
formatDate(Date date,
String pattern)
Format a date using a given pattern
|
static String |
formatDate(Date date,
String pattern)
Format a date using a given pattern
|
static String |
formatDate(String date,
String pattern)
Format a date using a given pattern
|
static boolean |
getBoolean(Object o)
Convert object to boolean, or
false if conversion
failed |
static boolean |
getBoolean(Object o,
boolean defaultValue)
Convert object to boolean, or
defaultValue if conversion
failed |
static Calendar |
getCalendar(Object o)
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 |
getChar(Object o)
Convert object to char, or ' ' if no conversion can
be applied
|
static char |
getChar(Object o,
char defaultValue)
Convert object to char, or
defaultValue if no conversion can
be applied |
static Date |
getDate(Object date)
Converts the given object to a
Date object. |
static Date |
getDate(Object date,
Date defaultValue)
Converts the given object to a
Date object. |
static double |
getDouble(Object o)
Convert object to double, or
0 if conversion
failed |
static double |
getDouble(Object o,
double defaultValue)
Convert object to double, or
defaultValue if conversion
failed |
static File |
getFile(Object o)
Converts an object to a
File |
static float |
getFloat(Object o)
Convert object to float, or
0 if conversion
failed |
static float |
getFloat(Object o,
float defaultValue)
Convert object to float, or
defaultValue if conversion failed |
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)
Replace newlines "\n" with
insertion |
public static Object convert(Object value, Class<?> toType)
value
- object to converttoType
- type to convert object topublic static Calendar getCalendar(Object date, Calendar defaultValue)
defaultValue
if the given object can't be converted.public static Calendar getCalendar(Object o)
o
- object that should be converted to a Calendar
Calendar
representing the given o
or a new
GregorianCalendar
using the current time if conversion
failedpublic static Date getDate(Object date)
Date
object. Defaults to the
current time if the given object can't be converted.public static Date getDate(Object date, Date defaultValue)
Date
object. Defaults to the
defaultValue
if the given object can't be converted.public static float getFloat(Object o, float defaultValue)
defaultValue
if conversion failedo
- object to convertdefaultValue
- default value to use, when conversion faileddefaultValue
if conversion failedpublic static float getFloat(Object o)
0
if conversion
failedo
- object to convert0
if conversion
failedpublic static double getDouble(Object o, double defaultValue)
defaultValue
if conversion
failedo
- object to convertdefaultValue
- default value to use, when conversion faileddefaultValue
if conversion
failedpublic static double getDouble(Object o)
0
if conversion
failedo
- object to convert0
if conversion
failedpublic static boolean getBoolean(Object o)
false
if conversion
failedo
- object to convertfalse
if conversion
failedpublic static boolean getBoolean(Object o, boolean defaultValue)
defaultValue
if conversion
failedo
- object to convertdefaultValue
- default value to use, when conversion faileddefaultValue
if conversion
failedpublic static int getInt(Object o, int defaultValue)
defaultValue
if object is not
convertible or is null
.o
- object to convertdefaultValue
- default value to be used when no conversion can be donepublic static char getChar(Object o)
o
- object to convertpublic static char getChar(Object o, char defaultValue)
defaultValue
if no conversion can
be appliedo
- object to convertdefaultValue
- default value to use, when conversion faileddefaultValue
if conversion failedpublic static int getInt(Object o)
0
if object is
not convertible or is null
.o
- object to convert0
if conversion failedpublic static long getLong(Object o, long defaultValue)
defaultValue
if object is
not convertible or is null
.o
- object to convertdefaultValue
- default value to use, when conversion faileddefaultValue
when conversion
failedpublic static long getLong(Object o)
0
if object is not
convertible or is null
o
- object to convert0
if conversion failedpublic static String formatDate(Date date, String pattern)
date
- date to formatpattern
- pattern to use for formattingnull
IllegalArgumentException
- when pattern
is invalidpublic static String formatDate(Date date, String pattern)
date
- date to formatpattern
- pattern to use for formattingnull
IllegalArgumentException
- when pattern
is invalidpublic static String formatDate(String date, String pattern)
date
- date to formatpattern
- pattern to use for formattingnull
IllegalArgumentException
- when pattern
is invalidpublic static String formatDate(Calendar date, String pattern)
date
- date to formatpattern
- pattern to use for formattingnull
IllegalArgumentException
- when pattern
is invalidpublic static String formatCalendar(Calendar date, String pattern)
date
- calendar to formatpattern
- pattern to use for formattingnull
IllegalArgumentException
- when pattern
is invalidpublic static String getString(Object o, String defaultValue)
defaultValue
if object
is null
.o
- object to convertdefaultValue
- default value to use when conversion faileddefaultValue
when conversion
failedpublic static String insertLineBreaks(String v, String insertion)
insertion
v
- String in which the newlines should be replacedinsertion
- new string which should be used instead of "\n"insertion
public static String getString(Object o)
o
- object to convertCopyright © 1998-2019 Apache Software Foundation. All Rights Reserved.