Improved performance if str is null.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137672 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fredrik Westermarck 2003-09-23 17:02:10 +00:00
parent 00731e8e2a
commit c978c7f029
1 changed files with 7 additions and 1 deletions

View File

@ -71,7 +71,7 @@
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
* @since 2.0
* @version $Id: NumberUtils.java,v 1.15 2003/09/23 15:46:42 fredrik Exp $
* @version $Id: NumberUtils.java,v 1.16 2003/09/23 17:02:10 fredrik Exp $
*/
public class NumberUtils {
@ -204,6 +204,9 @@ public static int stringToInt(String str, int defaultValue) {
* @return the int represented by the string, or the default if conversion fails
*/
public static int toInt(String str, int defaultValue) {
if(str == null) {
return defaultValue;
}
try {
return Integer.parseInt(str);
} catch (NumberFormatException nfe) {
@ -250,6 +253,9 @@ public static long toLong(String str) {
* @since 2.1
*/
public static long toLong(String str, long defaultValue) {
if (str == null) {
return defaultValue;
}
try {
return Long.parseLong(str);
} catch (NumberFormatException nfe) {