You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/02/01 07:45:10 UTC
svn commit: r1238947 - in /commons/sandbox/beanutils2/trunk/src:
changes/changes.xml
main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java
Author: simonetripodi
Date: Wed Feb 1 06:45:10 2012
New Revision: 1238947
URL: http://svn.apache.org/viewvc?rev=1238947&view=rev
Log:
[SANDBOX-376] Extract magic numbers in AccessibleObjectsRegistry.getObjectTransformationCosts(...) to constants - patch provided by Benedikt Ritter
Modified:
commons/sandbox/beanutils2/trunk/src/changes/changes.xml
commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java
Modified: commons/sandbox/beanutils2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/changes/changes.xml?rev=1238947&r1=1238946&r2=1238947&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/beanutils2/trunk/src/changes/changes.xml Wed Feb 1 06:45:10 2012
@@ -23,6 +23,9 @@
</properties>
<body>
<release version="0.1" date="201?-??-??" description="First release.">
+ <action dev="simonetripodi" type="update" issue="SANDBOX-376" due-to="Benedikt Ritter">
+ Extract magic numbers in AccessibleObjectsRegistry.getObjectTransformationCosts(...) to constants
+ </action>
<action dev="simonetripodi" type="update" issue="SANDBOX-373" due-to="Benedikt Ritter">
Implement setProperty( String name ) on DefaultBeanAccessor
</action>
Modified: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java?rev=1238947&r1=1238946&r2=1238947&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java (original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java Wed Feb 1 06:45:10 2012
@@ -42,6 +42,18 @@ import java.util.concurrent.locks.Reentr
abstract class AccessibleObjectsRegistry<AO extends AccessibleObject & Member>
{
+ // extracted from BeanUtils1
+ private static final float NON_FOUND_COST = 1.5f;
+
+ // extracted from BeanUtils1
+ private static final float SUPERCLASS_COST = 1.0f;
+
+ // extracted from BeanUtils1
+ private static final float INTERFACE_COST = 0.25f;
+
+ // extracted from BeanUtils1
+ private static final float WRAPPER_COST = 0.25f;
+
private static final AccessibleObjectsRegistry<Constructor<?>> CONSTRUCTORS_REGISTRY = new ConstructorsRegistry();
private static final AccessibleObjectsRegistry<Method> METHODS_REGISTRY = new MethodsRegistry();
@@ -134,6 +146,7 @@ abstract class AccessibleObjectsRegistry
AO current = resolveAccessible( type, accessibleObjectsArray[i] );
if ( current != null )
{
+ // determine which method the compiler would chose
myCost = getTotalTransformationCost( parameterTypes, getParameterTypes( current ) );
if ( myCost < bestMatchCost )
{
@@ -171,8 +184,8 @@ abstract class AccessibleObjectsRegistry
protected abstract AO resolveAccessible( Class<?> type, AO accessibleObject );
/**
- * Returns the sum of the object transformation cost for each class in the source
- * argument list.
+ * Returns the sum of the object transformation cost for each class in the source argument list.
+ *
* @param srcArgs The source arguments
* @param destArgs The destination arguments
* @return The total transformation cost
@@ -191,9 +204,8 @@ abstract class AccessibleObjectsRegistry
}
/**
- * Gets the number of steps required needed to turn the source class into the
- * destination class. This represents the number of steps in the object hierarchy
- * graph.
+ * Determines the costs of turning the source class into the destination class. This represents the weighted number
+ * of steps in the object hierarchy graph.
*
* @param srcClass The source class
* @param destClass The destination class
@@ -209,7 +221,7 @@ abstract class AccessibleObjectsRegistry
Class<?> destClassWrapperClazz = getPrimitiveWrapper( destClass );
if ( destClassWrapperClazz != null && destClassWrapperClazz.equals( srcClass ) )
{
- cost += 0.25f;
+ cost += WRAPPER_COST;
break;
}
}
@@ -219,20 +231,18 @@ abstract class AccessibleObjectsRegistry
// we still want an exact match to override an interface match, but
// an interface match should override anything where we have to get a
// superclass.
- cost += 0.25f;
+ cost += INTERFACE_COST;
break;
}
- cost++;
+ cost += SUPERCLASS_COST;
srcClass = srcClass.getSuperclass();
}
- /*
- * If the destination class is null, we've travelled all the way up to an Object match. We'll penalize this
- * by adding 1.5 to the cost.
- */
+
+ // If the destination class is null, we've travelled all the way up to an Object match.
if ( srcClass == null )
{
- cost += 1.5f;
+ cost += NON_FOUND_COST;
}
return cost;