@Test public void testConvert__illegalArgument() { Object[] illegals = {new Date(), new int[0], "abc"}; for (Object obj : illegals) { try { type.convert(obj); fail(); } catch (RuntimeException e) { assertTrue(e instanceof IllegalArgumentException || e instanceof NumberFormatException); } } }
@Override public NumberHolder convert(Object obj) { if (obj instanceof Number) { Number n = (Number) obj; BigDecimal result; if (n instanceof Double || n instanceof Float) { result = new BigDecimal(n.doubleValue()); } else if (n instanceof BigDecimal) { result = (BigDecimal) n; } else if (n instanceof BigInteger) { result = new BigDecimal((BigInteger) n); } else { result = new BigDecimal(n.longValue()); } return new NumberHolder(result); } if (obj == null) { return new NumberHolder(null); } if (obj instanceof String) { return decode((String) obj); } throw new IllegalArgumentException("conversion not supported for: " + obj.getClass()); }
NumberType implements Type<NumberHolder> { @Override public NumberHolder convert(Object obj) { if (obj instanceof Number) { Number n = (Number) obj; BigDecimal result; if (n instanceof Double || n instanceof Float) { result = new BigDecimal(n.doubleValue()); } else if (n instanceof BigDecimal) { result = (BigDecimal) n; } else if (n instanceof BigInteger) { result = new BigDecimal((BigInteger) n); } else { result = new BigDecimal(n.longValue()); } return new NumberHolder(result); } if (obj == null) { return new NumberHolder(null); } if (obj instanceof String) { return decode((String) obj); } throw new IllegalArgumentException("conversion not supported for: " + obj.getClass()); } }
NumberType implements Type<NumberHolder> { @Override public NumberHolder convert(Object obj) { if (obj instanceof Number) { Number n = (Number) obj; BigDecimal result; if (n instanceof Double || n instanceof Float) { result = new BigDecimal(n.doubleValue()); } else if (n instanceof BigDecimal) { result = (BigDecimal) n; } else if (n instanceof BigInteger) { result = new BigDecimal((BigInteger) n); } else { result = new BigDecimal(n.longValue()); } return new NumberHolder(result); } if (obj == null) { return new NumberHolder(null); } if (obj instanceof String) { return decode((String) obj); } throw new IllegalArgumentException("conversion not supported for: " + obj.getClass()); }  }
NumberType implements Type<NumberHolder> { @Override public NumberHolder convert(Object obj) { if (obj instanceof Number) { Number n = (Number) obj; BigDecimal result; if (n instanceof Double || n instanceof Float) { result = new BigDecimal(n.doubleValue()); } else if (n instanceof BigDecimal) { result = (BigDecimal) n; } else if (n instanceof BigInteger) { result = new BigDecimal((BigInteger) n); } else { result = new BigDecimal(n.longValue()); } return new NumberHolder(result); } if (obj == null) { return new NumberHolder(null); } if (obj instanceof String) { return decode((String) obj); } throw new IllegalArgumentException("conversion not supported for: " + obj.getClass()); }  @Override String encode(NumberHolder value); @Override NumberHolder decode(String text); @Override NumberHolder convert(Object obj); @Override NumberHolder[] newArray(int size); }
NumberType implements Type<NumberHolder> { @Override public NumberHolder convert(Object obj) { if (obj instanceof Number) { Number n = (Number) obj; BigDecimal result; if (n instanceof Double || n instanceof Float) { result = new BigDecimal(n.doubleValue()); } else if (n instanceof BigDecimal) { result = (BigDecimal) n; } else if (n instanceof BigInteger) { result = new BigDecimal((BigInteger) n); } else { result = new BigDecimal(n.longValue()); } return new NumberHolder(result); } if (obj == null) { return new NumberHolder(null); } if (obj instanceof String) { return decode((String) obj); } throw new IllegalArgumentException("conversion not supported for: " + obj.getClass()); }  @Override String encode(NumberHolder value); @Override NumberHolder decode(String text); @Override NumberHolder convert(Object obj); @Override NumberHolder[] newArray(int size); static final String TYPE_NAME; }