forked from fanruan/finekit
richie
5 years ago
4 changed files with 60 additions and 1 deletions
@ -0,0 +1,22 @@
|
||||
package com.fanruan.api.cal; |
||||
|
||||
import com.fr.base.ParameterHelper; |
||||
import com.fr.stable.ParameterProvider; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-08-16 |
||||
* 参数相关的工具类 |
||||
*/ |
||||
public class ParameterKit { |
||||
|
||||
/** |
||||
* 分析公式中所携带的参数 |
||||
* @param text 公式内容 |
||||
* @return 参数数组 |
||||
*/ |
||||
public static ParameterProvider[] analyze4ParametersFromFormula(String text) { |
||||
return ParameterHelper.analyze4ParametersFromFormula(text); |
||||
} |
||||
} |
@ -0,0 +1,27 @@
|
||||
package com.fanruan.api.cal; |
||||
|
||||
import com.fanruan.api.Prepare; |
||||
import com.fr.stable.ParameterProvider; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.TreeMap; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-08-16 |
||||
*/ |
||||
public class ParameterKitTest extends Prepare { |
||||
|
||||
@Test |
||||
public void analyze4ParametersFromFormula() { |
||||
ParameterProvider[] providers = ParameterKit.analyze4ParametersFromFormula("=sum($p1, $p2) + max($p4 - 1, pow(2, $p5))"); |
||||
TreeMap<String, Object> map = new TreeMap<>(); |
||||
for (ParameterProvider provider : providers) { |
||||
map.put(provider.getName(), provider.getValue()); |
||||
} |
||||
String[] names = map.keySet().toArray(new String[0]); |
||||
Assert.assertArrayEquals(new String[]{"p1", "p2", "p4", "p5"}, names); |
||||
} |
||||
} |
Loading…
Reference in new issue