@Override public Decimal getDecimal(int ordinal, int precision, int scale) { if (isNullAt(ordinal)) return null; if (precision <= Decimal.MAX_LONG_DIGITS()) { return Decimal.apply(getLong(ordinal), precision, scale); } else { final byte[] bytes = getBinary(ordinal); final BigInteger bigInteger = new BigInteger(bytes); final BigDecimal javaDecimal = new BigDecimal(bigInteger, scale); return Decimal.apply(new scala.math.BigDecimal(javaDecimal), precision, scale); } }
private Object normalize(Object value) { if (value instanceof Long) { return new BigDecimal((Long) value); } else if (value instanceof Integer) { return new BigDecimal((Integer) value); } else if (value instanceof Short) { return new BigDecimal((Short) value); } else if (value instanceof Byte) { return new BigDecimal((Byte) value); } else if (value instanceof scala.math.BigDecimal) { // Convert it to a Java BigDecimal return ((scala.math.BigDecimal) value).bigDecimal(); } return value; }
@Test void quotaSizeShouldBeWellSerialized() { assertThat(DTO_JSON_SERIALIZE.quotaValueWrites().writes(QuotaSize.size(18))) .isEqualTo(new JsNumber(BigDecimal.valueOf(18))); }
@Test void sessionIdShouldBeWellSerialized() { assertThat(DTO_JSON_SERIALIZE.sessionIdWrites().writes(MailboxSession.SessionId.of(18))) .isEqualTo(new JsNumber(BigDecimal.valueOf(18))); }
@Override public Decimal getDecimal(int ordinal, int precision, int scale) { if (isNullAt(ordinal)) return null; if (precision <= Decimal.MAX_LONG_DIGITS()) { return Decimal.apply(getLong(ordinal), precision, scale); } else { final byte[] bytes = getBinary(ordinal); final BigInteger bigInteger = new BigInteger(bytes); final BigDecimal javaDecimal = new BigDecimal(bigInteger, scale); return Decimal.apply(new scala.math.BigDecimal(javaDecimal), precision, scale); } }
@Test void messageUidShouldBeWellSerialized() { assertThat(DTO_JSON_SERIALIZE.messageUidWrites().writes(MessageUid.of(18))) .isEqualTo(new JsNumber(BigDecimal.valueOf(18))); }
private static Object normalize(Object value) { if (value instanceof Long) { return new BigDecimal((Long) value); } else if (value instanceof Integer) { return new BigDecimal((Integer) value); } else if (value instanceof Short) { return new BigDecimal((Short) value); } else if (value instanceof Byte) { return new BigDecimal((Byte) value); } else if (value instanceof scala.math.BigDecimal) { // Convert it to a Java BigDecimal return ((scala.math.BigDecimal) value).bigDecimal(); } return value; }
@Override public Decimal getDecimal(int ordinal, int precision, int scale) { if (isNullAt(ordinal)) return null; if (precision <= Decimal.MAX_LONG_DIGITS()) { return Decimal.apply(getLong(ordinal), precision, scale); } else { final byte[] bytes = getBinary(ordinal); final BigInteger bigInteger = new BigInteger(bytes); final BigDecimal javaDecimal = new BigDecimal(bigInteger, scale); return Decimal.apply(new scala.math.BigDecimal(javaDecimal), precision, scale); } }
@Test void quotaCountShouldBeWellSerialized() { assertThat(DTO_JSON_SERIALIZE.quotaValueWrites().writes(QuotaCount.count(18))) .isEqualTo(new JsNumber(BigDecimal.valueOf(18))); }
private static Object normalize(Object value) { if (value instanceof Long) { return new BigDecimal((Long) value); } else if (value instanceof Integer) { return new BigDecimal((Integer) value); } else if (value instanceof Short) { return new BigDecimal((Short) value); } else if (value instanceof Byte) { return new BigDecimal((Byte) value); } else if (value instanceof scala.math.BigDecimal) { // Convert it to a Java BigDecimal return ((scala.math.BigDecimal) value).bigDecimal(); } return value; }
@Override public void convert(UnsafeRowWriter writer, int column, ColumnVector vector, int row) { if (vector.isRepeating) { row = 0; } if (!vector.noNulls && vector.isNull[row]) { writer.setNullAt(column); } else { BigDecimal v = ((DecimalColumnVector) vector).vector[row] .getHiveDecimal().bigDecimalValue(); writer.write(column, new Decimal().set(new scala.math.BigDecimal(v), precision, scale), precision, scale); } }
@Test void messageUidShouldBeWellDeSerialized() { assertThat(DTO_JSON_SERIALIZE.messageUidReads().reads(new JsNumber(BigDecimal.valueOf(18))).get()) .isEqualTo(MessageUid.of(18)); }
private Object normalize(Object value) { if (value instanceof Long) { return new BigDecimal((Long) value); } else if (value instanceof Integer) { return new BigDecimal((Integer) value); } else if (value instanceof Short) { return new BigDecimal((Short) value); } else if (value instanceof Byte) { return new BigDecimal((Byte) value); } else if (value instanceof scala.math.BigDecimal) { // Convert it to a Java BigDecimal return ((scala.math.BigDecimal) value).bigDecimal(); } return value; }
@Override public void convert(UnsafeArrayWriter writer, int element, ColumnVector vector, int row) { if (vector.isRepeating) { row = 0; } if (!vector.noNulls && vector.isNull[row]) { writer.setNull(element); } else { BigDecimal v = ((DecimalColumnVector) vector).vector[row] .getHiveDecimal().bigDecimalValue(); writer.write(element, new Decimal().set(new scala.math.BigDecimal(v), precision, scale), precision, scale); } } }
@Test void quotaCountShouldBeWellDeSerialized() { assertThat(DTO_JSON_SERIALIZE.quotaCountReads().reads(new JsNumber(BigDecimal.valueOf(18))).get()) .isEqualTo(QuotaCount.count(18)); }
@Test void quotaSizeShouldBeWellDeSerialized() { assertThat(DTO_JSON_SERIALIZE.quotaSizeReads().reads(new JsNumber(BigDecimal.valueOf(18))).get()) .isEqualTo(QuotaSize.size(18)); }
@Test void sessionIdShouldBeWellDeSerialized() { assertThat(DTO_JSON_SERIALIZE.sessionIdReads().reads(new JsNumber(BigDecimal.valueOf(18))).get()) .isEqualTo(MailboxSession.SessionId.of(18)); }
@Test void mailboxIdDeserializationShouldReturnErrorWhenNumber() { assertThat(DTO_JSON_SERIALIZE.mailboxIdReads().reads(new JsNumber(BigDecimal.valueOf(18)))) .isInstanceOf(JsError.class); }
@Test void emptyQuotaRootShouldReturnErrorWhenNotString() { assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsNumber(BigDecimal.valueOf(18)))) .isInstanceOf(JsError.class); } }
@Test void messageIdDeserializationShouldReturnErrorWhenNumber() { assertThat(DTO_JSON_SERIALIZE.messageIdReads().reads(new JsNumber(BigDecimal.valueOf(18)))) .isInstanceOf(JsError.class); }