Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3376613A9 for ; Wed, 20 Apr 2011 08:36:50 +0000 (UTC) Received: (qmail 28799 invoked by uid 500); 20 Apr 2011 08:36:49 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 28722 invoked by uid 500); 20 Apr 2011 08:36:49 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 28668 invoked by uid 99); 20 Apr 2011 08:36:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Apr 2011 08:36:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Apr 2011 08:36:44 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 1CDE7AABE3 for ; Wed, 20 Apr 2011 08:36:06 +0000 (UTC) Date: Wed, 20 Apr 2011 08:36:06 +0000 (UTC) From: "Ivan Hristov (JIRA)" To: issues@commons.apache.org Message-ID: <944043811.69452.1303288566114.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1051970059.69447.1303288205727.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Updated] (LANG-694) ObjectUtils.defaultIfNotNull MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/LANG-694?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Ivan Hristov updated LANG-694: ------------------------------ Description: Currently there is a defaultIfNull method in ObjectUtils, which is a great one, but it will be nice to have an additional method called defaultIfNotNull which returns null if the first parameter is null or the second parameter if the object is not null. This is quite helpful and avoids an if statement for cases when there is a wrapper object which first need to be checked if it's null and then information could be taken from it. Example: public class MyNiceWrapper { private Date wrappedDate; public Date getWrappedDate() { return wrappedDate; } ... } MyNiceWrapper myNiceWrapperObject = someNiceMethodWhichReturnsMyNiceWrapper(...); ObjectUtils.defaultIfNotNull(myNiceWrapperObject, anotherObject); For the moment I have to perform a null comparison on my own,e.g., if (myNiceWrapperObject == null) { return null; } return anotherObject; was: Currently there is a defaultIfNull method in ObjectUtils, which is a great one, but it will be nice to have an additional method called defaultIfNotNull which returns null if the first parameter is null or the second parameter if the object is not null. This is quite helpful and avoids an if statement for cases when there is a wrapper object which first need to be checked if it's null and then information could be taken from it. Example: public class MyNiceWrapper { private Date wrappedDate; public Date getWrappedDate() { return wrappedDate; } ... } MyNiceWrapper myNiceWrapperObject = someNiceMethodWhichReturnsMyNiceWrapper(...); ObjectUtils.defaultIfNotNull(myNiceWrapperObject, myNiceWrapperObject.getWrappedDate); For the moment I have to perform a null comparison on my own,e.g., if (myNiceWrapperObject == null) { return null; } return myNiceWrapperObject.getWrappedDate(); > ObjectUtils.defaultIfNotNull > ---------------------------- > > Key: LANG-694 > URL: https://issues.apache.org/jira/browse/LANG-694 > Project: Commons Lang > Issue Type: Improvement > Components: lang.* > Environment: all > Reporter: Ivan Hristov > Priority: Minor > Original Estimate: 10m > Remaining Estimate: 10m > > Currently there is a defaultIfNull method in ObjectUtils, which is a great one, but it will be nice to have an additional method called defaultIfNotNull which returns null if the first parameter is null or the second parameter if the object is not null. This is quite helpful and avoids an if statement for cases when there is a wrapper object which first need to be checked if it's null and then information could be taken from it. Example: > public class MyNiceWrapper { > private Date wrappedDate; > public Date getWrappedDate() { > return wrappedDate; > } > ... > } > MyNiceWrapper myNiceWrapperObject = someNiceMethodWhichReturnsMyNiceWrapper(...); > ObjectUtils.defaultIfNotNull(myNiceWrapperObject, anotherObject); > For the moment I have to perform a null comparison on my own,e.g., > if (myNiceWrapperObject == null) { > return null; > } > return anotherObject; -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira