You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/12/31 12:36:58 UTC
[jira] [Commented] (LANG-1306) Add nullToEmpty method in
StringUtils
[ https://issues.apache.org/jira/browse/LANG-1306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15789451#comment-15789451 ]
ASF GitHub Bot commented on LANG-1306:
--------------------------------------
GitHub user arbasha opened a pull request:
https://github.com/apache/commons-lang/pull/224
[LANG-1306] Add nullToEmpty method in StringUtils
[Jira Link](https://issues.apache.org/jira/browse/LANG-1306)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/arbasha/commons-lang master
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/commons-lang/pull/224.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #224
----
commit cee84c01f986415dd2873d3623f67080d6470c09
Author: Basha <ar...@paypalcorp.com>
Date: 2016-12-31T12:12:00Z
Added method nullToEmpty in StringUtils.
----
> Add nullToEmpty method in StringUtils
> -------------------------------------
>
> Key: LANG-1306
> URL: https://issues.apache.org/jira/browse/LANG-1306
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Reporter: Arshad Basha
> Priority: Minor
> Fix For: 3.6
>
>
> The nullToEmpty method will convert null reference to empty string, for non null str it will return the str as it is (i.e. without striping or removing space)
> This method doesn't strips white-space nor removes control characters from the start and end of the input string like StringUtils.stripToEmpty and StringUtils.trimToEmpty methods.
> This method will allow us to replace common code patterns like the following from client side code:
> 1) if(str == null) { str = ""; }
> 2) return str == null ? "" : str;
> Examples:
> assertEquals("", StringUtils.nullToEmpty(null));
> assertEquals("", StringUtils.nullToEmpty(""));
> assertEquals("abc", StringUtils.nullToEmpty("abc"));
> assertEquals(" abc", StringUtils.nullToEmpty(" abc"));
> assertEquals("abc ", StringUtils.nullToEmpty("abc "));
> assertEquals("abc\t", StringUtils.nullToEmpty("abc\t"));
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)