From 1474331150c2edbb1a6d55b38ad9d958506cd8d3 Mon Sep 17 00:00:00 2001
From: wgzhao <wgzhao@gmail.com>
Date: Sun, 3 Nov 2024 09:53:22 +0800
Subject: [PATCH] [update][common] move OverFlowUtil from element package to
 util package

---
 .../addax/common/element/BoolColumn.java      |  2 +-
 .../addax/common/element/BytesColumn.java     |  2 +-
 .../addax/common/element/DoubleColumn.java    |  1 +
 .../addax/common/element/LongColumn.java      |  1 +
 .../addax/common/element/StringColumn.java    |  1 +
 .../{element => util}/OverFlowUtil.java       | 25 +++++++------------
 6 files changed, 14 insertions(+), 18 deletions(-)
 rename common/src/main/java/com/wgzhao/addax/common/{element => util}/OverFlowUtil.java (75%)

diff --git a/common/src/main/java/com/wgzhao/addax/common/element/BoolColumn.java b/common/src/main/java/com/wgzhao/addax/common/element/BoolColumn.java
index 10860abca..c1633c223 100644
--- a/common/src/main/java/com/wgzhao/addax/common/element/BoolColumn.java
+++ b/common/src/main/java/com/wgzhao/addax/common/element/BoolColumn.java
@@ -151,6 +151,6 @@ private void validate(final String data)
 
         throw AddaxException.asAddaxException(
                 ErrorCode.CONVERT_NOT_SUPPORT,
-                String.format("String [%s] cannot be converted to Bool .", data));
+                "String [" + data + "] cannot be converted to Bool .");
     }
 }
diff --git a/common/src/main/java/com/wgzhao/addax/common/element/BytesColumn.java b/common/src/main/java/com/wgzhao/addax/common/element/BytesColumn.java
index 54dd2ca88..75c75bfb6 100644
--- a/common/src/main/java/com/wgzhao/addax/common/element/BytesColumn.java
+++ b/common/src/main/java/com/wgzhao/addax/common/element/BytesColumn.java
@@ -69,7 +69,7 @@ public String asString()
         catch (Exception e) {
             throw AddaxException.asAddaxException(
                     ErrorCode.CONVERT_NOT_SUPPORT,
-                    String.format("Bytes[%s] cannot be converted to String .", this));
+                    "Bytes[" + this + "] cannot be converted to String .");
         }
     }
 
diff --git a/common/src/main/java/com/wgzhao/addax/common/element/DoubleColumn.java b/common/src/main/java/com/wgzhao/addax/common/element/DoubleColumn.java
index ed6a31406..22a291fda 100644
--- a/common/src/main/java/com/wgzhao/addax/common/element/DoubleColumn.java
+++ b/common/src/main/java/com/wgzhao/addax/common/element/DoubleColumn.java
@@ -21,6 +21,7 @@
 
 import com.wgzhao.addax.common.spi.ErrorCode;
 import com.wgzhao.addax.common.exception.AddaxException;
+import com.wgzhao.addax.common.util.OverFlowUtil;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
diff --git a/common/src/main/java/com/wgzhao/addax/common/element/LongColumn.java b/common/src/main/java/com/wgzhao/addax/common/element/LongColumn.java
index 12a1faefa..77a31ed80 100644
--- a/common/src/main/java/com/wgzhao/addax/common/element/LongColumn.java
+++ b/common/src/main/java/com/wgzhao/addax/common/element/LongColumn.java
@@ -21,6 +21,7 @@
 
 import com.wgzhao.addax.common.exception.AddaxException;
 import com.wgzhao.addax.common.spi.ErrorCode;
+import com.wgzhao.addax.common.util.OverFlowUtil;
 import org.apache.commons.lang3.math.NumberUtils;
 
 import java.math.BigDecimal;
diff --git a/common/src/main/java/com/wgzhao/addax/common/element/StringColumn.java b/common/src/main/java/com/wgzhao/addax/common/element/StringColumn.java
index 62813bd41..cebc6d69f 100644
--- a/common/src/main/java/com/wgzhao/addax/common/element/StringColumn.java
+++ b/common/src/main/java/com/wgzhao/addax/common/element/StringColumn.java
@@ -21,6 +21,7 @@
 
 import com.wgzhao.addax.common.spi.ErrorCode;
 import com.wgzhao.addax.common.exception.AddaxException;
+import com.wgzhao.addax.common.util.OverFlowUtil;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
diff --git a/common/src/main/java/com/wgzhao/addax/common/element/OverFlowUtil.java b/common/src/main/java/com/wgzhao/addax/common/util/OverFlowUtil.java
similarity index 75%
rename from common/src/main/java/com/wgzhao/addax/common/element/OverFlowUtil.java
rename to common/src/main/java/com/wgzhao/addax/common/util/OverFlowUtil.java
index 94b14a4b1..076d86f1c 100644
--- a/common/src/main/java/com/wgzhao/addax/common/element/OverFlowUtil.java
+++ b/common/src/main/java/com/wgzhao/addax/common/util/OverFlowUtil.java
@@ -6,9 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
  *   http://www.apache.org/licenses/LICENSE-2.0
- *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -17,7 +15,7 @@
  * under the License.
  */
 
-package com.wgzhao.addax.common.element;
+package com.wgzhao.addax.common.util;
 
 import com.wgzhao.addax.common.spi.ErrorCode;
 import com.wgzhao.addax.common.exception.AddaxException;
@@ -27,14 +25,10 @@
 
 public final class OverFlowUtil
 {
-    public static final BigInteger MAX_LONG = BigInteger
-            .valueOf(Long.MAX_VALUE);
-    public static final BigInteger MIN_LONG = BigInteger
-            .valueOf(Long.MIN_VALUE);
-    public static final BigDecimal MIN_DOUBLE_POSITIVE = new BigDecimal(
-            String.valueOf(Double.MIN_VALUE));
-    public static final BigDecimal MAX_DOUBLE_POSITIVE = new BigDecimal(
-            String.valueOf(Double.MAX_VALUE));
+    public static final BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE);
+    public static final BigInteger MIN_LONG = BigInteger.valueOf(Long.MIN_VALUE);
+    public static final BigDecimal MIN_DOUBLE_POSITIVE = new BigDecimal(String.valueOf(Double.MIN_VALUE));
+    public static final BigDecimal MAX_DOUBLE_POSITIVE = new BigDecimal(String.valueOf(Double.MAX_VALUE));
 
     private OverFlowUtil() {}
 
@@ -51,7 +45,7 @@ public static void validateLongNotOverFlow(final BigInteger integer)
         if (isOverFlow) {
             throw AddaxException.asAddaxException(
                     ErrorCode.CONVERT_OVER_FLOW,
-                    String.format("An overflow occurred when converting [%s] to Long type.", integer));
+                    "An overflow occurred when converting " + integer + " to Long type.");
         }
     }
 
@@ -67,8 +61,8 @@ public static boolean isDoubleOverFlow(final BigDecimal decimal)
             newDecimal = decimal.negate();
         }
 
-        return (newDecimal.compareTo(MIN_DOUBLE_POSITIVE) < 0 || newDecimal
-                .compareTo(MAX_DOUBLE_POSITIVE) > 0);
+        return (newDecimal.compareTo(MIN_DOUBLE_POSITIVE) < 0
+                || newDecimal.compareTo(MAX_DOUBLE_POSITIVE) > 0);
     }
 
     public static void validateDoubleNotOverFlow(final BigDecimal decimal)
@@ -77,8 +71,7 @@ public static void validateDoubleNotOverFlow(final BigDecimal decimal)
         if (isOverFlow) {
             throw AddaxException.asAddaxException(
                     ErrorCode.CONVERT_OVER_FLOW,
-                    String.format("An overflow occurred when converting [%s] to Double type.",
-                            decimal.toPlainString()));
+                    "An overflow occurred when converting " + decimal.toPlainString() + " to Double type.");
         }
     }
 }