|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.empire.commons.ObjectUtils
public final class ObjectUtils
This class contains common functions for comparing and converting values of type Object.
Nested Class Summary | |
---|---|
static class |
ObjectUtils.NoValue
This class eplicitly defines that an Object has not been assined a value. This may be used in cases where the value of null may be a valid value. |
Field Summary | |
---|---|
static ObjectUtils.NoValue |
NO_VALUE
Constant that defines a object of type NoValue. |
Method Summary | ||
---|---|---|
static
|
coalesce(T preferred,
T alternative)
Checks whether a preferred value is valid and returns an alternative value if not. |
|
static boolean |
compareEqual(Object o1,
Object o2)
Compares two objects for equality |
|
static
|
contains(T[] array,
T item)
returns wheter or not a array contains a certain item |
|
static
|
convert(Class<T> t,
Collection<? extends T> source)
Generic conversion function that will convert a list to another list type. |
|
static
|
convert(Class<T> c,
Object v)
Generic conversion function that will convert a object to another value type. |
|
static String |
formatDate(Date date,
boolean withTime)
Formats a given date object to a standard date string. |
|
static boolean |
getBoolean(Object v)
Converts an object value to a boolean. |
|
static Date |
getDate(Object v)
Converts an object value to a Date. |
|
static Date |
getDate(Object v,
Locale locale)
Converts an object value to a Date. |
|
static BigDecimal |
getDecimal(Object v)
Converts an object value to a BigDecimal. |
|
static BigDecimal |
getDecimal(Object v,
BigDecimal defValue)
Converts an object value to a BigDecimal. |
|
static double |
getDouble(Object v)
Converts an object value to a double. |
|
static double |
getDouble(Object v,
double defValue)
Converts an object value to a double. |
|
static int |
getInteger(Object v)
Converts an object value to an integer. |
|
static int |
getInteger(Object v,
int defValue)
Converts an object value to an integer. |
|
static long |
getLong(Object v)
Converts an object value to a long. |
|
static long |
getLong(Object v,
long defValue)
Converts an object value to a long. |
|
static boolean |
isAssignmentCompatible(Class<?> target,
Class<?> source)
|
|
static boolean |
isEmpty(Object o)
Checks whether an object has no value. |
|
static String[] |
toStringArray(Object[] objArray,
String defValue)
Converts an Object array to a String array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final ObjectUtils.NoValue NO_VALUE
Method Detail |
---|
public static boolean isEmpty(Object o)
o
- the object to check
public static boolean compareEqual(Object o1, Object o2)
o1
- the first objecto2
- the second object
public static <T> T coalesce(T preferred, T alternative)
T
- the type of the valuespreferred
- the preferred return valuealternative
- the alternative return value used if the preferred value is null
public static int getInteger(Object v, int defValue)
If the object value supplied is null or if conversion is not possible then the default value is returned.
v
- the obect to convertdefValue
- the default value if o is null or conversion is not possible
public static int getInteger(Object v)
If the object value supplied is null or if conversion is not possible then 0 is returned.
v
- the object value to convert
public static long getLong(Object v, long defValue)
If the object value supplied is null or if conversion is not possible then the default value is returned.
v
- the obect to convertdefValue
- the default value if o is null or conversion is not possible
public static long getLong(Object v)
If the object value supplied is null or if conversion is not possible then 0 is returned.
v
- the object value to convert
public static double getDouble(Object v, double defValue)
If the object value supplied is null or if conversion is not possible then defValue is returned.
v
- the object value to convertdefValue
- the default value
public static double getDouble(Object v)
If the object value supplied is null or if conversion is not possible then 0.0 is returned.
v
- the object value to convert
public static BigDecimal getDecimal(Object v, BigDecimal defValue)
If the object value supplied is null or if conversion is not possible then defValue is returned.
v
- the object value to convertdefValue
- the default value
public static BigDecimal getDecimal(Object v)
If the object value supplied is null or if conversion is not possible then 0.0 is returned.
v
- the object value to convert
public static boolean getBoolean(Object v)
If the object value supplied is null or if conversion is not possible then false is returned.
v
- the object to convert
public static Date getDate(Object v, Locale locale)
If the object value supplied is null or if conversion is not possible then null is returned.
v
- the object to convertlocale
- the locale used for conversion
public static Date getDate(Object v)
v
- the object to convert
public static String formatDate(Date date, boolean withTime)
date
- the date to be formatedwithTime
- indicates whether the date string should include the time or not
public static <T> T convert(Class<T> c, Object v) throws ClassCastException
T
- the type to convert toc
- the class type to convert tov
- the object to convert
ClassCastException
- if the object is not null and is not assignable to the type T.public static boolean isAssignmentCompatible(Class<?> target, Class<?> source)
public static <T> List<T> convert(Class<T> t, Collection<? extends T> source)
T
- the type of elementst
- the type classsource
- the source collection
public static String[] toStringArray(Object[] objArray, String defValue)
objArray
- the object array to convertdefValue
- default value which will be set for all null objects
public static <T> boolean contains(T[] array, T item)
T
- the ype of the objects in the arrayarray
- the array to searchitem
- the item to search for
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |