commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmjones500 <...@git.apache.org>
Subject [GitHub] commons-lang issue #197: ObjectUtils::xorNull added
Date Fri, 09 Dec 2016 20:34:02 GMT
Github user dmjones500 commented on the issue:

    https://github.com/apache/commons-lang/pull/197
  
    @cezarykluczynski Commons Lang solves frequently encountered programming problems by adding
methods that are arguably "missing" from `java.lang`. I'm trying to imagine the sort of problem
this solves.
    
    You've provided two examples. Looking at them, I'm not sure whether `xorNull` is the best
way to solve them.
    
    Based on the name of the method, I would have thought this might work:
    
    ```java
    private void removeBirthNameIfItEqualsName(ActorTemplate actorTemplate) {
        String name = actorTemplate.getName();
        String birthName = actorTemplate.getBirthName();
    
        if (birthName == null) {
            return;
        }
    
        if (birthName.equals(name)) {
            actorTemplate.setBirthName(null);
        }
    }
    ```
    
    In your other example, you could rearrange the conditional statements and remove the need
for your method:
    
    ```java
    private LocalDate getIfEqualSkipNulls(LocalDate left, LocalDate right, Page item, boolean
dateOfBirth) {
    
        if (left == null && right == null) {
            return null;
        } else if (left != null && right != null) {
            if (left.equals(right)) {
                return left;
            } else {
                String dateType = dateOfBirth ? "birth" : "death";
                log.error(
                        "Date of {} {} from for PageToLifeRangeProcessor does not equal date
of {} {} from "
                                + "ActorTemplateToLifeRangeProcessor for {} - setting date
to null",
                        dateType, left, dateType, right, item.getTitle());
                return null;
            }
        } else {
            return ObjectUtils.firstNonNull(left, right);
        }
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message