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:
parent
00731e8e2a
commit
c978c7f029
|
@ -71,7 +71,7 @@
|
||||||
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
|
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
|
||||||
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
|
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
|
||||||
* @since 2.0
|
* @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 {
|
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
|
* @return the int represented by the string, or the default if conversion fails
|
||||||
*/
|
*/
|
||||||
public static int toInt(String str, int defaultValue) {
|
public static int toInt(String str, int defaultValue) {
|
||||||
|
if(str == null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(str);
|
return Integer.parseInt(str);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
|
@ -250,6 +253,9 @@ public static long toLong(String str) {
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
*/
|
*/
|
||||||
public static long toLong(String str, long defaultValue) {
|
public static long toLong(String str, long defaultValue) {
|
||||||
|
if (str == null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return Long.parseLong(str);
|
return Long.parseLong(str);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
|
|
Loading…
Reference in New Issue