Github user nsuke commented on a diff in the pull request:
https://github.com/apache/thrift/pull/448#discussion_r52825710
--- Diff: compiler/cpp/src/generate/t_java_generator.cc ---
@@ -1886,24 +1889,57 @@ void
t_java_generator::generate_java_struct_equality(ofstream& out, t_struct* ts
bool can_be_null = type_can_be_null(t);
string name = (*m_iter)->get_name();
- string present = "true";
+ if (is_optional || can_be_null) {
+ indent(out) << "hashCode = hashCode * " << MUL << " + ((" <<
generate_isset_check(*m_iter)
+ << ") ? " << B_YES << " : " << B_NO << ");" << endl;
+ }
if (is_optional || can_be_null) {
- present += " && (" + generate_isset_check(*m_iter) + ")";
+ indent(out) << "if (" + generate_isset_check(*m_iter) + ")" << endl;
+ indent_up();
}
- indent(out) << "boolean present_" << name << " = " << present << ";"
<< endl;
- indent(out) << "list.add(present_" << name << ");" << endl;
- indent(out) << "if (present_" << name << ")" << endl;
if (t->is_enum()) {
- indent(out) << " list.add(" << name << ".getValue());" << endl;
+ indent(out) << "hashCode = hashCode * " << MUL << " + " << name <<
".getValue();" << endl;
+ } else if (t->is_base_type()) {
+ switch(((t_base_type*)t)->get_base()) {
+ case t_base_type::TYPE_VOID:
+ break;
+ case t_base_type::TYPE_STRING:
+ indent(out) << "hashCode = hashCode * " << MUL << " + " << name
<< ".hashCode();" << endl;
+ break;
+ case t_base_type::TYPE_BOOL:
+ indent(out) << "hashCode = hashCode * " << MUL << " + ((" <<
name << ") ? "
+ << B_YES << " : " << B_NO << ");" << endl;
+ break;
+ case t_base_type::TYPE_I8:
+ indent(out) << "hashCode = hashCode * " << MUL << " + (int) ("
<< name << ");" << endl;
+ break;
+ case t_base_type::TYPE_I16:
+ case t_base_type::TYPE_I32:
+ indent(out) << "hashCode = hashCode * " << MUL << " + " << name
<< ";" << endl;
+ break;
+ case t_base_type::TYPE_I64:
+ indent(out) << "hashCode = hashCode * " << MUL << " +
org.apache.thrift.TBaseHelper.hashCode(" << name << ");" << endl;
+ break;
+ case t_base_type::TYPE_DOUBLE:
+ indent(out) << "hashCode = hashCode * " << MUL << " +
org.apache.thrift.TBaseHelper.hashCode(" << name << ");" << endl;
+ break;
+ default:
+ throw "compiler error: the following base type has no hashcode
generator: " +
+ t_base_type::t_base_name(((t_base_type*)t)->get_base());
--- End diff --
Just a style nit, could you indent switch in the same way as the other part
of this file (less indentation) ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---