List of utility methods to do Object Type Case
long | castInttoLong(int x) cast Intto Long return x & 0x00000000ffffffffL;
|
T | castNode(Class> jsonNode, Class cast Node if (classz.isAssignableFrom(jsonNode)) { return (T) classz; throw new ClassCastException("can not cast " + classz + " to " + jsonNode); |
T[] | castNonNullArray( T [] arr) cast Non Null Array assert arr != null : "Misuse of castNonNullArray: called with a null array argument"; for (int i = 0; i < arr.length; ++i) { assert arr[i] != null : "Misuse of castNonNull: called with a null array element"; checkIfArray(arr[i]); return ( T[]) arr; |
R | castNullableParameterTo(String parameterName, T value, Class cast Nullable Parameter To final R result; if (value != null) { if (!requiredType.isInstance(value)) { throw new IllegalArgumentException( parameterName + " is not of type " + requiredType.getName() + "."); } else { result = requiredType.cast(value); } else { result = null; return result; |
T | castNumber(Number num, Class Casts provided number value to desired number type. Number cNum = 0; if (clazz.isAssignableFrom(Long.class)) { cNum = num.longValue(); } else if (clazz.isAssignableFrom(Integer.class)) { cNum = num.intValue(); } else if (clazz.isAssignableFrom(Byte.class)) { cNum = num.byteValue(); } else if (clazz.isAssignableFrom(Float.class)) { ... |
T | castObject(Class cast Object return clazz.cast(object);
|
boolean | castObject(Object fromObj, Class> toClass) castObject returns boolean value indicating whether the value need to be cast if (toClass.equals(fromObj.getClass())) { return false; } else if (toClass.isPrimitive()) { if (toClass.equals(long.class) && fromObj.getClass().equals(Long.class)) { return false; } else if (toClass.equals(int.class) && fromObj.getClass().equals(Integer.class)) { return false; } else if (toClass.equals(double.class) && fromObj.getClass().equals(Double.class)) { ... |
T | castObject(Object ob) Reads an object from an input and converts it to the appropriate type. return (T) ob;
|
T | castOrDefault(Class Casts a value to another type, returning a default value if the cast is not possible or if the value is null and null values are not allowed. if (value == null) return allowNull ? null : defaultValue; if (!type.isAssignableFrom(value.getClass())) { return defaultValue; return (T) value; |
T | castOrDefault(Object o, Class cast Or Default return o == null || !type.isInstance(o) ? def : (T) o;
|