MCPcopy Create free account
hub / github.com/ChenSen5/api_autotest / FunctionUtil

Class FunctionUtil

src/main/java/com/sen/api/utils/FunctionUtil.java:9–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import com.sen.api.functions.Function;
8
9public class FunctionUtil{
10
11 private static final Map<String, Class<? extends Function>> functionsMap = new HashMap<String, Class<? extends Function>>();
12 static {
13 //bodyfile 特殊处理
14 functionsMap.put("bodyfile", null);
15 List<Class<?>> clazzes = ClassFinder.getAllAssignedClass(Function.class);
16 clazzes.forEach((clazz) -> {
17 try {
18 // function
19 Function tempFunc = (Function) clazz.newInstance();
20 String referenceKey = tempFunc.getReferenceKey();
21 if (referenceKey.length() > 0) { // ignore self
22 functionsMap.put(referenceKey, tempFunc.getClass());
23 }
24 } catch (Exception ex) {
25 ex.printStackTrace();
26 //TODO
27 }
28 });
29 }
30
31 public static boolean isFunction(String functionName){
32 return functionsMap.containsKey(functionName);
33 }
34
35 public static String getValue(String functionName,String[] args){
36 try {
37 return functionsMap.get(functionName).newInstance().execute(args);
38 } catch (Exception e) {
39 // TODO Auto-generated catch block
40 e.printStackTrace();
41 return "";
42 }
43 }
44
45}
46

Callers

nothing calls this directly

Calls 2

getAllAssignedClassMethod · 0.95
getReferenceKeyMethod · 0.65

Tested by

no test coverage detected