Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use java.util.Objects to implement equals, hashCode #294

Merged
merged 2 commits into from
Nov 20, 2017

Conversation

dagnir
Copy link
Contributor

@dagnir dagnir commented Nov 17, 2017

Description

Use java.util.Objects to implements equals() and hashCode().

Motivation and Context

Should cut down on generated file size.

Testing

Updated reference tests.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG

License

  • I confirm that this pull request can be released under the Apache 2 license

@millems
Copy link
Contributor

millems commented Nov 17, 2017

This creates a bit more garbage because it needs to load things into an array. I'm guessing we're balancing against jar size? How much does this help that?

@dagnir
Copy link
Contributor Author

dagnir commented Nov 17, 2017

This uses Objects.hashCode rather than Objects.hash, so don't think the array creation is an issue here

@millems
Copy link
Contributor

millems commented Nov 17, 2017

Cool, I missed that!

}
if (!Objects.equals(booleanMember(), other.booleanMember()) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance we could just do return Object.equals() && Object.equals() & ...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 sounds good

@dagnir
Copy link
Contributor Author

dagnir commented Nov 18, 2017

Updated equals generation to chain &&

memberModels.stream()
.skip(1)
.forEach(m -> adder.accept("&&", m));
memberEqualsStmt.add(";");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the PoetCollectors.toDelimitedCodeBlock make this a bit easier to implement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Didn't know that was there. Done

@dagnir dagnir merged commit a5819ad into aws:master Nov 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants