org.jnario.lib
Class StringConversions

java.lang.Object
  extended by org.jnario.lib.StringConversions

public class StringConversions
extends Object

Jnario extensions to convert string values into other formats. Useful when converting StepArguments.

Author:
Sebastian Benz - Initial contribution and API

Constructor Summary
StringConversions()
           
 
Method Summary
static BigDecimal toBigDecimal(String s)
          Translates the string representation of a BigDecimal into a BigDecimal.
static boolean toBool(String s)
          Returns a Boolean with a value represented by the specified string.
static double toDouble(String s)
          Returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.
static int toInt(String s)
          Parses the string argument as a signed decimal integer.
static List<String> toList(String s)
          Convert a comma separated value string into a List.
static long toLong(String s)
          Parses the string argument as a signed decimal long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringConversions

public StringConversions()
Method Detail

toInt

public static int toInt(String s)
Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the #parseInt(java.lang.String, int) method.

Parameters:
s - a String containing the int representation to be parsed
Returns:
the integer value represented by the argument in decimal.
Throws:
NumberFormatException - if the string does not contain a parsable integer.
See Also:
Integer.parseInt(String)

toLong

public static long toLong(String s)
Parses the string argument as a signed decimal long. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' (\u002D') to indicate a negative value. The resulting long value is returned, exactly as if the argument and the radix 10 were given as arguments to the #parseLong(java.lang.String, int) method.

Note that neither the character L ('\u004C') nor l ('\u006C') is permitted to appear at the end of the string as a type indicator, as would be permitted in Java programming language source code.

Parameters:
s - a String containing the long representation to be parsed
Returns:
the long represented by the argument in decimal.
Throws:
NumberFormatException - if the string does not contain a parsable long.
See Also:
Long.parseLong(String)

toDouble

public static double toDouble(String s)
Returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.

Parameters:
s - the string to be parsed.
Returns:
the double value represented by the string argument.
Throws:
NumberFormatException - if the string does not contain a parsable double.
See Also:
Double.parseDouble(String)

toBool

public static boolean toBool(String s)
Returns a Boolean with a value represented by the specified string. The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string "true".

Parameters:
s - a string.
Returns:
the Boolean value represented by the string.
See Also:
Boolean.parseBoolean(String)

toBigDecimal

public static BigDecimal toBigDecimal(String s)
Translates the string representation of a BigDecimal into a BigDecimal. The string representation consists of an optional sign, '+' ( '\u002B') or '-' ('\u002D'), followed by a sequence of zero or more decimal digits ("the integer"), optionally followed by a fraction, optionally followed by an exponent.


toList

public static List<String> toList(String s)
Convert a comma separated value string into a List.

Parameters:
s - a list with comma separated values
Returns:
a list with the trimmed values


Copyright © 2012-2013 BMW Car IT. All Rights Reserved.