com.logabit.utils
Class ConvertHelper

java.lang.Object
  extended by com.logabit.utils.ConvertHelper

public class ConvertHelper
extends java.lang.Object

This helper class provides some utility methods to convert from string into other datatypes and datastructures.

Author:
Stephan Niedermeier, Andreas Schmid

Constructor Summary
ConvertHelper()
           
 
Method Summary
static boolean convertToBoolean(java.lang.String value, boolean defaultValue)
          Tries to convert the given string into a boolean representation.
static int convertToInteger(java.lang.String value, int defaultValue)
          Tries to convert the given string into a integer representation.
static java.lang.String convertToString(java.lang.String value, java.lang.String defaultValue)
          Looks for the given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConvertHelper

public ConvertHelper()
Method Detail

convertToString

public static java.lang.String convertToString(java.lang.String value,
                                               java.lang.String defaultValue)
Looks for the given string. If this string value is null, the default value will be returned instead.

Parameters:
value - - The string value to look for.
defaultValue - The default value to return if the given string is null.
Returns:
The string value if it is not empty. Otherwise the default value.

convertToBoolean

public static boolean convertToBoolean(java.lang.String value,
                                       boolean defaultValue)
Tries to convert the given string into a boolean representation. If the string is "true", "yes" or a integer number higher than 0, the returned boolean value will become true. If the given string is null or empty, the default value will be returned. In all other cases false will be returned.

Parameters:
value - - The string to convert.
defaultValue - - The default value to return if the string is null or empty.
Returns:
- The boolean representation of the string value.

convertToInteger

public static int convertToInteger(java.lang.String value,
                                   int defaultValue)
Tries to convert the given string into a integer representation. If the given string is null or empty, the default value will be returned.

Parameters:
value - - The string value to convert to integer.
defaultValue - - The default value to return if the string is null or empty.
Returns:
The integer representation of the string value.


Copyright © 2007. All Rights Reserved.