[jboss-cvs] JBossAS SVN: r104390 - projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 3 02:41:51 EDT 2010
Author: jeff.zhang
Date: 2010-05-03 02:41:51 -0400 (Mon, 03 May 2010)
New Revision: 104390
Modified:
projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java
Log:
[JBJCA-316] config-properties in hashCode/equals
Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java 2010-05-02 04:18:08 UTC (rev 104389)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java 2010-05-03 06:41:51 UTC (rev 104390)
@@ -189,7 +189,7 @@
}
/**
- * Output class boby
+ * Output class body
* @param def definition
* @param out Writer
*/
@@ -218,13 +218,14 @@
writeEndpointLifecycle(def, out, indent);
writeLifecycle(def, out, indent);
writeXAResource(def, out, indent);
- writeHashEquals(def, out, indent);
+ writeHashCode(def, out, indent);
+ writeEquals(def, out, indent);
writeRightCurlyBracket(out, 0);
}
/**
- * Output class boby
+ * Output Configuration Properties
* @param def definition
* @param out Writer
* @param indent space number
@@ -246,8 +247,8 @@
def.getRaConfigProps().get(i).getName() +
";");
writeEol(out);
+ writeEol(out);
}
- writeEol(out);
for (int i = 0; i < def.getRaConfigProps().size(); i++)
{
@@ -299,12 +300,12 @@
/**
- * Output class boby
+ * Output hashCode method
* @param def definition
* @param out Writer
* @param indent space number
*/
- private void writeHashEquals(Definition def, Writer out, int indent) throws IOException
+ private void writeHashCode(Definition def, Writer out, int indent) throws IOException
{
writeIndent(out, indent);
out.write("@Override");
@@ -313,10 +314,61 @@
out.write("public int hashCode()");
writeLeftCurlyBracket(out, indent);
writeIndent(out, indent + 1);
- out.write("return 43;");
+ out.write("int result = 17;");
+ writeEol(out);
+ for (int i = 0; i < def.getRaConfigProps().size(); i++)
+ {
+ writeIndent(out, indent + 1);
+ String type = def.getRaConfigProps().get(i).getType();
+ if (type.equals("int"))
+ {
+ out.write("result = 31 * result + " + def.getRaConfigProps().get(i).getName() + ";");
+ }
+ else if (type.equals("short") || type.equals("char") || type.equals("byte"))
+ {
+ out.write("result = 31 * result + (int)" + def.getRaConfigProps().get(i).getName() + ";");
+ }
+ else if (type.equals("boolean"))
+ {
+ out.write("result = 31 * result + (" + def.getRaConfigProps().get(i).getName() + " ? 0 : 1);");
+ }
+ else if (type.equals("long"))
+ {
+ out.write("result = 31 * result + (int)(" + def.getRaConfigProps().get(i).getName() +
+ " ^ (" + def.getRaConfigProps().get(i).getName() + " >>> 32));");
+ }
+ else if (type.equals("float"))
+ {
+ out.write("result = 31 * result + Float.floatToIntBits(" + def.getRaConfigProps().get(i).getName() + ");");
+ }
+ else if (type.equals("double"))
+ {
+ out.write("long tolong = Double.doubleToLongBits(" + def.getRaConfigProps().get(i).getName() + ");");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("result = 31 * result + (int)(tolong ^ (tolong >>> 32));");
+ }
+ else
+ {
+ out.write("result = 31 * result + " + def.getRaConfigProps().get(i).getName() + ".hashCode();");
+ }
+ writeEol(out);
+ }
+ writeIndent(out, indent + 1);
+ out.write("return result;");
writeRightCurlyBracket(out, indent);
writeEol(out);
+ }
+
+ /**
+ * Output equals method
+ * @param def definition
+ * @param out Writer
+ * @param indent space number
+ */
+ private void writeEquals(Definition def, Writer out, int indent) throws IOException
+ {
writeIndent(out, indent);
out.write("@Override");
writeEol(out);
@@ -330,13 +382,39 @@
out.write("return false;");
writeEol(out);
writeIndent(out, indent + 1);
- out.write("return getClass().equals(other.getClass());");
+ out.write("if (other == this)");
+ writeEol(out);
+ writeIndent(out, indent + 2);
+ out.write("return true;");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("if (!(other instanceof " + def.getRaClass() + "))");
+ writeEol(out);
+ writeIndent(out, indent + 2);
+ out.write("return false;");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write(def.getRaClass() + " ra = (" + def.getRaClass() + ")other;");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("return ");
+ for (int i = 0; i < def.getRaConfigProps().size(); i++)
+ {
+ if (i != 0)
+ {
+ writeEol(out);
+ writeIndent(out, indent + 2);
+ out.write("&& ");
+ }
+ out.write(def.getRaConfigProps().get(i).getName() + " == ra." + def.getRaConfigProps().get(i).getName());
+ }
+ out.write(";");
writeRightCurlyBracket(out, indent);
writeEol(out);
}
/**
- * Output class boby
+ * Output getXAResources method
* @param def definition
* @param out Writer
* @param indent space number
@@ -359,7 +437,7 @@
}
/**
- * Output class boby
+ * Output Lifecycle method
* @param def definition
* @param out Writer
* @param indent space number
@@ -387,7 +465,7 @@
}
/**
- * Output class boby
+ * Output EndpointLifecycle method
* @param def definition
* @param out Writer
* @param indent space number
More information about the jboss-cvs-commits
mailing list