@Test public void castObjectFloatArrayTest() { final Object value = ClassCast.cast(new Object[]{1.0, 2, "0.6", null, "" }, "[Ljava.lang.Float;"); assertEquals(value instanceof Float[], true); assertEquals(((Float[]) value)[0], (Float) 1F); assertEquals(((Float[]) value)[1], (Float) 2F); assertEquals(((Float[]) value)[2], (Float) 0.6F); }
public static final Object cast(final String value, final String typeName) { if (value == null) { return null; } try { switch (typeName) { case INTEGER_OBJ: case INT: return Integer.valueOf(value); case LONG_OBJ: case LONG: return Long.valueOf(value); case DOUBLE_OBJ: case DOUBLE: return Double.valueOf(value); case FLOAT_OBJ: case FLOAT: return Float.valueOf(value); case BOOLEAN_OBJ: case BOOLEAN: if (ObjectCompare.isInList(value.toUpperCase(), "1", "YES", "Y", "TRUE")) { return Boolean.TRUE; } else if (ObjectCompare.isInList(value.toUpperCase(), "0", "NO", "N", "FALSE")) { return Boolean.FALSE; } else { return Boolean.valueOf(value); } case STRING: return value; case DATE_UTIL: case DATE_SQL: return DateFormat.parse(value, Pattern.DATETIME); case TIMESTAMP: final long time = DateFormat.parse(value, Pattern.TIMESTAMP).getTime(); return new Timestamp(time); default: return JSON.parseObject(value, Class.forName(typeName)); } } catch (final ClassCastException | ClassNotFoundException | ParseException e) { throw new org.nanoframework.commons.exception.ClassCastException(e.getMessage(), e); } }
ClassCast { public static final Object cast(final String value, final String typeName) { if (value == null) { return null; } try { switch (typeName) { case INTEGER_OBJ: case INT: return Integer.valueOf(value); case LONG_OBJ: case LONG: return Long.valueOf(value); case DOUBLE_OBJ: case DOUBLE: return Double.valueOf(value); case FLOAT_OBJ: case FLOAT: return Float.valueOf(value); case BOOLEAN_OBJ: case BOOLEAN: if (ObjectCompare.isInList(value.toUpperCase(), "1", "YES", "Y", "TRUE")) { return Boolean.TRUE; } else if (ObjectCompare.isInList(value.toUpperCase(), "0", "NO", "N", "FALSE")) { return Boolean.FALSE; } else { return Boolean.valueOf(value); } case STRING: return value; case DATE_UTIL: case DATE_SQL: return DateFormat.parse(value, Pattern.DATETIME); case TIMESTAMP: final long time = DateFormat.parse(value, Pattern.TIMESTAMP).getTime(); return new Timestamp(time); default: return JSON.parseObject(value, Class.forName(typeName)); } } catch (final ClassCastException | ClassNotFoundException | ParseException e) { throw new org.nanoframework.commons.exception.ClassCastException(e.getMessage(), e); } } }
ClassCast { public static final Object cast(final String value, final String typeName) { if (value == null) { return null; } try { switch (typeName) { case INTEGER_OBJ: case INT: return Integer.valueOf(value); case LONG_OBJ: case LONG: return Long.valueOf(value); case DOUBLE_OBJ: case DOUBLE: return Double.valueOf(value); case FLOAT_OBJ: case FLOAT: return Float.valueOf(value); case BOOLEAN_OBJ: case BOOLEAN: if (ObjectCompare.isInList(value.toUpperCase(), "1", "YES", "Y", "TRUE")) { return Boolean.TRUE; } else if (ObjectCompare.isInList(value.toUpperCase(), "0", "NO", "N", "FALSE")) { return Boolean.FALSE; } else { return Boolean.valueOf(value); } case STRING: return value; case DATE_UTIL: case DATE_SQL: return DateFormat.parse(value, Pattern.DATETIME); case TIMESTAMP: final long time = DateFormat.parse(value, Pattern.TIMESTAMP).getTime(); return new Timestamp(time); default: return JSON.parseObject(value, Class.forName(typeName)); } } catch (final ClassCastException | ClassNotFoundException | ParseException e) { throw new org.nanoframework.commons.exception.ClassCastException(e.getMessage(), e); } } private  ClassCast(); }
ClassCast { public static final Object cast(final String value, final String typeName) { if (value == null) { return null; } try { switch (typeName) { case INTEGER_OBJ: case INT: return Integer.valueOf(value); case LONG_OBJ: case LONG: return Long.valueOf(value); case DOUBLE_OBJ: case DOUBLE: return Double.valueOf(value); case FLOAT_OBJ: case FLOAT: return Float.valueOf(value); case BOOLEAN_OBJ: case BOOLEAN: if (ObjectCompare.isInList(value.toUpperCase(), "1", "YES", "Y", "TRUE")) { return Boolean.TRUE; } else if (ObjectCompare.isInList(value.toUpperCase(), "0", "NO", "N", "FALSE")) { return Boolean.FALSE; } else { return Boolean.valueOf(value); } case STRING: return value; case DATE_UTIL: case DATE_SQL: return DateFormat.parse(value, Pattern.DATETIME); case TIMESTAMP: final long time = DateFormat.parse(value, Pattern.TIMESTAMP).getTime(); return new Timestamp(time); default: return JSON.parseObject(value, Class.forName(typeName)); } } catch (final ClassCastException | ClassNotFoundException | ParseException e) { throw new org.nanoframework.commons.exception.ClassCastException(e.getMessage(), e); } } private  ClassCast(); static final Object cast(final String value, final String typeName); static final Object cast(final Object value, final String typeName); static Date parseDate(final String date); }
ClassCast { public static final Object cast(final String value, final String typeName) { if (value == null) { return null; } try { switch (typeName) { case INTEGER_OBJ: case INT: return Integer.valueOf(value); case LONG_OBJ: case LONG: return Long.valueOf(value); case DOUBLE_OBJ: case DOUBLE: return Double.valueOf(value); case FLOAT_OBJ: case FLOAT: return Float.valueOf(value); case BOOLEAN_OBJ: case BOOLEAN: if (ObjectCompare.isInList(value.toUpperCase(), "1", "YES", "Y", "TRUE")) { return Boolean.TRUE; } else if (ObjectCompare.isInList(value.toUpperCase(), "0", "NO", "N", "FALSE")) { return Boolean.FALSE; } else { return Boolean.valueOf(value); } case STRING: return value; case DATE_UTIL: case DATE_SQL: return DateFormat.parse(value, Pattern.DATETIME); case TIMESTAMP: final long time = DateFormat.parse(value, Pattern.TIMESTAMP).getTime(); return new Timestamp(time); default: return JSON.parseObject(value, Class.forName(typeName)); } } catch (final ClassCastException | ClassNotFoundException | ParseException e) { throw new org.nanoframework.commons.exception.ClassCastException(e.getMessage(), e); } } private  ClassCast(); static final Object cast(final String value, final String typeName); static final Object cast(final Object value, final String typeName); static Date parseDate(final String date);  }