/** * Gets common converted amount from low to high. * * @param sourceType the source type * @param targetType the target type * @param originalAmount the original amount * @param calculatedAmount the calculated amount * @return the common converted amount from low to high */ public static BigDecimal getCommonConvertedAmountFromLowToHigh( AreaEnum sourceType, AreaEnum targetType, BigDecimal originalAmount, BigDecimal calculatedAmount) { if (sourceType == targetType) { return calculatedAmount; } BigDecimal result = BigDecimal.ONE; boolean startFlag = false; AreaEnum[] vv = AreaEnum.values(); int len = vv.length - 1; for (int i = len; i >= 0; --i) { AreaEnum t = vv[i]; if (sourceType == t && startFlag == false) { startFlag = true; continue; } if (startFlag) { BigDecimal srcAmountVal = t.getLowerToUpperVal(); result = result.multiply(srcAmountVal, Constant.MC); if (t == targetType) { break; } } } return calculatedAmount.multiply(result); }
/** * Gets common converted amount from high to low. * * @param sourceType the source type * @param targetType the target type * @param amount the amount * @return common converted amount from high to low */ public static BigDecimal getCommonConvertedAmountFromHighToLow( AreaEnum sourceType, AreaEnum targetType, BigDecimal amount) { if (sourceType == targetType) { return amount; } BigDecimal result = amount; boolean startFlag = false; for (AreaEnum t : AreaEnum.values()) { if (sourceType == t && startFlag == false) { startFlag = true; continue; } if (startFlag) { BigDecimal srcAmountVal = t.getUpperToLowerVal(); result = result.multiply(srcAmountVal); if (t == targetType) { break; } } } return result; }
private static boolean isSourceToTargetOrderDescending( AreaEnum sourceType, AreaEnum targetType, BigDecimal amount) { boolean flag = false; for (AreaEnum t : AreaEnum.values()) { if (sourceType == t) { flag = true; break; } if (targetType == t) { flag = false; break; } } return flag; }