MINOR: Generated classes should have standard equals#7709
Closed
cmccabe wants to merge 1 commit intoapache:trunkfrom
Closed
MINOR: Generated classes should have standard equals#7709cmccabe wants to merge 1 commit intoapache:trunkfrom
cmccabe wants to merge 1 commit intoapache:trunkfrom
Conversation
ijuma
reviewed
Nov 18, 2019
Member
There was a problem hiding this comment.
It's better to do instanceof than this. The JVM folds the instanceof into the trap it needs to ensure JVM semantics.
Unite ImplicitLinkedHashCollection and ImplicitLinkedHashMultiCollection into a single class. It's simpler this way, and the code that needs to avoid duplicates can do it through the API. Fix the problem where inserting the same object into a collection twice causes corruption. This happened because due to the implicit linked list, there was only one set of previous and next pointers. We get around this in this PR by duplicating the inserted object when this situation arises. Generated Message classes now have a duplicate() function which creates a duplicate of the existing object, and a copy() method which sets all values to those of another object of the same type. Previously, we had to resort to clunky serializing and then deserializing to copy message objects. Generated Message classes now always have an equals() function which tests every field. Previously, message classes used as keys had special equals functions which only compared their key fields, which was confusing. We still support searching by the key because the find and findAll functions now take a comparator argument.
Contributor
Author
|
Superseded by #8539 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, generates classes that were used as keys got non-standard
equals and hashCode functions which only checked the fields that were
part of their keys. This was confusing for people using those functions
in different contexts.
Instead, we should give ImplicitLinkedHashCollection and subclasses the
ability to use a separate function to compare and hash the key fields,
and generate standard equals and hashCode functions.