@Test public void shouldCovertToShort() { Object object = Convert.toShort(1F); the(object).shouldBeA(Short.class); a(object).shouldBeEqual(1); object = Convert.toShort("1"); the(object).shouldBeA(Short.class); a(object).shouldBeEqual(1); object = Convert.toShort(1L); the(object).shouldBeA(Short.class); a(object).shouldBeEqual(1); object = Convert.toShort(new BigDecimal(1)); the(object).shouldBeA(Short.class); a(object).shouldBeEqual(1); }
public static Short toShort(Object value) { if (value == null) { return null; } else if (value instanceof Short) { return (Short) value; } else if (value instanceof Number) { return ((Number) value).shortValue(); } else { try { return Short.valueOf(value.toString().trim()); } catch (NumberFormatException e) { throw new ConversionException("failed to convert: '" + value + "' to Short", e); } } }
Convert { public static Short toShort(Object value) { if (value == null) { return null; } else if (value instanceof Short) { return (Short) value; } else if (value instanceof Number) { return ((Number) value).shortValue(); } else { try { return Short.valueOf(value.toString().trim()); } catch (NumberFormatException e) { throw new ConversionException("failed to convert: '" + value + "' to Short", e); } } } }
Convert { public static Short toShort(Object value) { if (value == null) { return null; } else if (value instanceof Short) { return (Short) value; } else if (value instanceof Number) { return ((Number) value).shortValue(); } else { try { return Short.valueOf(value.toString().trim()); } catch (NumberFormatException e) { throw new ConversionException("failed to convert: '" + value + "' to Short", e); } } } private  Convert(); }
Convert { public static Short toShort(Object value) { if (value == null) { return null; } else if (value instanceof Short) { return (Short) value; } else if (value instanceof Number) { return ((Number) value).shortValue(); } else { try { return Short.valueOf(value.toString().trim()); } catch (NumberFormatException e) { throw new ConversionException("failed to convert: '" + value + "' to Short", e); } } } private  Convert(); static String toString(Object value); static Boolean toBoolean(Object value); static java.sql.Date toSqlDate(Object value); static java.sql.Date truncateToSqlDate(Object value); static java.sql.Date truncateToSqlDate(long time); static String toIsoString(java.util.Date date); static Double toDouble(Object value); static java.sql.Time toTime(Object value); static java.sql.Timestamp toTimestamp(Object value); static Float toFloat(Object value); static Long toLong(Object value); static Integer toInteger(Object value); static BigDecimal toBigDecimal(Object value); static byte[] toBytes(Object value); static byte[] toBytes(Blob blob); static Short toShort(Object value); }
Convert { public static Short toShort(Object value) { if (value == null) { return null; } else if (value instanceof Short) { return (Short) value; } else if (value instanceof Number) { return ((Number) value).shortValue(); } else { try { return Short.valueOf(value.toString().trim()); } catch (NumberFormatException e) { throw new ConversionException("failed to convert: '" + value + "' to Short", e); } } } private  Convert(); static String toString(Object value); static Boolean toBoolean(Object value); static java.sql.Date toSqlDate(Object value); static java.sql.Date truncateToSqlDate(Object value); static java.sql.Date truncateToSqlDate(long time); static String toIsoString(java.util.Date date); static Double toDouble(Object value); static java.sql.Time toTime(Object value); static java.sql.Timestamp toTimestamp(Object value); static Float toFloat(Object value); static Long toLong(Object value); static Integer toInteger(Object value); static BigDecimal toBigDecimal(Object value); static byte[] toBytes(Object value); static byte[] toBytes(Blob blob); static Short toShort(Object value);  }