@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof Value)) { return false; } Value v = (Value) o; if (!v.isFloatValue()) { return false; } return value == v.asFloatValue().toFloat(); }
@Override public boolean isNumberValue() { return getValueType().isNumberType(); }
@Test public void testOrdinaryFloat() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("12345.12"); assertTrue(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345.12, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("12345.12", msgpackValue.asFloatValue().toString()); }
@Test public void testOrdinaryInteger() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("12345"); assertTrue(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345, msgpackValue.asIntegerValue().asInt()); }
@Override public void set(long v) { pageBuilder.setJson(column, ValueFactory.newInteger(v)); }
@Override public void set(Value v) { pageBuilder.setString(column, v.toJson()); } }
@Override public boolean isIntegerValue() { return getValueType().isIntegerType(); }
@Override public boolean isStringValue() { return getValueType().isStringType(); }
@Override public boolean isFloatValue() { return getValueType().isFloatType(); }
@Override public boolean isRawValue() { return getValueType().isRawType(); }
@Override public boolean isExtensionValue() { return getValueType().isExtensionType(); }
@Override public boolean isNilValue() { return getValueType().isNilType(); }
@Override public boolean isBooleanValue() { return getValueType().isBooleanType(); }
@Override public boolean isBinaryValue() { return getValueType().isBinaryType(); }
@Override public boolean isMapValue() { return getValueType().isMapType(); }
@Override public boolean isArrayValue() { return getValueType().isArrayType(); }
@Test public void testExponentialFloat() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("1.234512E4"); assertTrue(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345.12, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("12345.12", msgpackValue.asFloatValue().toString()); } }
@Test public void testExponentialInteger1() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("12345e3"); assertTrue(msgpackValue.getValueType().isNumberType()); // TODO: Consider this needs to be an integer? // See: https://github.com/embulk/embulk/issues/775 assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345000.0, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("1.2345E7", msgpackValue.asFloatValue().toString()); }
@Test public void testExponentialInteger2() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("123e2"); assertTrue(msgpackValue.getValueType().isNumberType()); // TODO: Consider this needs to be an integer? // See: https://github.com/embulk/embulk/issues/775 assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12300.0, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("12300.0", msgpackValue.asFloatValue().toString()); }