public class DefaultTypeTransformation
extends Object
Class providing various type conversions, coercions and boxing/unboxing operations.
| Modifiers | Name | Description |
|---|---|---|
protected static Object[] |
EMPTY_ARGUMENTS |
Empty array constant for backwards compatibility. |
protected static BigInteger |
ONE_NEG |
BigInteger constant representing negative one, for backwards compatibility. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static Collection |
arrayAsCollection(Object value)Converts an array (including primitive arrays) to a Collection. |
<T> |
public static Collection<T> |
arrayAsCollection(T[] value)Converts an object array to a Collection backed by Arrays.asList. |
|
public static Object |
asArray(Object object, Class type)Converts an object to an array of the specified target array type. |
<T> |
public static Collection<T> |
asCollection(T[] value)Converts a generic typed array to a typed Collection. |
|
public static Collection |
asCollection(Object value)Converts an object to a Collection. |
|
public static boolean |
booleanUnbox(Object value)Unboxes an object to a primitive boolean value. |
|
public static Object |
box(boolean value)Boxes a primitive boolean value into a Boolean wrapper object. |
|
public static Object |
box(byte value)Boxes a primitive byte value into a Byte wrapper object. |
|
public static Object |
box(char value)Boxes a primitive char value into a Character wrapper object. |
|
public static Object |
box(short value)Boxes a primitive short value into a Short wrapper object. |
|
public static Object |
box(int value)Boxes a primitive int value into an Integer wrapper object. |
|
public static Object |
box(long value)Boxes a primitive long value into a Long wrapper object. |
|
public static Object |
box(float value)Boxes a primitive float value into a Float wrapper object. |
|
public static Object |
box(double value)Boxes a primitive double value into a Double wrapper object. |
|
public static byte |
byteUnbox(Object value)Unboxes an object to a primitive byte value. |
|
public static boolean |
castToBoolean(Object 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)Attempts to coerce an object to a char value (as a Character wrapper). |
|
public static Number |
castToNumber(Object object)Attempts to coerce an object to a Number. |
|
public static Number |
castToNumber(Object object, Class type)Attempts to coerce an object to a Number of a specific target type. |
|
public static Object |
castToType(Object object, Class type)Performs a comprehensive type cast/coercion of an object to a target class. |
|
public static Object |
castToVargsArray(Object[] origin, int firstVargsPos, Class<?> arrayType)Converts an array of arguments to a varargs array of the specified type. |
|
public static char |
charUnbox(Object value)Unboxes an object to a primitive char value. |
|
public static boolean |
compareArrayEqual(Object left, Object right)Compares two arrays element-wise for equality. |
|
public static boolean |
compareEqual(Object left, Object right)Compares two objects for equality, handling nulls and type coercion. |
|
public static int |
compareTo(Object left, Object right)Compares the two objects handling nulls gracefully and performing numeric type coercion if required |
|
public static boolean[] |
convertToBooleanArray(Object a) |
|
public static byte[] |
convertToByteArray(Object a) |
|
public static char[] |
convertToCharArray(Object a) |
|
public static double[] |
convertToDoubleArray(Object a) |
|
public static float[] |
convertToFloatArray(Object a) |
|
public static int[] |
convertToIntArray(Object a) |
|
public static long[] |
convertToLongArray(Object a) |
|
public static Object |
convertToPrimitiveArray(Object a, Class type) |
|
public static short[] |
convertToShortArray(Object a) |
|
public static double |
doubleUnbox(Object value)Unboxes an object to a primitive double value. |
|
public static float |
floatUnbox(Object value)Unboxes an object to a primitive float value. |
|
public static Character |
getCharFromSizeOneString(Object value) |
|
public static int |
intUnbox(Object value)Unboxes an object to a primitive int value. |
|
public static boolean |
isEnumSubclass(Object value)Determines whether the value object is a Class object representing a subclass of java.lang.Enum. |
|
public static long |
longUnbox(Object value)Unboxes an object to a primitive long value. |
|
public static Object[] |
primitiveArrayBox(Object array)Boxes a primitive array to an object array. |
|
public static List |
primitiveArrayToList(Object array)Allows conversion of arrays into a mutable List |
|
public static List |
primitiveArrayToUnmodifiableList(Object array)Allows conversion of arrays into an immutable List view |
|
public static short |
shortUnbox(Object value)Unboxes an object to a primitive short value. |
Empty array constant for backwards compatibility.
BigInteger constant representing negative one, for backwards compatibility.
Converts an array (including primitive arrays) to a Collection.
value - an array (primitive or object array) Converts an object array to a Collection backed by Arrays.asList.
T - the element typevalue - an object arrayConverts an object to an array of the specified target array type.
Handles direct assignment if already correct type, stream conversions (IntStream, LongStream, DoubleStream), and generic collection to array conversions with element type casting.
object - the object to convert (Collection, Stream, or already an array)type - the target array typeConverts a generic typed array to a typed Collection.
T - the element typevalue - the typed array to convertConverts an object to a Collection.
Handles the following conversions:
value - the object to convert (may be null) Unboxes an object to a primitive boolean value.
Uses castToBoolean(Object) to perform the coercion.
value - the object to unbox (may be null for false, Boolean, or any object with asBoolean()) Boxes a primitive boolean value into a Boolean wrapper object.
value - the boolean value to boxBoolean.TRUE or Boolean.FALSE Boxes a primitive byte value into a Byte wrapper object.
value - the byte value to box Boxes a primitive char value into a Character wrapper object.
value - the char value to box Boxes a primitive short value into a Short wrapper object.
value - the short value to box Boxes a primitive int value into an Integer wrapper object.
value - the int value to box Boxes a primitive long value into a Long wrapper object.
value - the long value to box Boxes a primitive float value into a Float wrapper object.
value - the float value to box Boxes a primitive double value into a Double wrapper object.
value - the double value to box Unboxes an object to a primitive byte value.
Converts the object to a Number and then extracts its byte value.
value - the object to unbox (typically a wrapper object or string representation) Method used for coercing an object to a boolean value,
thanks to an asBoolean() method added on types.
object - to coerce to a boolean value Attempts to coerce an object to a char value (as a Character wrapper).
Accepts Character objects, Numbers (converted via intValue), or Strings of length 1.
object - the object to coerce (Character, Number, or String) Attempts to coerce an object to a Number.
If the object is already a Number, it is returned as-is. Characters are converted to their numeric code point. Strings of length 1 are converted to their character code point. GStrings are converted to String first, then processed.
object - the object to coerce (Number, Character, GString, or String) Attempts to coerce an object to a Number of a specific target type.
If the object is already a Number, it is returned as-is. Characters are converted to their numeric code point. Strings of length 1 are converted to their character code point. GStrings are converted to String first, then processed.
object - the object to coerce (Number, Character, GString, or String)type - the target numeric type (used for error reporting)Performs a comprehensive type cast/coercion of an object to a target class.
Handles the following conversions:
object - the object to cast (may be null)type - the target type to cast toConverts an array of arguments to a varargs array of the specified type.
Handles conversion of remaining arguments starting from the specified position into a properly typed array. If the argument at the start position is already the target array type and it's the only remaining argument, returns it unchanged. Otherwise, creates a new array with type-converted elements.
origin - the original array of argumentsfirstVargsPos - the index of the first varargs elementarrayType - the target array type Unboxes an object to a primitive char value.
Returns the null character ('\u0000') if the value is null.
Otherwise delegates to ShortTypeHandling.castToChar.
value - the object to unbox (may be null, Character, Number, or String)Compares two arrays element-wise for equality.
Performs element-by-element comparison of two arrays using compareEqual(Object, Object). Returns true only if both arrays have the same length and all corresponding elements are equal. Null arrays are handled according to standard null comparison semantics.
left - the first array to compareright - the second array to compareCompares two objects for equality, handling nulls and type coercion.
Performs semantic equality comparison with proper handling of null values, null objects, Comparable types, and arrays. Applies numeric type coercion when appropriate.
left - the first object to compareright - the second object to compareCompares the two objects handling nulls gracefully and performing numeric type coercion if required
Unboxes an object to a primitive double value.
Returns Double.NaN if the value is null.
Otherwise converts the object to a Number and extracts its double value.
value - the object to unbox (typically a wrapper object or string representation, may be null) Unboxes an object to a primitive float value.
Returns Float.NaN if the value is null.
Otherwise converts the object to a Number and extracts its float value.
value - the object to unbox (typically a wrapper object or string representation, may be null) Unboxes an object to a primitive int value.
Converts the object to a Number and then extracts its int value.
value - the object to unbox (typically a wrapper object or string representation)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.
value - an object Unboxes an object to a primitive long value.
Converts the object to a Number and then extracts its long value.
value - the object to unbox (typically a wrapper object or string representation)Boxes a primitive array to an object array.
Converts primitive values in the array to their boxed equivalents. Each primitive element is converted to its corresponding wrapper class (e.g., int to Integer).
array - the primitive array to boxAllows conversion of arrays into a mutable List
array - an arrayAllows conversion of arrays into an immutable List view
array - an array Unboxes an object to a primitive short value.
Converts the object to a Number and then extracts its short value.
value - the object to unbox (typically a wrapper object or string representation)