Skip to content

Commit

Permalink
[update][common] move OverFlowUtil from element package to util package
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzhao committed Nov 3, 2024
1 parent 4ac6e37 commit 1474331
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 .");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 .");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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() {}

Expand All @@ -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.");
}
}

Expand All @@ -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)
Expand All @@ -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.");
}
}
}

0 comments on commit 1474331

Please sign in to comment.