com.canoo.webtest.util
Class ConversionUtil

java.lang.Object
  extended by com.canoo.webtest.util.ConversionUtil

public class ConversionUtil
extends Object

Date: May 4, 2005

Author:
paulk

Constructor Summary
ConversionUtil()
           
 
Method Summary
static boolean convertToBoolean(String value, boolean defaultValue)
          Convert a string value to a boolean according to ANT defintion of true.
static double convertToDouble(String value, double defaultValue)
          Convert a string value to a double.
static float convertToFloat(String value, float defaultValue)
          Convert a string value to a float.
static int convertToInt(String value, int defaultValue)
          Convert a string value to an integer.
static int convertToIntOrReject(String property, String value, Step step)
          Parses a value as integer.
static long convertToLong(String value, long defaultValue)
          Convert a string value to a long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConversionUtil

public ConversionUtil()
Method Detail

convertToBoolean

public static boolean convertToBoolean(String value,
                                       boolean defaultValue)
Convert a string value to a boolean according to ANT defintion of true. If the value is null or empty, return the specified default value.

Returns:
parsed value. If value is null or empty, return default value.

convertToInt

public static int convertToInt(String value,
                               int defaultValue)
Convert a string value to an integer. If the value is null, return the specified default value.

Returns:
parsed value. If value is null return default value.
Throws:
NumberFormatException

convertToLong

public static long convertToLong(String value,
                                 long defaultValue)
Convert a string value to a long. If the value is null, return the specified default value.

Returns:
parsed value. If value is null return default value.
Throws:
NumberFormatException

convertToFloat

public static float convertToFloat(String value,
                                   float defaultValue)
Convert a string value to a float. If the value is null, return the specified default value.

Returns:
parsed value. If value is null return default value.
Throws:
NumberFormatException

convertToDouble

public static double convertToDouble(String value,
                                     double defaultValue)
Convert a string value to a double. If the value is null, return the specified default value.

Returns:
parsed value. If value is null return default value.
Throws:
NumberFormatException

convertToIntOrReject

public static int convertToIntOrReject(String property,
                                       String value,
                                       Step step)
                                throws StepExecutionException
Parses a value as integer.

Parameters:
property - the name of the property (used in the exception's message if parse fails)
value - the value to parse
Returns:
the parsed int
Throws:
StepExecutionException - if the value can't be parsed as int

Copyright © 2001-2007 Canoo Engineering AG, Basel. All rights reserved.