org.omnaest.utils.beans
Class BeanUtils

java.lang.Object
  extended by org.omnaest.utils.beans.BeanUtils

public class BeanUtils
extends Object

Helper class for Java beans.

Author:
Omnaest

Constructor Summary
BeanUtils()
           
 
Method Summary
static BeanMethodInformation beanMethodInformation(Method method)
          Returns a BeanMethodInformation object determined for the given Method.
static Set<BeanMethodInformation> beanMethodInformationSet(Class<?> clazz)
          Returns a set of BeanMethodInformation instances for all methods of a given Class.
static
<B> BeanPropertyAccessor<B>
beanPropertyAccessor(Class<B> beanClass, Field field)
          Returns a BeanPropertyAccessor object determined for the given Field.
static
<B> BeanPropertyAccessor<B>
beanPropertyAccessor(Class<B> beanClass, Method method)
          Returns a BeanPropertyAccessor object determined for the given Method.
static
<B> BeanPropertyAccessor<B>
beanPropertyAccessor(Class<B> beanClass, String propertyName)
          Returns a BeanPropertyAccessor object determined for the given property name
static
<B> BeanPropertyAccessors<B>
beanPropertyAccessors(Class<B> beanClass)
          Returns the BeanPropertyAccessors for a given Java Bean type
static
<B> Set<BeanPropertyAccessor<B>>
beanPropertyAccessorSet(Class<B> beanClass)
          Returns a set of BeanPropertyAccessor instances for all Java Bean properties of the given Class
static
<S,D> void
copyPropertyValues(S beanSource, D beanDestination)
          Copies the property values from one Java Bean to another.
static
<S,D> void
copyPropertyValues(S beanSource, D beanDestination, Collection<String> propertyNameCollection)
          Copies the property values from one Java Bean to another but only for the given property names.
static
<S,D> void
copyPropertyValues(S beanSource, D beanDestination, String... propertyNames)
          Copies the property values for the given property names from one Java Bean to another.
static Map<String,BeanMethodInformation> methodNameToBeanMethodInformationMap(Class<?> clazz)
          Determines a Map with the referenced Method.getName()s as keys and the respective BeanMethodInformation name.
static Map<String,BeanMethodInformation> methodNameToBeanMethodInformationMap(Method... methods)
          Determines a Map with all Method.getName()s and the respective BeanMethodInformation instances.
static int numberOfProperties(Class<?> beanClass)
          Returns the number of available Java Bean properties for the given Java Bean type.
static String[] propertyNamesForMethodAccess(Class<?> clazz)
          Determines the property names of a given bean class which are addressed by getter or setter.
static Map<String,Set<BeanMethodInformation>> propertyNameToBeanMethodInformationMap(Class<?> clazz)
          Determines a Map with the referenced field names as keys and a Set of BeanMethodInformation for every field name.
static Map<String,Set<BeanMethodInformation>> propertyNameToBeanMethodInformationMap(Method... methods)
          Determines a map with the referenced field names as keys and a Set of BeanMethodInformation for every field name.
static
<B> Map<String,BeanPropertyAccessor<B>>
propertyNameToBeanPropertyAccessorMap(Class<B> beanClass)
          Returns a map of property names and BeanPropertyAccessor instances for all Java Bean properties of the given Class.
static
<B> Map<String,BeanPropertyAccessor<B>>
propertyNameToBeanPropertyAccessorMap(Class<B> beanClass, Field... fields)
          Returns a map of field names and BeanPropertyAccessor instances for all Java Bean properties related to at least one of the given Fields.
static
<B> Map<String,BeanPropertyAccessor<B>>
propertyNameToBeanPropertyAccessorMap(Class<B> beanClass, Method... methods)
          Returns a map of field names and BeanPropertyAccessor instances for all Java Bean properties related to at least one of the given Methods.
static
<B,V> Map<String,V>
propertyNameToBeanPropertyValueMap(B bean)
          Returns a map of property names and their current values for all Java Bean properties or the given Java Bean object.
static
<B,V> Map<String,V>
propertyNameToBeanPropertyValueMap(B bean, Collection<String> propertyNameCollection)
          Returns a map of property names and their current values for the Java Bean properties determined by the given property names for the given Java Bean object.
static
<B,V> Map<String,V>
propertyNameToBeanPropertyValueMap(B bean, String... propertyNames)
          Returns a Map of property names and their current values for the Java Bean properties determined by the given property names for the given Java Bean object.
static
<B> Map<Class<?>,Set<BeanPropertyAccessor<B>>>
propertyTypeToBeanPropertyAccessorSetMap(Class<B> beanClass)
          Returns a map of property types for all Java Bean properties of the given Class and a Set of BeanPropertyAccessor instances for each type.
static
<B> List<B>
propertyValueList(B bean, Collection<String> propertyNameCollection)
          Returns an new ordered List of all property values for the given property names from the given Java Bean object
static
<B> List<B>
propertyValueList(B bean, String... propertyNames)
          Returns an new ordered List of all property values for the given property names from the given Java Bean object
static
<B> Map<String,Object>
transformBeanIntoMap(B bean)
          Returns a new Map instance which contains the property names as keys and the values of the properties as map values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanUtils

public BeanUtils()
Method Detail

transformBeanIntoMap

public static <B> Map<String,Object> transformBeanIntoMap(B bean)
Returns a new Map instance which contains the property names as keys and the values of the properties as map values. Modifications to the returned map will have no impact on the original Java Bean object.

Type Parameters:
B -
Parameters:
bean -
Returns:
See Also:
MapToTypeAdapter

numberOfProperties

public static int numberOfProperties(Class<?> beanClass)
Returns the number of available Java Bean properties for the given Java Bean type.

Parameters:
beanClass -
Returns:

beanPropertyAccessorSet

public static <B> Set<BeanPropertyAccessor<B>> beanPropertyAccessorSet(Class<B> beanClass)
Returns a set of BeanPropertyAccessor instances for all Java Bean properties of the given Class

Parameters:
beanClass -
Returns:
See Also:
propertyNameToBeanPropertyAccessorMap(Class), beanPropertyAccessor(Class, Field)

beanPropertyAccessors

public static <B> BeanPropertyAccessors<B> beanPropertyAccessors(Class<B> beanClass)
Returns the BeanPropertyAccessors for a given Java Bean type

Type Parameters:
B -
Parameters:
beanClass -
Returns:

propertyValueList

public static <B> List<B> propertyValueList(B bean,
                                            String... propertyNames)
Returns an new ordered List of all property values for the given property names from the given Java Bean object

Parameters:
bean -
propertyNames -
Returns:

propertyValueList

public static <B> List<B> propertyValueList(B bean,
                                            Collection<String> propertyNameCollection)
Returns an new ordered List of all property values for the given property names from the given Java Bean object

Parameters:
bean -
propertyNameCollection -
Returns:

propertyNameToBeanPropertyValueMap

public static <B,V> Map<String,V> propertyNameToBeanPropertyValueMap(B bean,
                                                                     String... propertyNames)
Returns a Map of property names and their current values for the Java Bean properties determined by the given property names for the given Java Bean object. The Map will be ordered in the same way than the given property names

Type Parameters:
B - : type of the bean
V - : type of the values
Parameters:
bean -
propertyNames -
Returns:

propertyNameToBeanPropertyValueMap

public static <B,V> Map<String,V> propertyNameToBeanPropertyValueMap(B bean,
                                                                     Collection<String> propertyNameCollection)
Returns a map of property names and their current values for the Java Bean properties determined by the given property names for the given Java Bean object. The Map keys and values will have the same order as the given property names.

Type Parameters:
B - : type of the bean
V - : type of the values
Parameters:
bean -
propertyNameCollection -
Returns:

propertyNameToBeanPropertyValueMap

public static <B,V> Map<String,V> propertyNameToBeanPropertyValueMap(B bean)
Returns a map of property names and their current values for all Java Bean properties or the given Java Bean object.

Type Parameters:
B - : type of the bean
V - : type of the values
Parameters:
bean -
Returns:

propertyNameToBeanPropertyAccessorMap

public static <B> Map<String,BeanPropertyAccessor<B>> propertyNameToBeanPropertyAccessorMap(Class<B> beanClass,
                                                                                            Field... fields)
Returns a map of field names and BeanPropertyAccessor instances for all Java Bean properties related to at least one of the given Fields.

Type Parameters:
B -
Parameters:
beanClass -
fields -
Returns:

propertyNameToBeanPropertyAccessorMap

public static <B> Map<String,BeanPropertyAccessor<B>> propertyNameToBeanPropertyAccessorMap(Class<B> beanClass,
                                                                                            Method... methods)
Returns a map of field names and BeanPropertyAccessor instances for all Java Bean properties related to at least one of the given Methods.

Type Parameters:
B -
Parameters:
beanClass -
methods -
Returns:

propertyTypeToBeanPropertyAccessorSetMap

public static <B> Map<Class<?>,Set<BeanPropertyAccessor<B>>> propertyTypeToBeanPropertyAccessorSetMap(Class<B> beanClass)
Returns a map of property types for all Java Bean properties of the given Class and a Set of BeanPropertyAccessor instances for each type.

Parameters:
beanClass -
Returns:
See Also:
beanPropertyAccessorSet(Class), propertyNameToBeanPropertyAccessorMap(Class)

propertyNameToBeanPropertyAccessorMap

public static <B> Map<String,BeanPropertyAccessor<B>> propertyNameToBeanPropertyAccessorMap(Class<B> beanClass)
Returns a map of property names and BeanPropertyAccessor instances for all Java Bean properties of the given Class. The properties are in no order.

Parameters:
beanClass -
Returns:
See Also:
beanPropertyAccessorSet(Class)

beanPropertyAccessor

public static <B> BeanPropertyAccessor<B> beanPropertyAccessor(Class<B> beanClass,
                                                               String propertyName)
Returns a BeanPropertyAccessor object determined for the given property name

Parameters:
beanClass -
propertyName -
Returns:
See Also:
beanPropertyAccessor(Class, Field), beanPropertyAccessorSet(Class), propertyNameToBeanPropertyAccessorMap(Class)

beanPropertyAccessor

public static <B> BeanPropertyAccessor<B> beanPropertyAccessor(Class<B> beanClass,
                                                               Field field)
Returns a BeanPropertyAccessor object determined for the given Field.

Parameters:
beanClass -
field -
Returns:
See Also:
beanPropertyAccessor(Class, Method), beanPropertyAccessor(Class, String), beanPropertyAccessorSet(Class), propertyNameToBeanPropertyAccessorMap(Class)

beanPropertyAccessor

public static <B> BeanPropertyAccessor<B> beanPropertyAccessor(Class<B> beanClass,
                                                               Method method)
Returns a BeanPropertyAccessor object determined for the given Method.

Parameters:
beanClass -
method -
Returns:
See Also:
beanPropertyAccessor(Class, Field), beanPropertyAccessorSet(Class), propertyNameToBeanPropertyAccessorMap(Class)

beanMethodInformationSet

public static Set<BeanMethodInformation> beanMethodInformationSet(Class<?> clazz)
Returns a set of BeanMethodInformation instances for all methods of a given Class.

Parameters:
clazz -
Returns:

propertyNameToBeanMethodInformationMap

public static Map<String,Set<BeanMethodInformation>> propertyNameToBeanMethodInformationMap(Class<?> clazz)
Determines a Map with the referenced field names as keys and a Set of BeanMethodInformation for every field name.

Parameters:
clazz -
Returns:

methodNameToBeanMethodInformationMap

public static Map<String,BeanMethodInformation> methodNameToBeanMethodInformationMap(Class<?> clazz)
Determines a Map with the referenced Method.getName()s as keys and the respective BeanMethodInformation name.

Parameters:
clazz -
Returns:

propertyNameToBeanMethodInformationMap

public static Map<String,Set<BeanMethodInformation>> propertyNameToBeanMethodInformationMap(Method... methods)
Determines a map with the referenced field names as keys and a Set of BeanMethodInformation for every field name. The map keys are in no order.

Parameters:
methods -
Returns:

methodNameToBeanMethodInformationMap

public static Map<String,BeanMethodInformation> methodNameToBeanMethodInformationMap(Method... methods)
Determines a Map with all Method.getName()s and the respective BeanMethodInformation instances.

Parameters:
methods -
Returns:

beanMethodInformation

public static BeanMethodInformation beanMethodInformation(Method method)
Returns a BeanMethodInformation object determined for the given Method.


copyPropertyValues

public static <S,D> void copyPropertyValues(S beanSource,
                                            D beanDestination)
Copies the property values from one Java Bean to another.

Type Parameters:
S -
D -
Parameters:
beanSource -
beanDestination -

copyPropertyValues

public static <S,D> void copyPropertyValues(S beanSource,
                                            D beanDestination,
                                            String... propertyNames)
Copies the property values for the given property names from one Java Bean to another.

Type Parameters:
S -
D -
Parameters:
beanSource -
beanDestination -
propertyNames -

copyPropertyValues

public static <S,D> void copyPropertyValues(S beanSource,
                                            D beanDestination,
                                            Collection<String> propertyNameCollection)
Copies the property values from one Java Bean to another but only for the given property names.

Type Parameters:
S -
D -
Parameters:
beanSource -
beanDestination -
propertyNameCollection -

propertyNamesForMethodAccess

public static String[] propertyNamesForMethodAccess(Class<?> clazz)
Determines the property names of a given bean class which are addressed by getter or setter.

Parameters:
clazz -
Returns:


Copyright © 2011. All Rights Reserved.