ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Réf. : RE: Réf. : Re: Commons Validator
Date Thu, 07 Nov 2002 16:14:00 GMT
Well, if you really want it faster, don't new an object ;-)
And static and final are redundant too... It's also cleaner IMHO to catch
the right exception (also thrown for null values BTW). And to make it still
faster, use the overload that takes a radix of 10, which will avoid still
one indirection. Cheers, --DD

public static boolean isByte(String value) {
    try {
        Byte.parseByte(value, 10);
        return true;
    } catch (NumberFormatException e) {
        return false;
    }
}

-----Original Message-----
From: loic.lefevre@bnpparibas.com [mailto:loic.lefevre@bnpparibas.com] 
Sent: Thursday, November 07, 2002 10:03 AM
To: ant-dev@jakarta.apache.org
Subject: Réf. : RE: Réf. : Re: Commons Validator

    public static final boolean isByte( String value )
    {
        try
        {
            new Byte( value );
            return true;
        }
        catch( Exception e )
        {
            return false;
        }
    }

Cheer,
Loïc

ps: don't have the time to make a patch (sorry)

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


Mime
View raw message