You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Ruslan Sibgatullin (JIRA)" <ji...@apache.org> on 2018/07/14 09:33:00 UTC
[jira] [Comment Edited] (LANG-1404) BooleanUtils.toBoolean(Integer)
method added
[ https://issues.apache.org/jira/browse/LANG-1404?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16544138#comment-16544138 ]
Ruslan Sibgatullin edited comment on LANG-1404 at 7/14/18 9:32 AM:
-------------------------------------------------------------------
yes, ofc it's trivial, but the reason devs use BooleanUtils is to increase readability hiding details.
Lets's take this example
{code:java}
if (Integer.valueOf(1).equals(value)){code}
vs
{code:java}
if (BooleanUtils.toBoolean(value)){code}
in the first case dev needs to think about what is Integer.valueOf(1), why exactly 1 etc.
in the second case you just read the code without those implementation details.
Basically, the use-case for this newly added method is the same as for BooleanUtils.isFalse\isNotFalse\isTrue etc.
Why to use BooleanUtils.isFalse if dev can just use Boolean.FALSE.equals(boolVal)? the same answer - to increase readability hiding details.
was (Author: enigo):
yes, ofc it's trivial, but the reason devs use BooleanUtils is to increase readability hiding details.
Lets's take this example
{code:java}
if (Integer.valueOf(1).equals(value)){code}
vs
{code:java}
if (BooleanUtils.toBoolean(value)){code}
in the first case dev needs to think about what is Integer.valueOf(1), why exactly 1 etc.
in the second case you just read the code without those implementation details.
Basically, the use-case for this newly added method is the same as for BooleanUtils.isFalse\isNotFalse\isTrue etc.
Why to use BooleanUtils.isFalse if dev can just use Boolean.FALSE.equals(boolVal)? the same answer - to increase readability hiding details.
> BooleanUtils.toBoolean(Integer) method added
> --------------------------------------------
>
> Key: LANG-1404
> URL: https://issues.apache.org/jira/browse/LANG-1404
> Project: Commons Lang
> Issue Type: Improvement
> Components: lang.*
> Reporter: Ruslan Sibgatullin
> Priority: Minor
>
> Right now to convert an Integer to boolean there is either a null check needed:
> {{final Integer value = 1;}}
> {{if (value != null) {}}
> {{ if(BooleanUtils.toBoolean(value)) {}}
> {{ // some code}}
> }
> {{}}}
> or two methods call:
>
> {{final Integer value = 1;}}
> {{final Boolean b = BooleanUtils.toBooleanObject(value);}}
> {{if (BooleanUtils.toBoolean(b)) {}}
> {{ // some code}}
> {{}}}
> Some code-sugar is added with the help of method that accepts Integer and returns boolean:
> {{final Integer value = 1;}}
> {{if (BooleanUtils.toBoolean(value)) {}}
> // some code
> {{}}}
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)