|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.velocity.tools.ConversionUtils
public class ConversionUtils
Utility methods for parsing or otherwise converting between types.
Field Summary | |
---|---|
static ConversionUtils |
INSTANCE
|
private static int |
STYLE_CURRENCY
|
private static int |
STYLE_INTEGER
|
private static int |
STYLE_NUMBER
|
private static int |
STYLE_PERCENT
|
Constructor Summary | |
---|---|
private |
ConversionUtils()
|
Method Summary | |
---|---|
static java.text.DateFormat |
getDateFormat(int dateStyle,
int timeStyle,
java.util.Locale locale,
java.util.TimeZone timezone)
Returns a DateFormat instance for the specified
time style, date style, Locale , and TimeZone . |
static java.text.DateFormat |
getDateFormat(java.lang.String format,
java.util.Locale locale,
java.util.TimeZone timezone)
Returns a DateFormat instance for the specified
format, Locale , and TimeZone . |
static java.text.DateFormat |
getDateFormat(java.lang.String dateStyle,
java.lang.String timeStyle,
java.util.Locale locale,
java.util.TimeZone timezone)
Returns a DateFormat instance for the specified
date style, time style, Locale , and TimeZone . |
static int |
getDateStyleAsInt(java.lang.String style)
Checks a string to see if it matches one of the standard DateFormat style patterns: full, long, medium, short, or default. |
ConversionUtils |
getInstance()
|
static java.text.NumberFormat |
getNumberFormat(int numberStyle,
java.util.Locale locale)
Returns a NumberFormat instance for the specified
number style and Locale . |
static java.text.NumberFormat |
getNumberFormat(java.lang.String format,
java.util.Locale locale)
Returns a NumberFormat instance for the specified
format and Locale . |
static int |
getNumberStyleAsInt(java.lang.String style)
Checks a string to see if it matches one of the standard NumberFormat style patterns: number, currency, percent, integer, or default. |
static java.util.Calendar |
toCalendar(java.util.Date date,
java.util.Locale locale)
|
static java.util.Date |
toDate(java.lang.Object obj)
Attempts to convert an unidentified Object into a Date ,
just short of turning it into a string and parsing it. |
static java.util.Date |
toDate(java.lang.Object obj,
java.lang.String format,
java.util.Locale locale,
java.util.TimeZone timezone)
Converts an object to an instance of Date using the
specified format, Locale , and TimeZone if the
object is not already an instance of Date, Calendar, or Long. |
static java.util.Date |
toDate(java.lang.String str,
java.lang.String format,
java.util.Locale locale,
java.util.TimeZone timezone)
Converts an object to an instance of Date using the
specified format, Locale , and TimeZone if the
object is not already an instance of Date, Calendar, or Long. |
static java.util.Locale |
toLocale(java.lang.String value)
Converts a string to a Locale |
static java.lang.Number |
toNumber(java.lang.Object obj)
Attempts to convert an unidentified Object into a Number ,
just short of turning it into a string and parsing it. |
static java.lang.Number |
toNumber(java.lang.Object value,
java.lang.String format,
java.util.Locale locale)
Converts an object to an instance of Number using the
specified format and Locale to parse it, if necessary. |
static java.lang.Number |
toNumber(java.lang.String value,
java.lang.String format,
java.util.Locale locale)
Converts a string to an instance of Number using the
specified format and Locale to parse it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final ConversionUtils INSTANCE
private static final int STYLE_NUMBER
private static final int STYLE_CURRENCY
private static final int STYLE_PERCENT
private static final int STYLE_INTEGER
Constructor Detail |
---|
private ConversionUtils()
Method Detail |
---|
public ConversionUtils getInstance()
public static java.text.NumberFormat getNumberFormat(java.lang.String format, java.util.Locale locale)
NumberFormat
instance for the specified
format and Locale
. If the format specified is a standard
style pattern, then a number instance
will be returned with the number style set to the
specified style. If it is a custom format, then a customized
NumberFormat
will be returned.
format
- the custom or standard formatting pattern to be usedlocale
- the Locale
to be used
NumberFormat
NumberFormat
public static java.text.NumberFormat getNumberFormat(int numberStyle, java.util.Locale locale)
NumberFormat
instance for the specified
number style and Locale
.
numberStyle
- the number style (number will be ignored if this is
less than zero or the number style is not recognized)locale
- the Locale
to be used
NumberFormat
or null
if an instance cannot be constructed with the given
parameterspublic static int getNumberStyleAsInt(java.lang.String style)
style
- the string to be checked
NumberFormat
public static java.lang.Number toNumber(java.lang.Object obj)
Object
into a Number
,
just short of turning it into a string and parsing it. In other words,
this will convert to Number
from a Number
, Calendar
,
or Date
. If it can't do that, it will return null
.
obj
- - the object to convertpublic static java.lang.Number toNumber(java.lang.String value, java.lang.String format, java.util.Locale locale)
Number
using the
specified format and Locale
to parse it.
value
- - the string to convertformat
- - the format the number is inlocale
- - the Locale
Number
or null
if no
conversion is possibleNumberFormat.parse(java.lang.String, java.text.ParsePosition)
public static java.lang.Number toNumber(java.lang.Object value, java.lang.String format, java.util.Locale locale)
Number
using the
specified format and Locale
to parse it, if necessary.
value
- - the object to convertformat
- - the format the number is inlocale
- - the Locale
Number
or null
if no
conversion is possibleNumberFormat.parse(java.lang.String, java.text.ParsePosition)
public static java.text.DateFormat getDateFormat(java.lang.String format, java.util.Locale locale, java.util.TimeZone timezone)
DateFormat
instance for the specified
format, Locale
, and TimeZone
. If the format
specified is a standard style pattern, then a date-time instance
will be returned with both the date and time styles set to the
specified style. If it is a custom format, then a customized
SimpleDateFormat
will be returned.
format
- the custom or standard formatting pattern to be usedlocale
- the Locale
to be usedtimezone
- the TimeZone
to be used
DateFormat
SimpleDateFormat
,
DateFormat
public static java.text.DateFormat getDateFormat(java.lang.String dateStyle, java.lang.String timeStyle, java.util.Locale locale, java.util.TimeZone timezone)
DateFormat
instance for the specified
date style, time style, Locale
, and TimeZone
.
dateStyle
- the date styletimeStyle
- the time stylelocale
- the Locale
to be usedtimezone
- the TimeZone
to be used
DateFormat
getDateFormat(int timeStyle, int dateStyle, Locale locale, TimeZone timezone)
public static java.text.DateFormat getDateFormat(int dateStyle, int timeStyle, java.util.Locale locale, java.util.TimeZone timezone)
DateFormat
instance for the specified
time style, date style, Locale
, and TimeZone
.
dateStyle
- the date style (date will be ignored if this is
less than zero and the date style is not)timeStyle
- the time style (time will be ignored if this is
less than zero and the date style is not)locale
- the Locale
to be usedtimezone
- the TimeZone
to be used
DateFormat
or null
if an instance cannot be constructed with the given
parameterspublic static int getDateStyleAsInt(java.lang.String style)
style
- the string to be checked
DateFormat
public static java.util.Date toDate(java.lang.Object obj)
Object
into a Date
,
just short of turning it into a string and parsing it. In other words,
this will convert to Date
from a Date
, Calendar
,
or Number
. If it can't do that, it will return null
.
obj
- - the object to convertpublic static java.util.Date toDate(java.lang.Object obj, java.lang.String format, java.util.Locale locale, java.util.TimeZone timezone)
Date
using the
specified format, Locale
, and TimeZone
if the
object is not already an instance of Date, Calendar, or Long.
obj
- - the date to convertformat
- - the format the date is inlocale
- - the Locale
timezone
- - the TimeZone
Date
or null
if no
conversion is possiblegetDateFormat(java.lang.String, java.util.Locale, java.util.TimeZone)
,
SimpleDateFormat.parse(java.lang.String, java.text.ParsePosition)
public static java.util.Date toDate(java.lang.String str, java.lang.String format, java.util.Locale locale, java.util.TimeZone timezone)
Date
using the
specified format, Locale
, and TimeZone
if the
object is not already an instance of Date, Calendar, or Long.
str
- - the string to parseformat
- - the format the date is inlocale
- - the Locale
timezone
- - the TimeZone
Date
or null
if the
parsing failsgetDateFormat(java.lang.String, java.util.Locale, java.util.TimeZone)
,
SimpleDateFormat.parse(java.lang.String, java.text.ParsePosition)
public static java.util.Calendar toCalendar(java.util.Date date, java.util.Locale locale)
public static java.util.Locale toLocale(java.lang.String value)
Locale
value
- - the string to parse
Locale
or null
if the
parsing fails
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |