[ 
https://issues.apache.org/jira/browse/LANG-1634?focusedWorklogId=837665&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-837665
 ]

ASF GitHub Bot logged work on LANG-1634:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 07/Jan/23 05:04
            Start Date: 07/Jan/23 05:04
    Worklog Time Spent: 10m 
      Work Description: singhbaljit commented on PR #684:
URL: https://github.com/apache/commons-lang/pull/684#issuecomment-1374380735

   We could really use this method. This is helpful because it removes the 
if/else code branch from the application codes, and therefore, devs don't have 
to write trivial unit tests to meet the code coverage requirements.




Issue Time Tracking
-------------------

    Worklog Id:     (was: 837665)
    Time Spent: 3h 40m  (was: 3.5h)

> ObjectUtils - apply Consumer with non-null value
> ------------------------------------------------
>
>                 Key: LANG-1634
>                 URL: https://issues.apache.org/jira/browse/LANG-1634
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: Bindul Bhowmik
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 3h 40m
>  Remaining Estimate: 0h
>
> There are multiple places in code where we have to check if a value is 
> {{null}} before using it in a setter or other method, like:
> {code:java}
> if (valueX != null) {
>       bean.setValue(valueX);
>       someObject.compute(valueX, "bar");
> }
> {code}
> This enhancement request is to add a couple of methods in {{ObjectUtils}} to 
> wrap this logic,  like the following:
> {code:java}
> public static <T> void applyIfNonNull(final Consumer<T> consumer, final T 
> object)
> public static <T> void applyFirstNonNull(final Consumer<T> consumer, final 
> T... objects)
> {code}
> With this the two statements above could be used as:
> {code:java}
> ObjectUtils.applyIfNonNull(bean::setValue, valueX);
> ObjectUtils.appyIfNonNull(v -> someObject.compute(v, "bar"), valueX);
> {code}
> The benefit of this should increase with more such null checks we need in the 
> code that can be replaced by single statements.
> Pull request forthcoming.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to