public class CommonFns extends Object
| Modifier | Constructor and Description |
|---|---|
protected |
CommonFns() |
| Modifier and Type | Method and Description |
|---|---|
static String |
formatDate(Date date,
String pattern)
Formats a Date into a date/time string.
|
static String |
formatDate(Date date,
String pattern,
Locale locale,
TimeZone timezone,
String dateStyle,
String timeStyle)
Formats a Date into a date/time string.
|
static String |
formatNumber(Object value,
String format)
Formats a number (Integer, BigDecimal...) into a string.
|
static String |
formatNumber(Object number,
String pattern,
Locale locale)
Formats a number (Integer, BigDecimal...) into a string.
|
static String |
getLabel(String key)
Returns the label or message of the specified key.
|
static String |
getLabel(String key,
Object[] args)
Returns the label of the specified key and formats it
with the specified argument, or null if not found.
|
static int |
indexOf(Object o,
Object element)
Returns the index of the given element.
|
static boolean |
isInstance(Object c,
Object o)
Tests whether an object, o, is an instance of a class, c.
|
static int |
lastIndexOf(Object o,
Object element)
Returns the last index of the given element.
|
static int |
length(Object o)
Returns the length of an array, string, collection or map.
|
static Object |
new_(Object o)
Instantiates the specified class.
|
static Object |
new_(Object o,
Object arg)
Instantiates the specified class, and argument.
|
static Object |
new_(Object o,
Object arg1,
Object arg2)
Instantiates the specified class, and two arguments.
|
static Object |
new_(Object o,
Object arg1,
Object arg2,
Object arg3)
Instantiates the specified class, and two arguments.
|
static Date |
parseDate(String source,
String pattern)
Parses text from the beginning of the given string to produce a date.
|
static Date |
parseDate(String source,
String pattern,
Locale locale,
TimeZone timezone,
String dateStyle,
String timeStyle)
Parses text from the beginning of the given string to produce a date.
|
static Number |
parseNumber(String source,
String pattern)
Parses text from the beginning of the given string to produce a number.
|
static Number |
parseNumber(String source,
String pattern,
Locale locale)
Parses text from the beginning of the given string to produce a number.
|
static boolean |
toBoolean(Object val)
Converts the specified object to a boolean.
|
static char |
toChar(Object val)
Converts the specified object to an character.
|
static BigDecimal |
toDecimal(Object val)
Converts the specified object to a (big) decimal.
|
static int |
toInt(Object val)
Converts the specified object to an integer.
|
static Number |
toNumber(Object val)
Converts the specified object to a number.
|
static String |
toString(Object val)
Converts the specified object to a string.
|
public static boolean toBoolean(Object val)
public static int toInt(Object val)
public static BigDecimal toDecimal(Object val)
public static char toChar(Object val)
public static boolean isInstance(Object c, Object o)
public static final String getLabel(String key)
Labels.getLabel(String) is called.
getLabel(String, Object[])public static final String getLabel(String key, Object[] args)
It first uses getLabel(String) to load the label.
Then, it, if not null, invokes MessageFormats.format(java.lang.String, java.lang.Object[], java.util.Locale) to format it.
The current locale is given by Locales.getCurrent().
public static final int length(Object o)
public static final int indexOf(Object o, Object element)
o - the array/collection of objects to examine, or a string.
If o is a map, then Map.keySet() is assumed.public static final int lastIndexOf(Object o, Object element)
o - the array/list of objects to examine, or a string.public static final Object new_(Object o) throws Exception
Exceptionpublic static final Object new_(Object o, Object arg) throws Exception
o - the class name or classarg - the argumentExceptionpublic static final Object new_(Object o, Object arg1, Object arg2) throws Exception
o - the class name or classarg1 - the first argumentarg2 - the second argumentExceptionpublic static final Object new_(Object o, Object arg1, Object arg2, Object arg3) throws Exception
o - the class name or classarg1 - the first argumentarg2 - the second argumentExceptionpublic static final String formatDate(Date date, String pattern)
date - the time value to be formatted into a time string.pattern - the pattern describing the date and time formatpublic static final Date parseDate(String source, String pattern) throws Exception
source - A String whose beginning should be parsed.pattern - the pattern describing the date and time formatDate parsed from the string.Exceptionpublic static final String formatNumber(Object value, String format)
A utility to assist the handling of numeric data.
value - The number to format.format - The pattern to apply, if it is null,
the system's default format is used.public static final Number parseNumber(String source, String pattern) throws Exception
source - A String whose beginning should be parsed.pattern - the pattern describing the date and time formatNumber parsed from the string.Exceptionpublic static final String formatDate(Date date, String pattern, Locale locale, TimeZone timezone, String dateStyle, String timeStyle)
date - the time value to be formatted into a time string.pattern - the pattern describing the date and time formatlocale - The Locale to apply, if it is null,
The current locale given by Locales.getCurrent() is used.timezone - the time zone to apply, if it is null,
The current timezone given by TimeZones.getCurrent() is used.dateStyle - styling index of date.timeStyle - styling index of time.public static final Date parseDate(String source, String pattern, Locale locale, TimeZone timezone, String dateStyle, String timeStyle) throws Exception
source - A String whose beginning should be parsed.pattern - the pattern describing the date and time formatlocale - The Locale to apply, if it is null,
The current locale given by Locales.getCurrent() is used.timezone - the time zone to apply, if it is null,
The current timezone given by TimeZones.getCurrent() is used.dateStyle - styling index of date.timeStyle - styling index of time.Date parsed from the string.Exceptionpublic static final String formatNumber(Object number, String pattern, Locale locale)
A utility to assist the handling of numeric data.
number - The number to format.pattern - The pattern to apply, if it is null,
the system's default format is used.locale - The Locale to apply, if it is null,
The current locale given by Locales.getCurrent() is used.public static final Number parseNumber(String source, String pattern, Locale locale) throws Exception
source - A String whose beginning should be parsed.pattern - the pattern describing the date and time formatlocale - The Locale to apply, if it is null,
The current locale given by Locales.getCurrent() is used.Number parsed from the string.ExceptionCopyright © 2018. All rights reserved.