net.sf.beanlib
Class BeanGetter

java.lang.Object
  extended by net.sf.beanlib.BeanGetter

public class BeanGetter
extends Object

Bean Getter.

Author:
Joe D. Velopar

Field Summary
static BeanGetter inst
          Singleton instance.
private  Log log
           
 
Constructor Summary
private BeanGetter()
          Singleton.
 
Method Summary
private  int addBeanHashCode(int hashCode, int delta)
           
private  int beanReaderHash(int hashCode, Method m, Object bean)
          Returns a hash code modified from the input hash code with the value returned from a JavaBean reader method using the algorithm suggested in Item 8 of Effective Java by Joshua Bloch.
 int getBeanHashCode(Object bean)
          Returns a hash code for the given JavaBean object for all the reader methods using the algorithm suggested in Item 8 of Effective Java by Joshua Bloch.
 String getPropertyAsString(Object bean, PropertyDescriptor pd)
          Returns the string value of the given property of the specified java bean class.
 Map getPropertyName2DescriptorMap(Class beanClass)
          Returns the property name to descriptor map for the given bean class.
private  int hashReturnValue(int hashCode, Class c, Object v)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inst

public static final BeanGetter inst
Singleton instance.


log

private final Log log
Constructor Detail

BeanGetter

private BeanGetter()
Singleton.

Method Detail

getPropertyAsString

public final String getPropertyAsString(Object bean,
                                        PropertyDescriptor pd)
Returns the string value of the given property of the specified java bean class.


getPropertyName2DescriptorMap

public final Map getPropertyName2DescriptorMap(Class beanClass)
Returns the property name to descriptor map for the given bean class.


beanReaderHash

private int beanReaderHash(int hashCode,
                           Method m,
                           Object bean)
                    throws IllegalAccessException,
                           InvocationTargetException
Returns a hash code modified from the input hash code with the value returned from a JavaBean reader method using the algorithm suggested in Item 8 of Effective Java by Joshua Bloch.

Parameters:
hashCode - starting hash code
m - a JavaBean reader method
bean - JavaNean object
Throws:
IllegalAccessException
InvocationTargetException

hashReturnValue

private int hashReturnValue(int hashCode,
                            Class c,
                            Object v)
Parameters:
hashCode - hash code value before invoking this method
c - class of value returned from a JavaBean reader method
v - value returned from a JavaBean reader method
Returns:
the hash code by taking into account the give value returned from a JavaBean reader method

addBeanHashCode

private int addBeanHashCode(int hashCode,
                            int delta)
Parameters:
hashCode - hash code to add to
delta - value to be added to the hash code
Returns:
resultant hash code added with the given delta value.

getBeanHashCode

public int getBeanHashCode(Object bean)
Returns a hash code for the given JavaBean object for all the reader methods using the algorithm suggested in Item 8 of Effective Java by Joshua Bloch.

Parameters:
bean - java bean for which the hash code is to be calculated.
Returns:
the hash code for the given java bean.