List of utility methods to do Object Type Case
T | castAs(Class cast As if (obj == null) { return null; try { if (clazz.isInstance(obj)) { return clazz.cast(obj); } catch (ClassCastException ex) { ... |
double[] | castAsDoubleArray(int[] input) cast As Double Array double[] output; output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = (double) input[i]; return output; |
Class | castClass(Class> aClass) cast Class return (Class<T>) aClass;
|
U | castClone(U obj, T superClone) cast Clone @SuppressWarnings("unchecked") U clone = (U) superClone; return clone; |
T | castEnum(Enum> enum_param) This method just is a workaround such that maven can compile and do not proclaim when an enum is directly casted! return (T) enum_param; |
U | castEnum(T from, U[] to) cast Enum return to[from.ordinal()];
|
String | castForRegex(String textContent) cast For Regex return textContent.replace("\\", "\\\\").replace("/", "\\/").replace("*", "\\*").replace("+", "\\+") .replace(".", "\\.").replace("?", "\\?").replace(")", "\\)").replace("{", "\\{").replace("}", "\\}") .replace("(", "\\(").replace("[", "\\[").replace("]", "\\]").replace("%", "\\%"); |
String | castingNum(double n) utility if (Math.ceil(n) == Math.floor(n)) { return ("" + (int) n); } else { return "" + n; |
Object | castingUtil(String value, Class classCasting) casting Util Object object = value; if (Number.class.isAssignableFrom(classCasting)) { if (classCasting.isAssignableFrom(Double.class)) { return Double.valueOf(value); } else if (classCasting.isAssignableFrom(Long.class)) { return Long.valueOf(value); } else if (classCasting.isAssignableFrom(Float.class)) { return Float.valueOf(value); ... |
T | castInstance(Object o, Class cast Instance try { return clazz.cast(o); } catch (ClassCastException e) { throw new IllegalArgumentException(e); |