我正在对数据集进行一些数学运算。根据项目的需要,可以随时更改数学公式/逻辑。所以我想把这些形式从Java代码中排除出来,可能在配置文件中。以下是示例配置文件-
formula.properties
文件-
formula_a=(a+b)/(7*c+b^2)
formula_b=(a^(1/2)-formula_a*13)
formula_c=spilt_time(formula_b,a,b)
Calculator.java
(一个虚拟的 Java 文件,可能不正确,因为它仅用于演示目的)
public class Calculator
{
private final static String FORMULA_A = "formula_a";
private final static String FORMULA_B = "formula_b";
private final static String FORMULA_C = "formula_c";
public static void main(String[] args)
{
long a = 1738342634L;
long b = 273562347895L;
long c = 89346755249L;
long ansFromFormulaA = applyFormulaFromConfig(FORMULA_A, new long[] { a, b, c });
long ansFromFormulaB = applyFormulaFromConfig(FORMULA_B, new long[] { a, b, c });
long ansFromFormulaC = applyFormulaFromConfig(FORMULA_C, new long[] { a, b });
}
// spilt_time is used in formula_c
public static long[] spilt_time(long[] params)
{
final long[] split = new long[2];
// Some logic here which is applied on params array and answer is pushed
// into split array
return split;
}
private static long applyFormulaFromConfig(String formulaName, long[] params)
{
long ans = 0L;
// Read formula from property file here and apply the params over it and
// return the answer
return ans;
}
}
请帮我设计一个解决方案。