@Test public void testDoubleConverter() { double data = 12.0; float floatData = (float) data; int intData = (int) data; long longData = (long) data; assertTrue("Failure returning same object", this.schema.convert(data).equals(data)); assertTrue("Failure parsing double from long", this.schema.convert(longData).equals(data)); assertTrue("Failure parsing double from integer", this.schema.convert(intData).equals(data)); assertTrue("Failure parsing double from float", this.schema.convert(floatData).equals(data)); assertTrue("Failure parsing double data", this.schema.convert("" + data).equals(data)); }
@Override public Object convert(Object value) { if (value instanceof Integer) { return ((Integer) value).doubleValue(); } else if (value instanceof Long) { return ((Long) value).doubleValue(); } else if (value instanceof Float) { return ((Float) value).doubleValue(); } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { try { return Double.parseDouble((String) value); } catch (NumberFormatException nfe) { throw (IllegalArgumentException) new IllegalArgumentException(value + " cannot be parsed to a double").initCause(nfe); } } throw new IllegalArgumentException(value + " is not a double"); }
DoubleSchema extends PrimitiveNumericSchema<Double> { @Override public Object convert(Object value) { if (value instanceof Integer) { return ((Integer) value).doubleValue(); } else if (value instanceof Long) { return ((Long) value).doubleValue(); } else if (value instanceof Float) { return ((Float) value).doubleValue(); } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { try { return Double.parseDouble((String) value); } catch (NumberFormatException nfe) { throw (IllegalArgumentException) new IllegalArgumentException(value + " cannot be parsed to a double").initCause(nfe); } } throw new IllegalArgumentException(value + " is not a double"); } }
DoubleSchema extends PrimitiveNumericSchema<Double> { @Override public Object convert(Object value) { if (value instanceof Integer) { return ((Integer) value).doubleValue(); } else if (value instanceof Long) { return ((Long) value).doubleValue(); } else if (value instanceof Float) { return ((Float) value).doubleValue(); } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { try { return Double.parseDouble((String) value); } catch (NumberFormatException nfe) { throw (IllegalArgumentException) new IllegalArgumentException(value + " cannot be parsed to a double").initCause(nfe); } } throw new IllegalArgumentException(value + " is not a double"); } DoubleSchema(); }
DoubleSchema extends PrimitiveNumericSchema<Double> { @Override public Object convert(Object value) { if (value instanceof Integer) { return ((Integer) value).doubleValue(); } else if (value instanceof Long) { return ((Long) value).doubleValue(); } else if (value instanceof Float) { return ((Float) value).doubleValue(); } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { try { return Double.parseDouble((String) value); } catch (NumberFormatException nfe) { throw (IllegalArgumentException) new IllegalArgumentException(value + " cannot be parsed to a double").initCause(nfe); } } throw new IllegalArgumentException(value + " is not a double"); } DoubleSchema(); @Override Object convert(Object value); }
DoubleSchema extends PrimitiveNumericSchema<Double> { @Override public Object convert(Object value) { if (value instanceof Integer) { return ((Integer) value).doubleValue(); } else if (value instanceof Long) { return ((Long) value).doubleValue(); } else if (value instanceof Float) { return ((Float) value).doubleValue(); } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { try { return Double.parseDouble((String) value); } catch (NumberFormatException nfe) { throw (IllegalArgumentException) new IllegalArgumentException(value + " cannot be parsed to a double").initCause(nfe); } } throw new IllegalArgumentException(value + " is not a double"); } DoubleSchema(); @Override Object convert(Object value);  }