You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by le...@apache.org on 2001/04/11 04:36:52 UTC

cvs commit: jakarta-turbine/src/java/org/apache/turbine/util StringUtils.java

legassick    01/04/10 19:36:52

  Modified:    src/java/org/apache/turbine/util StringUtils.java
  Log:
  Added an isEmpty methods which returns true for a null or empty
  (after trimming) string.
  
  Revision  Changes    Path
  1.12      +12 -1     jakarta-turbine/src/java/org/apache/turbine/util/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/util/StringUtils.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- StringUtils.java	2001/03/06 06:13:30	1.11
  +++ StringUtils.java	2001/04/11 02:36:51	1.12
  @@ -62,7 +62,7 @@
    * This is where common String manipulation routines should go.
    *
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
  - * @version $Id: StringUtils.java,v 1.11 2001/03/06 06:13:30 chrise Exp $
  + * @version $Id: StringUtils.java,v 1.12 2001/04/11 02:36:51 legassick Exp $
    */
   public class StringUtils
   {
  @@ -91,6 +91,17 @@
           if (foo == null || foo.length() == 0)
               return false;
           return true;
  +    }
  +    
  +    /**
  +     * Determine whether a (trimmed) string is empty
  +     *
  +     * @param foo A String.
  +     * @return A boolean.
  +     */
  +    public static final boolean isEmpty(String foo)
  +    {
  +        return makeString(foo).equals("");
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine/src/java/org/apache/turbine/util StringUtils.java

Posted by Sean Legassick <se...@informage.net>.
In message <m3...@despot.finemaltcoding.com>, Daniel Rall 
<dl...@collab.net> writes
>Sean Legassick <se...@informage.net> writes:
>> I'm not sure that's really true, surely the compiler will intern "",
>> so a new allocation only takes place if there are no other occurrences
>> of "" in all code... unlikely I would have thought.
>
>I don't have that much faith in Java compilers.  gcc, now that's a
>whole 'nother story...

True, they are immature in many respects. I think they tend to get the 
interning of string literals right though, it's a pretty basic 
optimisation.

-- 
Sean Legassick
sean@informage.net


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine/src/java/org/apache/turbine/util StringUtils.java

Posted by Daniel Rall <dl...@collab.net>.
Sean Legassick <se...@informage.net> writes:

> In message <B6...@latchkey.com>, Jon Stevens
> <jo...@latchkey.com> writes
> 
> >> +    public static final boolean isEmpty(String foo)
> >> +    {
> >> +        return makeString(foo).equals("");
> >>      }
> >
> >I believe a better way to write that is:
> >
> >return (makeString(foo).length() == 0?true:false)
> >
> >Your code above does extra new String allocations.
> 
> I'm not sure that's really true, surely the compiler will intern "",
> so a new allocation only takes place if there are no other occurrences
> of "" in all code... unlikely I would have thought.

I don't have that much faith in Java compilers.  gcc, now that's a
whole 'nother story...

Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine/src/java/org/apache/turbine/util StringUtils.java

Posted by Sean Legassick <se...@informage.net>.
In message <B6...@latchkey.com>, Jon Stevens 
<jo...@latchkey.com> writes
>> +    public static final boolean isEmpty(String foo)
>> +    {
>> +        return makeString(foo).equals("");
>>      }
>
>I believe a better way to write that is:
>
>return (makeString(foo).length() == 0?true:false)
>
>Your code above does extra new String allocations.

I'm not sure that's really true, surely the compiler will intern "", so 
a new allocation only takes place if there are no other occurrences of 
"" in all code... unlikely I would have thought.

-- 
Sean Legassick
sean@informage.net
         As a person, nothing human can be alien to me

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine/src/java/org/apache/turbine/utilStringUtils.java

Posted by Jon Stevens <jo...@latchkey.com>.
on 4/11/01 11:11 AM, "Kasper Nielsen" <ne...@kav.dk> wrote:

> 
> ----- Original Message -----
>> I believe a better way to write that is:
>> 
>> return (makeString(foo).length() == 0?true:false)
> 
> I believe a better way to write that is:
> 
> return (makeString(foo).length() == 0)  ;-)
> 
> - Kasper

Funny thing is that is what I originally wrote and then I changed it cause I
wasn't sure if it worked or not...Ug. Not my day.

:-)

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine/src/java/org/apache/turbine/utilStringUtils.java

Posted by Kasper Nielsen <ne...@kav.dk>.
----- Original Message ----- 
> I believe a better way to write that is:
> 
> return (makeString(foo).length() == 0?true:false)

I believe a better way to write that is:
 
return (makeString(foo).length() == 0)  ;-)

- Kasper



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine/src/java/org/apache/turbine/util StringUtils.java

Posted by Jon Stevens <jo...@latchkey.com>.
on 4/10/01 7:36 PM, "legassick@apache.org" <le...@apache.org> wrote:

> +    /**
> +     * Determine whether a (trimmed) string is empty
> +     *
> +     * @param foo A String.
> +     * @return A boolean.
> +     */
> +    public static final boolean isEmpty(String foo)
> +    {
> +        return makeString(foo).equals("");
>      }

I believe a better way to write that is:

return (makeString(foo).length() == 0?true:false)

Your code above does extra new String allocations. My code might not compile
so test it first. :-)

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org