[jboss-cvs] JBossAS SVN: r90102 - in projects/jboss-mdr/trunk: src/main/java/org/jboss/metadata/plugins and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 11 13:11:55 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-06-11 13:11:54 -0400 (Thu, 11 Jun 2009)
New Revision: 90102

Added:
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java
   projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature/
   projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java
Modified:
   projects/jboss-mdr/trunk/.classpath
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/Signature.java
Log:
[JBMDR-57] Make DeclaredMethodSignature.equals() less strict

Modified: projects/jboss-mdr/trunk/.classpath
===================================================================
--- projects/jboss-mdr/trunk/.classpath	2009-06-11 16:36:50 UTC (rev 90101)
+++ projects/jboss-mdr/trunk/.classpath	2009-06-11 17:11:54 UTC (rev 90102)
@@ -7,7 +7,7 @@
   <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-junit/1.7.0/ant-junit-1.7.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/javassist/javassist/3.8.1.GA/javassist-3.8.1.GA.jar" sourcepath="M2_REPO/javassist/javassist/3.8.1.GA/javassist-3.8.1.GA-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.8.GA/jboss-common-core-2.2.8.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-common-core/2.2.8.GA/jboss-common-core-2.2.8.GA-sources.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.9.GA/jboss-common-core-2.2.9.GA.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/jboss/profiler/jvmti/jboss-profiler-jvmti/1.0.0.CR5/jboss-profiler-jvmti-1.0.0.CR5.jar"/>

Added: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java	2009-06-11 17:11:54 UTC (rev 90102)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.metadata.plugins.signature;
+
+import java.util.Arrays;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SignatureNameUtil
+{
+   public static void signatureToString(StringBuilder builder, String name, String[] parameters)
+   {
+      if (name != null)
+         builder.append(name);
+      if (parameters != null)
+         builder.append(Arrays.asList(parameters));
+   }
+
+}

Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java	2009-06-11 16:36:50 UTC (rev 90101)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java	2009-06-11 17:11:54 UTC (rev 90102)
@@ -23,6 +23,7 @@
 
 import java.lang.reflect.Method;
 
+import org.jboss.metadata.plugins.signature.SignatureNameUtil;
 import org.jboss.reflect.spi.MethodInfo;
 
 /**
@@ -38,6 +39,11 @@
    
    /** The method */
    private Method method;
+
+   /**
+    * The cached hash code
+    */
+   int cachedHashCode = Integer.MIN_VALUE;
    
    /**
     * Create a new Signature.
@@ -121,14 +127,31 @@
    {
       if (obj == this)
          return true;
-      if (obj == null || obj instanceof DeclaredMethodSignature == false || super.equals(obj) == false)
+      if (obj == null || super.equals(obj) == false)
          return false;
 
-      DeclaredMethodSignature other = (DeclaredMethodSignature) obj;
-      return getDeclaringClass().equals(other.getDeclaringClass());
+      if (obj instanceof DeclaredMethodSignature)
+      {
+         DeclaredMethodSignature other = (DeclaredMethodSignature) obj;
+         return getDeclaringClass().equals(other.getDeclaringClass());
+      }
+      return true;
    }
 
    @Override
+   public int hashCode()
+   {
+      //Only take the short version of the name into consideration when creating the hashCode
+      if (cachedHashCode == Integer.MIN_VALUE)
+      {
+         StringBuilder builder = new StringBuilder();
+         SignatureNameUtil.signatureToString(builder, getName(), getParameters());
+         cachedHashCode = builder.toString().hashCode();
+      }
+      return cachedHashCode;
+   }
+
+   @Override
    protected void internalToString(StringBuilder builder)
    {
       super.internalToString(builder);

Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/Signature.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/Signature.java	2009-06-11 16:36:50 UTC (rev 90101)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/Signature.java	2009-06-11 17:11:54 UTC (rev 90102)
@@ -28,6 +28,7 @@
 import java.lang.reflect.Method;
 import java.util.Arrays;
 
+import org.jboss.metadata.plugins.signature.SignatureNameUtil;
 import org.jboss.reflect.spi.ConstructorInfo;
 import org.jboss.reflect.spi.FieldInfo;
 import org.jboss.reflect.spi.MemberInfo;
@@ -438,10 +439,6 @@
     */
    protected void internalToString(StringBuilder builder)
    {
-      if (name != null)
-         builder.append(getName());
-      String[] parameters = getParameters();
-      if (parameters != null)
-         builder.append(Arrays.asList(parameters));
+      SignatureNameUtil.signatureToString(builder, name, getParameters());
    }
 }

Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java	2009-06-11 17:11:54 UTC (rev 90102)
@@ -0,0 +1,80 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.signature;
+
+import java.lang.reflect.Method;
+
+import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+
+import junit.framework.TestCase;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SignatureEqualsUnitTestCase extends TestCase
+{
+   public void testEqualsMethodSignature() throws Exception
+   {
+      MethodSignature sig1 = getMethodSignature();
+      MethodSignature sig2 = getMethodSignature();
+      assertEquals(sig1.hashCode(), sig2.hashCode());
+      assertTrue(sig1.equals(sig2));
+      assertTrue(sig2.equals(sig1));
+   }
+   
+   public void testEqualsDeclaredMethodSignature() throws Exception
+   {
+      DeclaredMethodSignature sig1 = getDeclaredMethodSignature();
+      DeclaredMethodSignature sig2 = getDeclaredMethodSignature();
+      assertEquals(sig1.hashCode(), sig2.hashCode());
+      assertTrue(sig1.equals(sig2));
+      assertTrue(sig2.equals(sig1));
+   }
+   
+   public void testEqualsMethodSignatureAndDeclaredMethodSignature() throws Exception
+   {
+      MethodSignature ms = getMethodSignature();
+      DeclaredMethodSignature ds = getDeclaredMethodSignature();
+      assertEquals(ms.hashCode(), ds.hashCode());
+      assertTrue(ms.equals(ds));
+      assertTrue(ds.equals(ms));
+   }
+   
+   private MethodSignature getMethodSignature() throws Exception
+   {
+      return new MethodSignature(getMethod());
+   }
+   
+   private DeclaredMethodSignature getDeclaredMethodSignature() throws Exception
+   {
+      return new DeclaredMethodSignature(getMethod());
+   }
+   
+   private Method getMethod() throws Exception
+   {
+      Class<?> clazz = this.getClass();
+      return clazz.getDeclaredMethod("getMethod");
+   }
+}




More information about the jboss-cvs-commits mailing list