[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    [jira] [Commented] (LANG-1594) Add support for lambda expressions in StringUtils.join
From:       "Kiruahxh (Jira)" <jira () apache ! org>
Date:       2020-08-31 12:31:00
Message-ID: JIRA.13321747.1597047312000.298671.1598877060154 () Atlassian ! JIRA
[Download RAW message or body]


    [ https://issues.apache.org/jira/browse/LANG-1594?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17187693#comment-17187693 \
] 

Kiruahxh commented on LANG-1594:
--------------------------------

Yup, I agree we can do it with the streams API. However, this is much more verbose \
and I'd rather rely on StringUtils to do all the join tasks. I think that a \
StringUtils.join lambda override would have a very understandable syntax.

> Add support for lambda expressions in StringUtils.join
> ------------------------------------------------------
> 
> Key: LANG-1594
> URL: https://issues.apache.org/jira/browse/LANG-1594
> Project: Commons Lang
> Issue Type: Improvement
> Components: lang.*
> Affects Versions: 3.11
> Reporter: Kiruahxh
> Priority: Minor
> 
> It would be a nice addition to support lambda expressions in the StringUtils.join \
> overloads, they are supported in java 8   so there should not be compatibility \
> problems. This would simplify this kind of code :
> {code:java}
> List<ProductOutput> productList = new ArrayList<Product>();
> ...
> String ids = "";
> int i = 0;
> for (Product p : productList) {
> if (i != 0) {
> ids += ",";
> }
> ids += p.id;
> i++;
> }
> String sql = "UPDATE product SET published=1 WHERE id IN (" + list + ")";
> execUpdate(sql);{code}
> Fixed version :
> {code:java}
> List<Product> productList = new ArrayList<Product>();
> ...
> String ids = StringUtils.join(productList, ',', p -> String.valueOf(p.id))
> String sql = "UPDATE product SET published=1 WHERE id IN (" + list + ")";
> execUpdate(sql);
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic