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/03/15 12:26:26 UTC

svn commit: r1300925 - /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java

Author: simonetripodi
Date: Thu Mar 15 11:26:25 2012
New Revision: 1300925

URL: http://svn.apache.org/viewvc?rev=1300925&view=rev
Log:
just incrementally built the hashcode in the constructor  

Modified:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java

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=1300925&r1=1300924&r2=1300925&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 Thu Mar 15 11:26:25 2012
@@ -508,27 +508,28 @@ abstract class AccessibleObjectsRegistry
          */
         public AccessibleObjectDescriptor( boolean exact, Class<?> type, String methodName, Class<?>... paramTypes )
         {
+            final int prime = 31;
+            int hashCode = 1;
+
             this.exact = exact;
+            hashCode = prime * hashCode + ( exact ? 1231 : 1237 );
+
             this.type = type;
+            hashCode = prime * hashCode + ( ( type == null ) ? 0 : type.getName().hashCode() );
+
             this.methodName = methodName;
+            hashCode = prime * hashCode + ( ( methodName == null ) ? 0 : methodName.hashCode() );
+
             this.paramTypes = paramTypes;
-            hashCode = hashCode();
+            hashCode = prime * hashCode + Arrays.hashCode( paramTypes );
+
+            this.hashCode = hashCode;
         }
 
         @Override
         public int hashCode()
         {
-            if ( hashCode != 0 )
-            {
-                return hashCode;
-            }
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ( ( type == null ) ? 0 : type.getName().hashCode() );
-            result = prime * result + ( exact ? 1231 : 1237 );
-            result = prime * result + ( ( methodName == null ) ? 0 : methodName.hashCode() );
-            result = prime * result + Arrays.hashCode( paramTypes );
-            return result;
+            return hashCode;
         }
 
         @Override



Re: svn commit: r1300925 - /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java

Posted by Benedikt Ritter <be...@googlemail.com>.
Am 15. März 2012 12:59 schrieb sebb <se...@gmail.com>:
> On 15 March 2012 11:26,  <si...@apache.org> wrote:
>> Author: simonetripodi
>> Date: Thu Mar 15 11:26:25 2012
>> New Revision: 1300925
>>
>> URL: http://svn.apache.org/viewvc?rev=1300925&view=rev
>> Log:
>> just incrementally built the hashcode in the constructor
>>
>
> I wondered why you did not use the java.lang.String approach, but I
> see the class is used in a HashMap so the hashCode will always be
> needed.
> Might be an idea to note this in the ctor?
>

AccessibleObjectDescriptor is a nested private class of the package
private AccessibleObjectRegistry. So users will never create
AccessibleObjectDescriptors. The class comment says "Represents the
key to looking up an AccessibleObject by reflection."
Would be a bit redundant to add yet another comment to the constructor.

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1300925 - /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java

Posted by sebb <se...@gmail.com>.
On 15 March 2012 11:26,  <si...@apache.org> wrote:
> Author: simonetripodi
> Date: Thu Mar 15 11:26:25 2012
> New Revision: 1300925
>
> URL: http://svn.apache.org/viewvc?rev=1300925&view=rev
> Log:
> just incrementally built the hashcode in the constructor
>

I wondered why you did not use the java.lang.String approach, but I
see the class is used in a HashMap so the hashCode will always be
needed.
Might be an idea to note this in the ctor?

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org