org.appcelerator.titanium.util
Class TiConvert

java.lang.Object
  extended by org.appcelerator.titanium.util.TiConvert

public class TiConvert
extends Object

Utility class for type conversions.


Method Summary
static TiBlob toBlob(HashMap<String,Object> object, String property)
          A wrapper function.
static TiBlob toBlob(Object value)
          Casts and returns value as TiBlob.
static boolean toBoolean(HashMap<String,Object> hashMap, String key)
          Takes a value out of a hash table then attempts to convert it using toBoolean(Object).
static boolean toBoolean(Object value)
          Attempts to convert a value into a boolean, if value is a Boolean or String.
static int toColor(HashMap<String,Object> hashMap, String key)
          This is a wrapper method.
static int toColor(String value)
          This is a wrapper method.
static Date toDate(HashMap<String,Object> hashMap, String key)
          A wrapper function.
static Date toDate(Object value)
          Converts value into Date object and returns it.
static double toDouble(HashMap<String,Object> hashMap, String key)
          Takes a value out of a hash table then attempts to convert it using toDouble(Object) for more details.
static double toDouble(Object value)
          If value is a Double, Integer, or String, converts it to Double.
static float toFloat(HashMap<String,Object> hashMap, String key)
          Takes a value out of a hash table then attempts to convert it using toFloat(Object) for more details.
static float toFloat(HashMap<String,Object> hashMap, String key, float def)
          Takes a value out of a hash table then attempts to convert it using toFloat(Object) for more details.
static float toFloat(Object value)
          If value is a Double, Integer or String, converts it to Float.
static float toFloat(Object value, float def)
          If value is a Double, Integer, Long or String, converts it to Float.
static int toInt(HashMap<String,Object> hashMap, String key)
          Takes a value out of a hash table then attempts to convert it using toInt(Object).
static int toInt(Object value)
          If value is a Double, Integer, Long or String, converts it to Integer.
static int toInt(Object value, int def)
          If value is a Double, Integer, Long or String, converts it to Integer.
static String toJSONString(Object value)
          If value is a Date, formats and returns it.
static String toString(HashMap<String,Object> hashMap, String key)
          Takes a value out of a hash table then attempts to convert it using toString(Object) for more details.
static String toString(Object value)
          Converts a value into a String.
static String toString(Object value, String defaultString)
          Converts a vlaue into a String.
static String[] toStringArray(Object[] parts)
          Converts an Object array into a String array.
 

Method Detail

toColor

public static int toColor(String value)
This is a wrapper method. Refer to TiColorHelper.parseColor(String) for more details.

Parameters:
value - color value to convert.
Returns:
an int representation of the color.

toColor

public static int toColor(HashMap<String,Object> hashMap,
                          String key)
This is a wrapper method. Refer to TiColorHelper.parseColor(String) for more details.

Parameters:
hashMap - the HashMap contains the String representation of the color.
key - the color lookup key.
Returns:
an int representation of the color.

toBoolean

public static boolean toBoolean(Object value)
Attempts to convert a value into a boolean, if value is a Boolean or String. Otherwise, an exception is thrown.

Parameters:
value - the value to convert.
Returns:
a boolean value.

toBoolean

public static boolean toBoolean(HashMap<String,Object> hashMap,
                                String key)
Takes a value out of a hash table then attempts to convert it using toBoolean(Object).

Parameters:
hashMap - the hash map to search.
key - the lookup key.
Returns:
a boolean value.

toInt

public static int toInt(Object value)
If value is a Double, Integer, Long or String, converts it to Integer. Otherwise an exception is thrown.

Parameters:
value - the value to convert.
Returns:
an int value.

toInt

public static int toInt(Object value,
                        int def)
If value is a Double, Integer, Long or String, converts it to Integer. Otherwise returns default value.

Parameters:
value - the value to convert.
def - the default value to return
Returns:
an int value.

toInt

public static int toInt(HashMap<String,Object> hashMap,
                        String key)
Takes a value out of a hash table then attempts to convert it using toInt(Object).

Parameters:
hashMap - the hash map to search.
key - the lookup key.
Returns:
an int value.

toFloat

public static float toFloat(Object value)
If value is a Double, Integer or String, converts it to Float. Otherwise, an exception is thrown.

Parameters:
value - the value to convert.
Returns:
a float value.

toFloat

public static float toFloat(Object value,
                            float def)
If value is a Double, Integer, Long or String, converts it to Float. Otherwise returns default value.

Parameters:
value - the value to convert.
def - the default value to return
Returns:
an float value.

toFloat

public static float toFloat(HashMap<String,Object> hashMap,
                            String key)
Takes a value out of a hash table then attempts to convert it using toFloat(Object) for more details.

Parameters:
hashMap - the hash map to search.
key - the lookup key.
Returns:
a float value.

toFloat

public static float toFloat(HashMap<String,Object> hashMap,
                            String key,
                            float def)
Takes a value out of a hash table then attempts to convert it using toFloat(Object) for more details.

Parameters:
hashMap - the hash map to search.
key - the lookup key.
def - the default value to return.
Returns:
a float value.

toDouble

public static double toDouble(Object value)
If value is a Double, Integer, or String, converts it to Double. Otherwise, an exception is thrown.

Parameters:
value - the value to convert.
Returns:
a double value.

toDouble

public static double toDouble(HashMap<String,Object> hashMap,
                              String key)
Takes a value out of a hash table then attempts to convert it using toDouble(Object) for more details.

Parameters:
hashMap - the hash map to search.
key - the lookup key.
Returns:
a double.

toString

public static String toString(Object value,
                              String defaultString)
Converts a vlaue into a String. If value is null, a default value is returned.

Parameters:
value - the value to convert.
defaultString - the default value.
Returns:
a String.

toString

public static String toString(Object value)
Converts a value into a String. If value is null, returns null.

Parameters:
value - the value to convert.
Returns:
String or null.

toString

public static String toString(HashMap<String,Object> hashMap,
                              String key)
Takes a value out of a hash table then attempts to convert it using toString(Object) for more details.

Parameters:
hashMap - the hash map to search.
key - the lookup key.
Returns:
String or null.

toStringArray

public static String[] toStringArray(Object[] parts)
Converts an Object array into a String array.

Parameters:
parts - the object array to convert
Returns:
a String array.

toBlob

public static TiBlob toBlob(Object value)
Casts and returns value as TiBlob.

Parameters:
value - must be of type TiBlob.
Returns:
a TiBlob instance.

toBlob

public static TiBlob toBlob(HashMap<String,Object> object,
                            String property)
A wrapper function. Refer to toBlob(Object) for more details.

Parameters:
object - the hashmap.
property - the lookup key.
Returns:
a TiBlob instance.

toJSONString

public static String toJSONString(Object value)
If value is a Date, formats and returns it. Otherwise, return a String representation of value.

Parameters:
value - the value to convert.
Returns:
a String.

toDate

public static Date toDate(Object value)
Converts value into Date object and returns it.

Parameters:
value - the value to convert.
Returns:
a Date instance.

toDate

public static Date toDate(HashMap<String,Object> hashMap,
                          String key)
A wrapper function. Refer to toDate(Object) for more details.

Parameters:
hashMap - the hash map to search.
key - the lookup key
Returns:
a Date instance.


Copyright © 2010-2012 Appcelerator, Inc. Licensed under the Apache License 2.0