Class ConversionHelper

java.lang.Object
com.polarion.core.util.types.ConversionHelper

public class ConversionHelper extends Object
Helper for type conversions.

The general contract applied for the conversion methods of this class is that

  • when object is null, defaultValue is returned
  • when object is an instance of the desired type, reference to it is returned
  • when the conversion fails, defaultValue is returned
  • null is returned only in the case when both object and defaultValue are null
Version:
$Revision: 1.3 $ $Date: 2003/12/29 18:58:51 $
Author:
Ondrej Chylik, Polarion Software
  • Method Details

    • getString

      public static String getString(Object object, String defaultValue)
      Converts an object to string.
    • getObject

      public static Object getObject(Object object, Class type, Object defaultValue)
      Converts an object to the specified type.

      Note: Default value which is not an instance of the given type is an invalid argument for this method.

    • getBoolean

      public static boolean getBoolean(Object object, boolean defaultValue)
      Converts an object to primitive boolean type. String to boolean conversion applies to values "true", "on" or "yes" and "false", "off" or "no", case insensitive.
    • getInt

      public static int getInt(Object object, int defaultValue)
      Converts an object to primitive int type. Applies to any instance of Number or to strings.
    • getLong

      public static long getLong(Object object, long defaultValue)
      Converts an object to primitive long type. Applies to any instance of Number or to strings.
    • getFloat

      public static float getFloat(Object object, float defaultValue)
      Converts an object to primitive float type. Applies to any instance of Number or to strings.
    • getDouble

      public static double getDouble(Object object, double defaultValue)
      Converts an object to primitive double type. Applies to any instance of Number or to strings.
    • getByte

      public static byte getByte(Object object, byte defaultValue)
      Converts an object to primitive byte type. Applies to any instance of Number or to strings.
    • getShort

      public static short getShort(Object object, short defaultValue)
      Converts an object to primitive short type. Applies to any instance of Number or to strings.
    • getBoolean

      public static Boolean getBoolean(Object object, Boolean defaultValue)
      Converts an object to Boolean. String to boolean conversion applies to values "true", "on" or "yes" and "false", "off" or "no", case insensitive.
    • getIntenger

      public static Integer getIntenger(Object object, Integer defaultValue)
      Converts an object to Integer. Applies to any instance of Number or to strings.
    • getLong

      public static Long getLong(Object object, Long defaultValue)
      Converts an object to Long. Applies to any instance of Number or to strings.
    • getFloat

      public static Float getFloat(Object object, Float defaultValue)
      Converts an object to Float. Applies to any instance of Number or to strings.
    • getDouble

      public static Double getDouble(Object object, Double defaultValue)
      Converts an object to Double. Applies to any instance of Double or to strings.
    • getByte

      public static Byte getByte(Object object, Byte defaultValue)
      Converts an object to Byte. Applies to any instance of Number or to strings.
    • getShort

      public static Short getShort(Object object, Short defaultValue)
      Converts an object to Short. Applies to any instance of Number or to strings.