public static String getPropertyNameConvention ( Object object , String suffix ) { if ( object != null ) { Class < ? > type = object . getClass ( ) ; if ( type . isArray ( ) ) { return getPropertyName ( type . getComponentType ( ) ) + suffix + "Array" ; } if ( object instanceof Collection ) { Collection coll = ( Collection ) object ; if ( coll . isEmpty ( ) ) { return "emptyCollection" ; } Object first = coll . iterator ( ) . next ( ) ; if ( coll instanceof List ) { return getPropertyName ( first . getClass ( ) ) + suffix + "List" ; } if ( coll instanceof Set ) { return getPropertyName ( first . getClass ( ) ) + suffix + "Set" ; } return getPropertyName ( first . getClass ( ) ) + suffix + "Collection" ; } if ( object instanceof Map ) { Map map = ( Map ) object ; if ( map . isEmpty ( ) ) { return "emptyMap" ; } Object entry = map . values ( ) . iterator ( ) . next ( ) ; if ( entry != null ) { return getPropertyName ( entry . getClass ( ) ) + suffix + "Map" ; } } else { return getPropertyName ( object . getClass ( ) ) + suffix ; } } return null ; }
Returns an appropriate property name for the given object . If the object is a collection will append List Set Collection or Map to the property name .