Skip to content

Support equals() for IntOrString#283

Merged
brendandburns merged 1 commit into
kubernetes-client:masterfrom
russgold:issue_282_IntOrString_equals
Jun 1, 2018
Merged

Support equals() for IntOrString#283
brendandburns merged 1 commit into
kubernetes-client:masterfrom
russgold:issue_282_IntOrString_equals

Conversation

@russgold

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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