Skip to content

Support equals() for IntOrString #283

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

Conversation

russgold
Copy link
Contributor

Implemented equals() and hash() for the IntOrString class. Unit test included

@russgold russgold closed this May 30, 2018
@russgold russgold reopened this May 30, 2018
return this == o || (o instanceof IntOrString && equals((IntOrString) o));
}

private boolean equals(IntOrString o) {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit, but is there value in making this a separate function?

Why not:

if (this == o) {
   return true;
}
if (! o instanceof IntOrString) {
   return false;
}
IntOrString other = (IntOrString) o;
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use this approach because I find it easier to read. The approach you show uses seven lines of code to accomplish what the submitted change does in one. Extra functions can act as a very simple way of documenting functionality (see Robert Martin's "Clean Code"), and get optimized away at runtime.

But my goal is just getting this fixed so that my project doesn't need a workaround. if using my approach would hold up the pull request, I am perfectly happy to see it changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel strongly enough about this to have you correct it (though overally I think my suggestion is shorter once you consider the lines to define the new function..)

I'm merging as-is.

@brendandburns
Copy link
Contributor

Thanks for the PR, one minor nit...

@brendandburns brendandburns merged commit 7382152 into kubernetes-client:master Jun 1, 2018
@russgold russgold deleted the issue_282_IntOrString_equals branch June 1, 2018 17:37
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