可以进行以下优化:

  1. scoreItemValue.getExamineWeight()scoreItemValue.getAssessScore()的结果缓存起来,避免重复调用。
  2. 使用静态导入NumberUtils.createBigDecimal方法,避免每次都需要写完整的类名。
  3. BigDecimal.valueOf(size)的结果缓存起来,避免重复计算。
  4. 可能的话,将RoundingMode.HALF_UP的常量提取到一个变量中,避免重复创建。

优化后的代码如下:

BigDecimal examineWeight = scoreItemValue.getExamineWeight();
BigDecimal assessScore = NumberUtils.createBigDecimal(String.valueOf(scoreItemValue.getAssessScore()));
BigDecimal sizeBigDecimal = BigDecimal.valueOf(size);
final BigDecimal levelSubtotalAssessScore = examineWeight.multiply(assessScore).divide(sizeBigDecimal, 4, RoundingMode.HALF_UP);
``
代码优化 final BigDecimal levelSubtotalAssessScore = scoreItemValuegetExamineWeight multiplyNumberUtilscreateBigDecimalStringvalueOfscoreItemValuegetAssessScore divideBigDecim

原文地址: http://www.cveoy.top/t/topic/iU9u 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录