From cf53892b15adef4e1311ac28d6c85e58cb550bda Mon Sep 17 00:00:00 2001 From: shaper Date: Fri, 15 Mar 2002 18:05:36 +0000 Subject: [PATCH] Added isInteger(). git-svn-id: https://samskivert.googlecode.com/svn/trunk@655 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/util/StringUtil.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/StringUtil.java b/projects/samskivert/src/java/com/samskivert/util/StringUtil.java index 6687847c..381aec07 100644 --- a/projects/samskivert/src/java/com/samskivert/util/StringUtil.java +++ b/projects/samskivert/src/java/com/samskivert/util/StringUtil.java @@ -1,5 +1,5 @@ // -// $Id: StringUtil.java,v 1.32 2002/03/08 02:40:02 mdb Exp $ +// $Id: StringUtil.java,v 1.33 2002/03/15 18:05:36 shaper Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -94,6 +94,21 @@ public class StringUtil } } + /** + * Returns whether the supplied string represents an integer value by + * attempting to parse it with {@link Integer#parseInt}. + */ + public static boolean isInteger (String value) + { + try { + Integer.parseInt(value); + return true; + } catch (NumberFormatException nfe) { + // fall through + } + return false; + } + /** * Converts the supplied object to a string. Normally this is * accomplished via the object's built in toString()