commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave.De...@Equifax.com
Subject Re: [PATCH][LANG] StringUtils.trimNull(String)
Date Fri, 24 Jan 2003 11:58:06 GMT

I see your point, and I agree that there are cases where you would want to
trim to null. I still think that this is less often than the case where you
don't. Yesterday someone (I no longer have the message so I can't give
proper credit) suggested having 2 methods (ie. trimToBlank & trimToNull). I
think that this is a very reasonable compromise that allows the developer
to decide which he wants.

Dave Derry




                                                                                         
                                       
                      Leonardo Quijano                                                   
                                       
                      Vincenzi                 To:      commons-dev@jakarta.apache.org   
                                       
                      <lquijano@hotpop         cc:                                    
                                          
                      .com>                    Subject: Re: [PATCH][LANG] StringUtils.trimNull(String)
                          
                                                                                         
                                       
                      01/23/2003 09:39                                                   
                                       
                      PM                                                                 
                                       
                      Please respond                                                     
                                       
                      to "Jakarta                                                        
                                       
                      Commons                                                            
                                       
                      Developers List"                                                   
                                       
                                                                                         
                                       
                                                                                         
                                       



> Which is StringUtils.trim. Already there.
> Like Dave, I'm not sure I can see converting "" to null as a highly
common
> thing to do. In fact, I'd expect people to want the reverse more often
> [which I suspect Dave might like}, convert any null passed in into "".

>Leonardo, what's the use case for StringUtils.trimNull( str)?
>I, like Hen and Dave, have difficulties seeing one that occurs often
for >most people,
>which would motivate inclusion.

A use case could be in a web application. When I get data through an
HTML form, sometimes I'd like to treat whitespaces as null values
(meaning that the user didn't provide any information). In this case,
*null* is a special value, not a nuisance.

A QBE (Query By Example) could get a JavaBean with some fields filled
with data, and some nulls. The data fields are included in the query,
while the null ones aren't.

You would say, what if the whitespace *is* the special value? Well, I
would like to change the web interface later and provide checkboxes in
the form. The checked properties are taken into account, even if they
have whitespace. However, we wouldn't  need to change the business logic
of the QBE, because it always had nulls as "no values". Even more, the
program is more robust, because if by accident one of the request
parameters didn't show up (giving a null value), the business logic is
ready for that. If we have to check for empty strings, on the other
hand, a null value could get us a NullPointerException.

That's just an example. There could be several other examples where NULL
is important, and it would be useful to turn empty strings into nulls.
That's why I think the method would be useful.

Leonardo

--
To unsubscribe, e-mail:   <
mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <
mailto:commons-dev-help@jakarta.apache.org>







--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message