|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.joda.beans.JodaBeanUtils
public final class JodaBeanUtils
A set of utilities to assist when working with beans and properties.
| Method Summary | ||
|---|---|---|
static Iterator<Bean> |
beanIterator(Bean bean)
Returns an iterator over all the beans contained within the bean. |
|
static
|
clone(T original)
Clones a bean. |
|
static
|
cloneAlways(T original)
Clones a bean always. |
|
static Class<?> |
collectionType(MetaProperty<?> prop,
Class<?> targetClass)
Extracts the collection content type as a Class from a meta-property. |
|
static Class<?> |
collectionType(Property<?> prop)
Extracts the collection content type as a Class from a property. |
|
static List<Class<?>> |
collectionTypeTypes(MetaProperty<?> prop,
Class<?> targetClass)
Extracts the map value type generic type parameters as a Class from a meta-property. |
|
static Comparator<Bean> |
comparator(BeanQuery<?> query,
boolean ascending)
Obtains a comparator for the specified bean query. |
|
static Comparator<Bean> |
comparatorAscending(BeanQuery<?> query)
Obtains an ascending comparator for the specified bean query. |
|
static Comparator<Bean> |
comparatorDescending(BeanQuery<?> query)
Obtains an descending comparator for the specified bean query. |
|
static boolean |
equal(double val1,
double val2)
Checks if two doubles are equal based on identity. |
|
static boolean |
equal(float val1,
float val2)
Checks if two floats are equal based on identity. |
|
static boolean |
equal(Object obj1,
Object obj2)
Checks if two objects are equal handling null. |
|
static boolean |
equalIgnoring(Bean bean1,
Bean bean2,
MetaProperty<?>... properties)
Checks if two beans are equal ignoring one or more properties. |
|
static boolean |
equalWithTolerance(double val1,
double val2,
double tolerance)
Checks if two doubles are equal within the specified tolerance. |
|
static boolean |
equalWithTolerance(float val1,
float val2,
double tolerance)
Checks if two floats are equal within the specified tolerance. |
|
static Class<?> |
extractTypeClass(MetaProperty<?> prop,
Class<?> targetClass,
int size,
int index)
Low-level method to extract generic type information. |
|
static int |
hashCode(boolean value)
Returns a hash code for a boolean. |
|
static int |
hashCode(double value)
Returns a hash code for a double. |
|
static int |
hashCode(float value)
Returns a hash code for a float. |
|
static int |
hashCode(int value)
Returns a hash code for an int. |
|
static int |
hashCode(long value)
Returns a hash code for a long. |
|
static int |
hashCode(Object obj)
Returns a hash code for an object handling null. |
|
static Class<?> |
mapKeyType(MetaProperty<?> prop,
Class<?> targetClass)
Extracts the map key type as a Class from a meta-property. |
|
static Class<?> |
mapKeyType(Property<?> prop)
Extracts the map key type as a Class from a meta-property. |
|
static Class<?> |
mapValueType(MetaProperty<?> prop,
Class<?> targetClass)
Extracts the map value type as a Class from a meta-property. |
|
static Class<?> |
mapValueType(Property<?> prop)
Extracts the map value type as a Class from a meta-property. |
|
static List<Class<?>> |
mapValueTypeTypes(MetaProperty<?> prop,
Class<?> targetClass)
Extracts the map value type generic type parameters as a Class from a meta-property. |
|
static MetaBean |
metaBean(Class<?> cls)
Gets the meta-bean for a class. |
|
static void |
notEmpty(Collection<?> value,
String propertyName)
Checks if the collection value is not empty, throwing an exception if it is. |
|
static void |
notEmpty(Map<?,?> value,
String propertyName)
Checks if the map value is not empty, throwing an exception if it is. |
|
static void |
notEmpty(String value,
String propertyName)
Checks if the value is not empty, throwing an exception if it is. |
|
static void |
notNull(Object value,
String propertyName)
Checks if the value is not null, throwing an exception if it is. |
|
static boolean |
propertiesEqual(Bean bean1,
Bean bean2)
Checks if the two beans have the same set of properties. |
|
static int |
propertiesHashCode(Bean bean)
Returns a hash code based on the set of properties on a bean. |
|
static String |
propertiesToString(Bean bean,
String prefix)
Returns a string describing the set of properties on a bean. |
|
static void |
registerMetaBean(MetaBean metaBean)
Registers a meta-bean. |
|
static org.joda.convert.StringConvert |
stringConverter()
Gets the standard string format converter. |
|
static String |
toString(Object obj)
Returns the toString value handling arrays. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static MetaBean metaBean(Class<?> cls)
This only works for those beans that have registered their meta-beans.
See registerMetaBean(MetaBean).
A Class may use a static initializer block to call registerMetaBean.
The edge case where the class is loaded but not initialized is handled
by forcing the class to be initialized if necessary.
cls - the class to get the meta-bean for, not null
IllegalArgumentException - if unable to obtain the meta-beanpublic static void registerMetaBean(MetaBean metaBean)
This should be done for all beans in a static factory where possible. If the meta-bean is dynamic, this method should not be called.
metaBean - the meta-bean, not null
IllegalArgumentException - if unable to registerpublic static org.joda.convert.StringConvert stringConverter()
This returns a singleton that may be mutated (holds a concurrent map). New conversions should be registered at program startup.
public static boolean equal(Object obj1,
Object obj2)
obj1 - the first object, may be nullobj2 - the second object, may be null
public static boolean equal(float val1,
float val2)
This performs the same check as Float.equals(Object).
val1 - the first value, may be nullval2 - the second value, may be null
public static boolean equalWithTolerance(float val1,
float val2,
double tolerance)
Two NaN values are equal. Positive and negative infinity are only equal with themselves. Otherwise, the difference between the values is compared to the tolerance.
val1 - the first value, may be nullval2 - the second value, may be nulltolerance - the tolerance used to compare equal
public static boolean equal(double val1,
double val2)
This performs the same check as Double.equals(Object).
val1 - the first value, may be nullval2 - the second value, may be null
public static boolean equalWithTolerance(double val1,
double val2,
double tolerance)
Two NaN values are equal. Positive and negative infinity are only equal with themselves. Otherwise, the difference between the values is compared to the tolerance. The tolerance is expected to be a finite value, not NaN or infinity.
val1 - the first value, may be nullval2 - the second value, may be nulltolerance - the tolerance used to compare equal
public static int hashCode(Object obj)
obj - the object, may be null
public static int hashCode(boolean value)
boolean.
value - the value to convert to a hash code
public static int hashCode(int value)
int.
value - the value to convert to a hash code
public static int hashCode(long value)
long.
value - the value to convert to a hash code
public static int hashCode(float value)
float.
value - the value to convert to a hash code
public static int hashCode(double value)
double.
value - the value to convert to a hash code
public static String toString(Object obj)
toString value handling arrays.
obj - the object, may be null
public static boolean propertiesEqual(Bean bean1,
Bean bean2)
This comparison checks that both beans have the same set of property names
and that the value of each property name is also equal.
It does not check the bean type, thus a FlexiBean may be equal
to a DirectBean.
This comparison is usable with the propertiesHashCode(org.joda.beans.Bean) method.
The result is the same as that if each bean was converted to a Map
from name to value.
bean1 - the first bean to compare, not nullbean2 - the second bean to compare, not null
public static int propertiesHashCode(Bean bean)
This hash code is usable with the propertiesEqual(org.joda.beans.Bean, org.joda.beans.Bean) method.
The result is the same as that if each bean was converted to a Map
from name to value.
bean - the bean to generate a hash code for, not null
public static String propertiesToString(Bean bean,
String prefix)
The result is the same as that if the bean was converted to a Map
from name to value.
bean - the bean to generate a string for, not nullprefix - the prefix to use, null ignored
public static <T extends Bean> T clone(T original)
This performs a deep clone. There is no protection against cycles in
the object graph beyond StackOverflowError.
T - the type of the beanoriginal - the original bean to clone, null returns null
public static <T extends Bean> T cloneAlways(T original)
This performs a deep clone. There is no protection against cycles in
the object graph beyond StackOverflowError.
This differs from Object.clone() in that immutable beans are also cloned.
T - the type of the beanoriginal - the original bean to clone, not null
public static void notNull(Object value,
String propertyName)
value - the value to check, may be nullpropertyName - the property name, should not be null
IllegalArgumentException - if the value is null
public static void notEmpty(String value,
String propertyName)
value - the value to check, may be nullpropertyName - the property name, should not be null
IllegalArgumentException - if the value is null or empty
public static void notEmpty(Collection<?> value,
String propertyName)
value - the value to check, may be nullpropertyName - the property name, should not be null
IllegalArgumentException - if the value is null or empty
public static void notEmpty(Map<?,?> value,
String propertyName)
value - the value to check, may be nullpropertyName - the property name, should not be null
IllegalArgumentException - if the value is null or emptypublic static Class<?> collectionType(Property<?> prop)
Class from a property.
This method allows the resolution of generics in certain cases.
prop - the property to examine, not null
public static Class<?> collectionType(MetaProperty<?> prop,
Class<?> targetClass)
Class from a meta-property.
The target type is the type of the object, not the declaring type of the meta-property.
prop - the property to examine, not nulltargetClass - the target type to evaluate against, not null
public static List<Class<?>> collectionTypeTypes(MetaProperty<?> prop,
Class<?> targetClass)
Class from a meta-property.
The target type is the type of the object, not the declaring type of the meta-property.
This is used when the collection generic parameter is a map or collection.
prop - the property to examine, not nulltargetClass - the target type to evaluate against, not null
public static Class<?> mapKeyType(Property<?> prop)
Class from a meta-property.
prop - the property to examine, not null
public static Class<?> mapKeyType(MetaProperty<?> prop,
Class<?> targetClass)
Class from a meta-property.
The target type is the type of the object, not the declaring type of the meta-property.
prop - the property to examine, not nulltargetClass - the target type to evaluate against, not null
public static Class<?> mapValueType(Property<?> prop)
Class from a meta-property.
prop - the property to examine, not null
public static Class<?> mapValueType(MetaProperty<?> prop,
Class<?> targetClass)
Class from a meta-property.
The target type is the type of the object, not the declaring type of the meta-property.
prop - the property to examine, not nulltargetClass - the target type to evaluate against, not null
public static List<Class<?>> mapValueTypeTypes(MetaProperty<?> prop,
Class<?> targetClass)
Class from a meta-property.
The target type is the type of the object, not the declaring type of the meta-property.
This is used when the map value generic parameter is a map or collection.
prop - the property to examine, not nulltargetClass - the target type to evaluate against, not null
public static Class<?> extractTypeClass(MetaProperty<?> prop,
Class<?> targetClass,
int size,
int index)
prop - the property to examine, not nulltargetClass - the target type to evaluate against, not nullsize - the number of generic parameters expectedindex - the index of the generic parameter
public static boolean equalIgnoring(Bean bean1,
Bean bean2,
MetaProperty<?>... properties)
This version of equalIgnoring only checks properties at the top level.
For example, if a Person bean contains an Address bean then
only properties on the Person bean will be checked against the ignore list.
bean1 - the first bean, not nullbean2 - the second bean, not nullproperties - the properties to ignore, not null
IllegalArgumentException - if inputs are nullpublic static Iterator<Bean> beanIterator(Bean bean)
The iterator is a depth-first traversal of the beans within the specified bean. The first returned bean is the specified bean. Beans within collections will be returned.
A cycle in the bean structure will cause an infinite loop.
bean - the bean to iterate over, not null
public static Comparator<Bean> comparator(BeanQuery<?> query,
boolean ascending)
The result of the query must be Comparable.
query - the query to use, not nullascending - true for ascending, false for descending
public static Comparator<Bean> comparatorAscending(BeanQuery<?> query)
The result of the query must be Comparable.
query - the query to use, not null
public static Comparator<Bean> comparatorDescending(BeanQuery<?> query)
The result of the query must be Comparable.
query - the query to use, not null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||