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
Add TriState toBoolean helper methods #472
Add TriState toBoolean helper methods #472
Conversation
Thanks for the PR! Besides the checkstyle issues (which will be flagged up when this build completes), I like this PR! In terms of the implementation, I wonder if we could have the Boolean values as a property of the enum directly. I'd want to say an I hope that makes sense :') |
1ba82a2
to
1cd0b55
Compare
were fixed 👍 |
1cd0b55
to
daabe1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth a toBooleanOrElse
method, but it's not massively necessary, and this is just fine regardless :)
I'll add it :) |
While the TriState enum already has helper methods to quickly convert a boolean into a TriState (both nullable wrappers and their primitive counterparts), helper methods to convert a TriState back into a boolean representation are currently missing. This commit introduces two methods that do exactly that, one allowing a straight forward conversion to a Boolean as it can represent a TriState through its nullability as well as another method that discards the TriState#NOT_SET by accepting a supplier that will be used to map a not set tri-state.
daabe1a
to
b1550bf
Compare
Added the |
While the TriState enum already has helper methods to quickly convert a
boolean into a TriState (both nullable wrappers and their primitive
counterparts), helper methods to convert a TriState back into a boolean
representation are currently missing.
This commit introduces two methods that do exactly that, one
allowing a straight forward conversion to a Boolean as it can represent
a TriState through its nullability as well as another method that
discards the TriState#NOT_SET by accepting a supplier that will be
used to map a not set tri-state.
I would be very, very happy about suggestions/names for
TriState#toBooleanOrElseGet
. I based the current method name off of theOptional#orElseGet
method that also uses a supplier to map the "not-present" state of an optional, but there might very well be a much better name that I am missing.