public String generateHashCode(Property property, String result, String thisName, boolean jdk5) { StringBuffer buf = new StringBuffer(); if (c2j.getMetaAsBool(property, "use-in-equals")) { String javaTypeName = c2j.getJavaTypeName(property, jdk5, this); boolean isPrimitive = c2j.isPrimitive(javaTypeName); if (isPrimitive) { buf.append(result).append(" = 37 * ").append(result).append(" + "); String thisValue = thisName + "." + getGetterSignature(property) + "()"; if ("char".equals(javaTypeName) || "int".equals(javaTypeName) || "short".equals(javaTypeName) || "byte".equals(javaTypeName)) { buf.append(thisValue); } else if ("boolean".equals(javaTypeName)) { buf.append("(" + thisValue + "?1:0)"); } else { buf.append("(int) "); buf.append(thisValue); } buf.append(";"); } else { if (javaTypeName.endsWith("[]")) { if (jdk5) { buf.append(result).append(" = 37 * ").append(result).append(" + "); buf.append("( ") .append(getGetterSignature(property)) .append("() == null ? 0 : " + importType("java.util.Arrays") + ".hashCode(") .append(thisName) .append(".") .append(getGetterSignature(property)) .append("())") .append(" )") .append(";"); } else { buf.append(internalGenerateArrayHashcode(property, javaTypeName, result, thisName)); } } else { buf.append(result).append(" = 37 * ").append(result).append(" + "); buf.append("( ") .append(getGetterSignature(property)) .append("() == null ? 0 : ") .append(thisName) .append(".") .append(getGetterSignature(property)) .append("()") .append(".hashCode()") .append(" )") .append(";"); } } } return buf.toString(); }
private String internalgenerateEquals(String typeName, String lh, String rh) { if (c2j.isPrimitive(typeName)) { return "(" + lh + "==" + rh + ")"; } else { if (useCompareTo(typeName)) { return "( (" + lh + "==" + rh + ") || ( " + lh + "!=null && " + rh + "!=null && " + lh + ".compareTo(" + rh + ")==0 ) )"; } else { if (typeName.endsWith("[]")) { return "( (" + lh + "==" + rh + ") || ( " + lh + "!=null && " + rh + "!=null && " + importType("java.util.Arrays") + ".equals(" + lh + ", " + rh + ") ) )"; } else { return "( (" + lh + "==" + rh + ") || ( " + lh + "!=null && " + rh + "!=null && " + lh + ".equals(" + rh + ") ) )"; } } } }