From 2757f6a51b41ee52f5bcd5c594cfbfbe01a9a455 Mon Sep 17 00:00:00 2001 From: forge-bot Date: Sat, 18 Jul 2026 11:09:16 +0000 Subject: [PATCH] =?UTF-8?q?[=EA=B3=B5=ED=86=B5]=20util=20=E2=86=92=20frame?= =?UTF-8?q?work=20=EC=9C=A0=ED=8B=B8=20(ACM-CM-002)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/util/AmountUtil.java | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 boot/common-framework/src/main/java/com/klaro/acquirecore/framework/util/AmountUtil.java diff --git a/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/util/AmountUtil.java b/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/util/AmountUtil.java new file mode 100644 index 0000000..84a26a7 --- /dev/null +++ b/boot/common-framework/src/main/java/com/klaro/acquirecore/framework/util/AmountUtil.java @@ -0,0 +1,105 @@ +package com.klaro.acquirecore.framework.util; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +/** + * Static utility class for monetary amount operations migrated from legacy C code. + * Provides parsing, formatting, and arithmetic for BigDecimal amounts. + */ +public final class AmountUtil { + + public static final String DEFAULT_CURRENCY = "KRW"; + private static final int DEFAULT_SCALE = 2; + private static final RoundingMode DEFAULT_ROUNDING = RoundingMode.HALF_UP; + + private AmountUtil() { + // Utility class - prevent instantiation + } + + public static BigDecimal parse(String str) { + if (str == null || str.isBlank()) { + return null; + } + try { + String cleaned = str.trim().replaceAll(",", ""); + cleaned = cleaned.replaceAll("[A-Z]{3}\\s*", ""); + return new BigDecimal(cleaned).setScale(DEFAULT_SCALE, DEFAULT_ROUNDING); + } catch (NumberFormatException e) { + return null; + } + } + + public static String format(BigDecimal amount, String currency) { + if (amount == null) { + return ""; + } + String curr = (currency != null && !currency.isBlank()) ? currency : DEFAULT_CURRENCY; + return String.format("%s %s", curr, amount.setScale(DEFAULT_SCALE, DEFAULT_ROUNDING).toPlainString()); + } + + public static String format(BigDecimal amount) { + return format(amount, DEFAULT_CURRENCY); + } + + public static BigDecimal add(BigDecimal a, BigDecimal b) { + if (a == null || b == null) { + return null; + } + return a.add(b).setScale(DEFAULT_SCALE, DEFAULT_ROUNDING); + } + + public static BigDecimal subtract(BigDecimal a, BigDecimal b) { + if (a == null || b == null) { + return null; + } + return a.subtract(b).setScale(DEFAULT_SCALE, DEFAULT_ROUNDING); + } + + public static BigDecimal multiply(BigDecimal amount, int factor) { + if (amount == null) { + return null; + } + return amount.multiply(BigDecimal.valueOf(factor)).setScale(DEFAULT_SCALE, DEFAULT_ROUNDING); + } + + public static BigDecimal multiply(BigDecimal amount, BigDecimal factor) { + if (amount == null || factor == null) { + return null; + } + return amount.multiply(factor).setScale(DEFAULT_SCALE, DEFAULT_ROUNDING); + } + + public static BigDecimal divide(BigDecimal amount, BigDecimal divisor) { + if (amount == null || divisor == null || divisor.compareTo(BigDecimal.ZERO) == 0) { + return null; + } + return amount.divide(divisor, DEFAULT_SCALE, DEFAULT_ROUNDING); + } + + public static boolean isPositive(BigDecimal amount) { + return amount != null && amount.compareTo(BigDecimal.ZERO) > 0; + } + + public static boolean isNegative(BigDecimal amount) { + return amount != null && amount.compareTo(BigDecimal.ZERO) < 0; + } + + public static boolean isZero(BigDecimal amount) { + return amount != null && amount.compareTo(BigDecimal.ZERO) == 0; + } + + public static BigDecimal abs(BigDecimal amount) { + if (amount == null) { + return null; + } + return amount.abs().setScale(DEFAULT_SCALE, DEFAULT_ROUNDING); + } + + public static BigDecimal negate(BigDecimal amount) { + if (amount == null) { + return null; + } + return amount.negate().setScale(DEFAULT_SCALE, DEFAULT_ROUNDING); + } +}