1 | package com.github.dakusui.pcond.experimentals.currying.multi; | |
2 | ||
3 | import com.github.dakusui.pcond.core.printable.PrintableFunctionFactory; | |
4 | import com.github.dakusui.pcond.internals.InternalUtils; | |
5 | ||
6 | import java.lang.reflect.Method; | |
7 | import java.util.Arrays; | |
8 | import java.util.HashMap; | |
9 | import java.util.List; | |
10 | import java.util.Map; | |
11 | ||
12 | import static java.util.Arrays.asList; | |
13 | import static java.util.stream.Collectors.toList; | |
14 | ||
15 | /** | |
16 | * A utility class that collects helper methods for the multi-parameters function. | |
17 | */ | |
18 | public enum MultiFunctionUtils { | |
19 | ; | |
20 | private static final ThreadLocal<Map<List<Object>, MultiFunction<?>>> METHOD_BASED_FUNCTION_POOL = new ThreadLocal<>(); | |
21 | ||
22 | @SuppressWarnings("unchecked") | |
23 | public static <R> MultiFunction<R> multifunction(int[] order, Class<?> aClass, String methodName, Class<?>... parameterTypes) { | |
24 | Map<List<Object>, MultiFunction<?>> methodBasedMultiParameterFunctionPool = methodBasedMultiParameterFunctionPool(); | |
25 | List<Object> multiParamFuncDef = composeFuncDef(order, aClass, methodName, parameterTypes); | |
26 | methodBasedMultiParameterFunctionPool.computeIfAbsent( | |
27 | multiParamFuncDef, | |
28 | MultiFunctionUtils::createMultiParameterFunctionForStaticMethod); | |
29 |
1
1. multifunction : replaced return value with null for com/github/dakusui/pcond/experimentals/currying/multi/MultiFunctionUtils::multifunction → KILLED |
return (MultiFunction<R>) methodBasedMultiParameterFunctionPool.get(multiParamFuncDef); |
30 | } | |
31 | ||
32 | private static List<Object> composeFuncDef(int[] order, Class<?> aClass, String methodName, Class<?>[] parameterTypes) { | |
33 |
1
1. composeFuncDef : replaced return value with Collections.emptyList for com/github/dakusui/pcond/experimentals/currying/multi/MultiFunctionUtils::composeFuncDef → KILLED |
return asList(InternalUtils.getMethod(aClass, methodName, parameterTypes), Arrays.stream(order).boxed().collect(toList())); |
34 | } | |
35 | ||
36 | private static <R> MultiFunction<R> createMultiParameterFunctionForStaticMethod(List<Object> multiParamFuncDef) { | |
37 | final Method method = (Method) multiParamFuncDef.get(0); | |
38 | @SuppressWarnings("unchecked") final List<Integer> paramOrder = (List<Integer>) multiParamFuncDef.get(1); | |
39 |
1
1. createMultiParameterFunctionForStaticMethod : replaced return value with null for com/github/dakusui/pcond/experimentals/currying/multi/MultiFunctionUtils::createMultiParameterFunctionForStaticMethod → KILLED |
return PrintableFunctionFactory.multifunction(method, paramOrder); |
40 | } | |
41 | ||
42 | private static Map<List<Object>, MultiFunction<?>> methodBasedMultiParameterFunctionPool() { | |
43 |
1
1. methodBasedMultiParameterFunctionPool : negated conditional → KILLED |
if (METHOD_BASED_FUNCTION_POOL.get() == null) |
44 |
1
1. methodBasedMultiParameterFunctionPool : removed call to java/lang/ThreadLocal::set → SURVIVED |
METHOD_BASED_FUNCTION_POOL.set(new HashMap<>()); |
45 |
1
1. methodBasedMultiParameterFunctionPool : replaced return value with Collections.emptyMap for com/github/dakusui/pcond/experimentals/currying/multi/MultiFunctionUtils::methodBasedMultiParameterFunctionPool → KILLED |
return METHOD_BASED_FUNCTION_POOL.get(); |
46 | } | |
47 | } | |
Mutations | ||
29 |
1.1 |
|
33 |
1.1 |
|
39 |
1.1 |
|
43 |
1.1 |
|
44 |
1.1 |
|
45 |
1.1 |