avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ieme...@apache.org
Subject [avro] 01/02: Use RoundingMode for BigDecimal to avoid deprecation warning (Java > 9)
Date Wed, 26 Dec 2018 17:32:05 GMT
This is an automated email from the ASF dual-hosted git repository.

iemejia pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git

commit a9ec22cce3c5d0bbde162dca99a96adf4584b429
Author: Ismaël Mejía <iemejia@gmail.com>
AuthorDate: Thu Dec 20 14:21:16 2018 +0100

    Use RoundingMode for BigDecimal to avoid deprecation warning (Java > 9)
---
 .../apache/avro/specific/TestSpecificLogicalTypes.java    | 15 ++++++++-------
 .../java/org.apache.avro.codegentest/CustomDecimal.java   |  3 ++-
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
b/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
index 02bea73..ed64a77 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
@@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.*;
 import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatterBuilder;
 import java.time.temporal.ChronoField;
@@ -100,7 +101,7 @@ public class TestSpecificLogicalTypes {
         LocalDate.now(),
         LocalTime.now(),
         DateTime.now().withZone(DateTimeZone.UTC),
-        new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN)
+        new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN)
     );
 
     File data = write(TestRecordWithLogicalTypes.getClassSchema(), record);
@@ -121,7 +122,7 @@ public class TestSpecificLogicalTypes {
         java.time.LocalDate.now(),
         java.time.LocalTime.now(),
         java.time.Instant.now(),
-        new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN)
+        new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN)
     );
 
     File data = write(TestRecordWithJsr310LogicalTypes.getClassSchema(), record);
@@ -147,7 +148,7 @@ public class TestSpecificLogicalTypes {
             // for granularity less than one second second.
             new DateTime((System.currentTimeMillis() / 1000) * 1000,
                     ISOChronology.getInstance()).withZone(DateTimeZone.UTC),
-            new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN)
+            new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN)
     );
 
     File data = write(TestRecordWithLogicalTypes.getClassSchema(), withJoda);
@@ -182,7 +183,7 @@ public class TestSpecificLogicalTypes {
             java.time.LocalDate.now(),
             java.time.LocalTime.now(),
             java.time.Instant.now(),
-            new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN)
+            new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN)
     );
 
     File data = write(TestRecordWithJsr310LogicalTypes.getClassSchema(), withJsr310);
@@ -225,7 +226,7 @@ public class TestSpecificLogicalTypes {
         new TimestampConversion().toLong(
             DateTime.now().withZone(DateTimeZone.UTC), null, null),
         new Conversions.DecimalConversion().toBytes(
-            new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN), null,
+            new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN), null,
             LogicalTypes.decimal(9, 2))
     );
 
@@ -241,7 +242,7 @@ public class TestSpecificLogicalTypes {
     LocalDate date = LocalDate.now();
     LocalTime time = LocalTime.now();
     DateTime timestamp = DateTime.now().withZone(DateTimeZone.UTC);
-    BigDecimal decimal = new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN);
+    BigDecimal decimal = new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN);
 
     TestRecordWithoutLogicalTypes record = new TestRecordWithoutLogicalTypes(
         true,
@@ -282,7 +283,7 @@ public class TestSpecificLogicalTypes {
     LocalDate date = LocalDate.now();
     LocalTime time = LocalTime.now();
     DateTime timestamp = DateTime.now().withZone(DateTimeZone.UTC);
-    BigDecimal decimal = new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN);
+    BigDecimal decimal = new BigDecimal(123.45f).setScale(2, RoundingMode.HALF_DOWN);
 
     TestRecordWithLogicalTypes record = new TestRecordWithLogicalTypes(
         true,
diff --git a/lang/java/integration-test/test-custom-conversions/src/main/java/org.apache.avro.codegentest/CustomDecimal.java
b/lang/java/integration-test/test-custom-conversions/src/main/java/org.apache.avro.codegentest/CustomDecimal.java
index 1d4f40c..3febe7a 100644
--- a/lang/java/integration-test/test-custom-conversions/src/main/java/org.apache.avro.codegentest/CustomDecimal.java
+++ b/lang/java/integration-test/test-custom-conversions/src/main/java/org.apache.avro.codegentest/CustomDecimal.java
@@ -20,6 +20,7 @@ package org.apache.avro.codegentest;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.math.RoundingMode;
 
 /**
  * Wraps a BigDecimal just to demonstrate that it is possible to use custom implementation
classes with custom conversions.
@@ -35,7 +36,7 @@ public class CustomDecimal implements Comparable<CustomDecimal> {
     public byte[] toByteArray(int scale) {
         final BigDecimal correctlyScaledValue;
         if (scale != internalValue.scale()) {
-            correctlyScaledValue = internalValue.setScale(scale, BigDecimal.ROUND_HALF_UP);
+            correctlyScaledValue = internalValue.setScale(scale, RoundingMode.HALF_UP);
         } else {
             correctlyScaledValue = internalValue;
         }


Mime
View raw message