|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsk.baka.tools.JavaUtils
public final class JavaUtils
Contains several utilities for classic java classes.
| Nested Class Summary | |
|---|---|
static class |
JavaUtils.BeanProperty
Contains accessors to a bean property. |
static interface |
JavaUtils.IEqualsComparator
Compares two objects. |
| Field Summary | |
|---|---|
static JavaUtils.IEqualsComparator |
COMPARATOR_EQUALS
Compares two objects using equals(java.lang.Object, java.lang.Object). |
| Method Summary | ||
|---|---|---|
static Date |
clone(Date date)
Clones given date object. |
|
static boolean |
equals(Object o1,
Object o2)
Checks that two objects are equal. |
|
static
|
equalsBean(T bean1,
T bean2)
Compares two beans. |
|
static
|
equalsBean(T bean1,
T bean2,
JavaUtils.IEqualsComparator comparator)
Compares two beans. |
|
static List<JavaUtils.BeanProperty> |
getBeanProperties(Class<?> beanClass,
boolean includeSuperclasses)
Returns all property accessors from given class, and optionally from its superclasses. |
|
static Method |
getGetter(Field field)
Returns a getter method for given field, if such a method exists in the same class. |
|
static InputStream |
getResource(String resource)
Tries to obtain an input stream for given resource. |
|
static Method |
getSetter(Field field)
Returns a setter method for given field, if such a method exists in the same class. |
|
static String |
getStacktrace(Throwable t)
Returns a stacktrace of given throwable |
|
static boolean |
isBlank(Object array)
Deprecated. use isBlankArray(java.lang.Object) |
|
static boolean |
isBlankArray(Object array)
Returns true if given array is null, zero-sized or contains only nulls. |
|
static boolean |
isEmpty(Object array)
Deprecated. use #isEmptyList(java.lang.Object) |
|
static boolean |
isEmptyArray(Object array)
Returns true if given array is null or zero-sized. |
|
static boolean |
isEnum(Class<?> clazz)
A workaround around broken Class.isEnum() which returns false for more complex enums
(enums which define abstract methods and let each constant override the method). |
|
static boolean |
isPrimitiveArray(Object array)
Checks whether given array is an array of primitives. |
|
static Properties |
loadProperties(InputStream in)
Loads properties from given input stream. |
|
static Properties |
loadProperties(String filename)
Loads properties from given file. |
|
static List<Object> |
toList(Object array)
Creates a new list and copies given array to it. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final JavaUtils.IEqualsComparator COMPARATOR_EQUALS
equals(java.lang.Object, java.lang.Object).
| Method Detail |
|---|
public static Date clone(Date date)
date - the date to clone, may be null
public static Properties loadProperties(String filename)
throws IOException
filename - the file to load the properties from.
IOException - if i/o error occurs or the file does not exist.
public static Properties loadProperties(InputStream in)
throws IOException
in - the input stream, always closed
IOException - on i/o error
public static InputStream getResource(String resource)
throws IOException
resource - the resource to read
IOException - if the resource is not found@Deprecated public static boolean isEmpty(Object array)
#isEmptyList(java.lang.Object)
CollectionsEnumerationsIterators and Iterables
array - the array to check. null array is empty by definition.
public static boolean isEmptyArray(Object array)
CollectionsEnumerationsIterators and Iterables
array - the array to check. null array is empty by definition.
@Deprecated public static boolean isBlank(Object array)
isBlankArray(java.lang.Object)
CollectionsEnumerationsIterators and Iterables
array - the array to check, may be both primitive, Object array and a Collection.
public static boolean isBlankArray(Object array)
CollectionsEnumerationsIterators and Iterables
array - the array to check, may be both primitive, Object array and a Collection.
public static boolean isPrimitiveArray(Object array)
array - an array.
public static String getStacktrace(Throwable t)
t - the throwable to return
public static boolean equals(Object o1,
Object o2)
o1 - first object, may be nullo2 - first object, may be null
public static List<Object> toList(Object array)
CollectionsEnumerationsIterators and Iterables
array - the array to convert, may be null.
public static Method getGetter(Field field)
field - a field reference.
public static Method getSetter(Field field)
field - a field reference.
public static List<JavaUtils.BeanProperty> getBeanProperties(Class<?> beanClass,
boolean includeSuperclasses)
beanClass - the bean classincludeSuperclasses - if true then class superclasses are considered as well.
public static <T> JavaUtils.BeanProperty equalsBean(T bean1,
T bean2)
Object.equals(java.lang.Object) on
field values (does not perform recursive comparison).
T - the bean typebean1 - first bean, must not be nullbean2 - second bean, must not be null
IllegalArgumentException - if beans do not have same class.
NullPointerException - if at least one of the parameter is null
public static <T> JavaUtils.BeanProperty equalsBean(T bean1,
T bean2,
JavaUtils.IEqualsComparator comparator)
T - the bean typebean1 - first bean, must not be nullbean2 - second bean, must not be nullcomparator - use this comparator when comparing bean property values.
IllegalArgumentException - if beans do not have same class.
NullPointerException - if at least one of the parameter is nullpublic static boolean isEnum(Class<?> clazz)
Class.isEnum() which returns false for more complex enums
(enums which define abstract methods and let each constant override the method).
clazz -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||