@Test(expected = Error.class) public void testCastBadString() { bigDecimalType.cast("string"); }
@Override public Object cast(Object obj) { BigDecimal value = null; if (obj != null) { if (obj instanceof BigDecimal) { value = (BigDecimal) obj; } else if (obj instanceof Number) { if (obj instanceof Double || obj instanceof Float) { value = new BigDecimal(((Number) obj).doubleValue()); } else { value = new BigDecimal(((Number) obj).longValue()); } } else if (obj instanceof Boolean) { value = new BigDecimal(((Boolean) obj) ? 1 : 0); } else if (obj instanceof String) { try { value = new BigDecimal((String) obj); } catch (NumberFormatException e) { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } return value; }
BigDecimalType implements Type, Serializable { @Override public Object cast(Object obj) { BigDecimal value = null; if (obj != null) { if (obj instanceof BigDecimal) { value = (BigDecimal) obj; } else if (obj instanceof Number) { if (obj instanceof Double || obj instanceof Float) { value = new BigDecimal(((Number) obj).doubleValue()); } else { value = new BigDecimal(((Number) obj).longValue()); } } else if (obj instanceof Boolean) { value = new BigDecimal(((Boolean) obj) ? 1 : 0); } else if (obj instanceof String) { try { value = new BigDecimal((String) obj); } catch (NumberFormatException e) { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } return value; } }
BigDecimalType implements Type, Serializable { @Override public Object cast(Object obj) { BigDecimal value = null; if (obj != null) { if (obj instanceof BigDecimal) { value = (BigDecimal) obj; } else if (obj instanceof Number) { if (obj instanceof Double || obj instanceof Float) { value = new BigDecimal(((Number) obj).doubleValue()); } else { value = new BigDecimal(((Number) obj).longValue()); } } else if (obj instanceof Boolean) { value = new BigDecimal(((Boolean) obj) ? 1 : 0); } else if (obj instanceof String) { try { value = new BigDecimal((String) obj); } catch (NumberFormatException e) { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } return value; } private  BigDecimalType(); }
BigDecimalType implements Type, Serializable { @Override public Object cast(Object obj) { BigDecimal value = null; if (obj != null) { if (obj instanceof BigDecimal) { value = (BigDecimal) obj; } else if (obj instanceof Number) { if (obj instanceof Double || obj instanceof Float) { value = new BigDecimal(((Number) obj).doubleValue()); } else { value = new BigDecimal(((Number) obj).longValue()); } } else if (obj instanceof Boolean) { value = new BigDecimal(((Boolean) obj) ? 1 : 0); } else if (obj instanceof String) { try { value = new BigDecimal((String) obj); } catch (NumberFormatException e) { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } return value; } private  BigDecimalType(); @Override String getName(); @Override boolean supportsEq(); @Override boolean supportsOrdering(); @Override JsonNode toJson(JsonNodeFactory factory, Object obj); @Override Object fromJson(JsonNode node); @Override Object cast(Object obj); @SuppressWarnings({"rawtypes", "unchecked"}) @Override int compare(Object v1, Object v2); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
BigDecimalType implements Type, Serializable { @Override public Object cast(Object obj) { BigDecimal value = null; if (obj != null) { if (obj instanceof BigDecimal) { value = (BigDecimal) obj; } else if (obj instanceof Number) { if (obj instanceof Double || obj instanceof Float) { value = new BigDecimal(((Number) obj).doubleValue()); } else { value = new BigDecimal(((Number) obj).longValue()); } } else if (obj instanceof Boolean) { value = new BigDecimal(((Boolean) obj) ? 1 : 0); } else if (obj instanceof String) { try { value = new BigDecimal((String) obj); } catch (NumberFormatException e) { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } return value; } private  BigDecimalType(); @Override String getName(); @Override boolean supportsEq(); @Override boolean supportsOrdering(); @Override JsonNode toJson(JsonNodeFactory factory, Object obj); @Override Object fromJson(JsonNode node); @Override Object cast(Object obj); @SuppressWarnings({"rawtypes", "unchecked"}) @Override int compare(Object v1, Object v2); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static final Type TYPE; static final String NAME; }