Top Description Fields Constructors Methods
org.codehaus.groovy.runtime.typehandling

public Class DefaultTypeTransformation

extends Object
Class Inheritance
Imports
groovy.lang.Closure, .GString, .GroovyRuntimeException, org.codehaus.groovy.reflection.ReflectionCache, org.codehaus.groovy.reflection.stdclasses.CachedSAMClass, org.codehaus.groovy.runtime.DefaultGroovyMethods, .InvokerHelper, .InvokerInvocationException, .IteratorClosureAdapter, .MethodClosure, .NullObject, .ResourceGroovyMethods, .StringGroovyMethods, java.io.File, .IOException, java.lang.reflect.Array, .Method, .Modifier, java.math.BigDecimal, .BigInteger, java.text.MessageFormat, java.util.ArrayList, .Arrays, .Collection, .Collections, .Iterator, .LinkedHashSet, .List, .Map, .Objects

Class providing various type conversions, coercions and boxing/unboxing operations.

Field Summary

Modifier and TypeField and Description
protected static final Object[]
private static final Object[]
protected static final BigInteger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Collection<E>
public static <T> Collection<T>
arrayAsCollection(T[] value)

public static Object
asArray(Object object, Class<T> type)

public static <T> Collection<T>
asCollection(T[] value)

public static Collection<E>
public static boolean
public static Object
box(boolean value)

Deprecated
public static Object
box(byte value)

Deprecated
public static Object
box(char value)

Deprecated
public static Object
box(short value)

Deprecated
public static Object
box(int value)

Deprecated
public static Object
box(long value)

Deprecated
public static Object
box(float value)

Deprecated
public static Object
box(double value)

Deprecated
public static byte
public static boolean

Returns:

a boolean value
castToBoolean
(Object
to coerce to a boolean value
object
)

Method used for coercing an object to a boolean value, thanks to an asBoolean() method added on types.

public static char
castToChar(Object object)

Deprecated
public static Number
public static Number
castToNumber(Object object, Class<T> type)

private static Object
castToPrimitive(Object object, Class<T> type)

public static Object
castToType(Object object, Class<T> type)

public static Object
castToVargsArray(Object[] origin, int firstVargsPos, Class<?> arrayType)

public static char
public static boolean
public static boolean
compareEqual(Object left, Object right)

public static int
compareTo(Object left, Object right)

Compares the two objects handling nulls gracefully and performing numeric type coercion if required

private static int
compareToWithEqualityCheck(Object left, Object right, boolean equalityCheckOnly)

private static Object
private static Object
private static Object
continueCastOnSAM(Object object, Class<T> type)

public static boolean[]
public static byte[]
convertToByteArray(Object a)

Deprecated
public static char[]
convertToCharArray(Object a)

Deprecated
public static double[]
public static float[]
public static int[]
convertToIntArray(Object a)

Deprecated
public static long[]
convertToLongArray(Object a)

Deprecated
public static Object
convertToPrimitiveArray(Object a, Class<T> type)

Deprecated
public static short[]
public static double
public static float
public static Character
getCharFromSizeOneString(Object value)

Deprecated
public static int
public static boolean

Returns:

true if the object is an Enum
isEnumSubclass
(Object
an object
value
)

Deprecated
Determines whether the value object is a Class object representing a subclass of java.lang.Enum.
private static boolean

Returns:

true if the given value is a valid character string (i.e. has length of 1)
isValidCharacterString
(Object value)

public static long
public static Object[]
public static List<E>

Returns:

the array as a List
primitiveArrayToList
(Object
an array
array
)

Allows conversion of arrays into a mutable List

public static short
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_ARGUMENTSback to summary
protected static final Object[] EMPTY_ARGUMENTS
EMPTY_OBJECT_ARRAYback to summary
private static final Object[] EMPTY_OBJECT_ARRAY
ONE_NEGback to summary
protected static final BigInteger ONE_NEG

Constructor Detail

DefaultTypeTransformationback to summary
public DefaultTypeTransformation()

Method Detail

arrayAsCollectionback to summary
public static Collection<E> arrayAsCollection(Object value)
arrayAsCollectionback to summary
public static <T> Collection<T> arrayAsCollection(T[] value)
asArrayback to summary
public static Object asArray(Object object, Class<T> type)
asCollectionback to summary
public static <T> Collection<T> asCollection(T[] value)
asCollectionback to summary
public static Collection<E> asCollection(Object value)
booleanUnboxback to summary
public static boolean booleanUnbox(Object value)
boxback to summary
public static Object box(boolean value)

Deprecated

Annotations
@Deprecated
boxback to summary
public static Object box(byte value)

Deprecated

Annotations
@Deprecated
boxback to summary
public static Object box(char value)

Deprecated

Annotations
@Deprecated
boxback to summary
public static Object box(short value)

Deprecated

Annotations
@Deprecated
boxback to summary
public static Object box(int value)

Deprecated

Annotations
@Deprecated
boxback to summary
public static Object box(long value)

Deprecated

Annotations
@Deprecated
boxback to summary
public static Object box(float value)

Deprecated

Annotations
@Deprecated
boxback to summary
public static Object box(double value)

Deprecated

Annotations
@Deprecated
byteUnboxback to summary
public static byte byteUnbox(Object value)
castToBooleanback to summary
public static boolean castToBoolean(Object object)

Method used for coercing an object to a boolean value, thanks to an asBoolean() method added on types.

Parameters
object:Object

to coerce to a boolean value

Returns:boolean

a boolean value

castToCharback to summary
public static char castToChar(Object object)

Deprecated

Annotations
@Deprecated
castToNumberback to summary
public static Number castToNumber(Object object)
castToNumberback to summary
public static Number castToNumber(Object object, Class<T> type)
castToPrimitiveback to summary
private static Object castToPrimitive(Object object, Class<T> type)
castToTypeback to summary
public static Object castToType(Object object, Class<T> type)
castToVargsArrayback to summary
public static Object castToVargsArray(Object[] origin, int firstVargsPos, Class<?> arrayType)
charUnboxback to summary
public static char charUnbox(Object value)
compareArrayEqualback to summary
public static boolean compareArrayEqual(Object left, Object right)
compareEqualback to summary
public static boolean compareEqual(Object left, Object right)
compareToback to summary
public static int compareTo(Object left, Object right)

Compares the two objects handling nulls gracefully and performing numeric type coercion if required

compareToWithEqualityCheckback to summary
private static int compareToWithEqualityCheck(Object left, Object right, boolean equalityCheckOnly)
continueCastOnCollectionback to summary
private static Object continueCastOnCollection(Object object, Class<T> type)
continueCastOnNumberback to summary
private static Object continueCastOnNumber(Object object, Class<T> type)
continueCastOnSAMback to summary
private static Object continueCastOnSAM(Object object, Class<T> type)
convertToBooleanArrayback to summary
public static boolean[] convertToBooleanArray(Object a)

Deprecated

Annotations
@Deprecated
convertToByteArrayback to summary
public static byte[] convertToByteArray(Object a)

Deprecated

Annotations
@Deprecated
convertToCharArrayback to summary
public static char[] convertToCharArray(Object a)

Deprecated

Annotations
@Deprecated
convertToDoubleArrayback to summary
public static double[] convertToDoubleArray(Object a)

Deprecated

Annotations
@Deprecated
convertToFloatArrayback to summary
public static float[] convertToFloatArray(Object a)

Deprecated

Annotations
@Deprecated
convertToIntArrayback to summary
public static int[] convertToIntArray(Object a)

Deprecated

Annotations
@Deprecated
convertToLongArrayback to summary
public static long[] convertToLongArray(Object a)

Deprecated

Annotations
@Deprecated
convertToPrimitiveArrayback to summary
public static Object convertToPrimitiveArray(Object a, Class<T> type)

Deprecated

Annotations
@Deprecated
convertToShortArrayback to summary
public static short[] convertToShortArray(Object a)

Deprecated

Annotations
@Deprecated
doubleUnboxback to summary
public static double doubleUnbox(Object value)
floatUnboxback to summary
public static float floatUnbox(Object value)
getCharFromSizeOneStringback to summary
public static Character getCharFromSizeOneString(Object value)

Deprecated

Annotations
@Deprecated
intUnboxback to summary
public static int intUnbox(Object value)
isEnumSubclassback to summary
public static boolean isEnumSubclass(Object value)

Deprecated

Determines whether the value object is a Class object representing a subclass of java.lang.Enum. Uses class name check to avoid breaking on pre-Java 5 JREs.

Parameters
value:Object

an object

Returns:boolean

true if the object is an Enum

Annotations
@Deprecated
isValidCharacterStringback to summary
private static boolean isValidCharacterString(Object value)
Returns:boolean

true if the given value is a valid character string (i.e. has length of 1)

longUnboxback to summary
public static long longUnbox(Object value)
primitiveArrayBoxback to summary
public static Object[] primitiveArrayBox(Object array)
primitiveArrayToListback to summary
public static List<E> primitiveArrayToList(Object array)

Allows conversion of arrays into a mutable List

Parameters
array:Object

an array

Returns:List<E>

the array as a List

shortUnboxback to summary
public static short shortUnbox(Object value)