| 1 | package com.github.valid8j.pcond.experimentals.currying; | |
| 2 | ||
| 3 | import com.github.valid8j.pcond.core.printable.PrintableFunctionFactory; | |
| 4 | import com.github.valid8j.pcond.experimentals.currying.context.CurriedContext; | |
| 5 | import com.github.valid8j.pcond.experimentals.currying.multi.MultiFunction; | |
| 6 | import com.github.valid8j.pcond.internals.InternalUtils; | |
| 7 | ||
| 8 | import java.util.List; | |
| 9 | import java.util.function.Function; | |
| 10 | import java.util.function.Supplier; | |
| 11 | import java.util.stream.IntStream; | |
| 12 | import java.util.stream.Stream; | |
| 13 | ||
| 14 | import static com.github.valid8j.pcond.internals.InternalUtils.formatObject; | |
| 15 | import static java.util.Arrays.asList; | |
| 16 | import static java.util.Collections.emptyList; | |
| 17 | import static java.util.stream.Collectors.joining; | |
| 18 | ||
| 19 | /** | |
| 20 | * Intended for internal use only. | |
| 21 | */ | |
| 22 | public enum CurryingUtils { | |
| 23 | ; | |
| 24 | private static final ThreadLocal<Function<List<Object>, CurriedFunction<Object, Object>>> CURRIED_FUNCTION_FACTORY_POOL = new ThreadLocal<>(); | |
| 25 | ||
| 26 | public static CurriedFunction<Object, Object> curry(MultiFunction<Object> function) { | |
| 27 |
1
1. curry : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::curry → KILLED |
return curry(function, emptyList()); |
| 28 | } | |
| 29 | ||
| 30 | public static Function<List<Object>, CurriedFunction<Object, Object>> currier() { | |
| 31 |
1
1. currier : negated conditional → KILLED |
if (CURRIED_FUNCTION_FACTORY_POOL.get() == null) |
| 32 |
1
1. currier : removed call to java/lang/ThreadLocal::set → SURVIVED |
CURRIED_FUNCTION_FACTORY_POOL.set((List<Object> args) -> |
| 33 |
1
1. lambda$currier$3 : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$currier$3 → KILLED |
PrintableFunctionFactory.create( |
| 34 |
3
1. lambda$null$0 : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$0 → KILLED 2. lambda$null$1 : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$1 → KILLED 3. lambda$null$2 : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$2 → KILLED |
(args_) -> () -> functionNameFormatter(functionName(args_), ongoingContext(args_)).apply(function(args_)), (args_) -> new CurriedFunction.Impl(function(args_), ongoingContext(args_)), args, CurryingUtils.class |
| 35 | )); | |
| 36 |
1
1. currier : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::currier → KILLED |
return CURRIED_FUNCTION_FACTORY_POOL.get(); |
| 37 | } | |
| 38 | ||
| 39 | public static <R> Function<CurriedContext, R> applyCurriedFunction(CurriedFunction<Object, Object> curriedFunction, int... orderArgs) { | |
| 40 |
1
1. applyCurriedFunction : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::applyCurriedFunction → KILLED |
return context -> { |
| 41 | CurriedFunction<?, ?> cur = curriedFunction; | |
| 42 | int[] normalizedOrderArgs = normalizeOrderArgs(context, orderArgs); | |
| 43 |
4
1. lambda$applyCurriedFunction$4 : changed conditional boundary → KILLED 2. lambda$applyCurriedFunction$4 : Changed increment from 1 to -1 → KILLED 3. lambda$applyCurriedFunction$4 : Replaced integer subtraction with addition → KILLED 4. lambda$applyCurriedFunction$4 : negated conditional → KILLED |
for (int i = 0; i < normalizedOrderArgs.length - 1; i++) |
| 44 | cur = cur.applyNext(context.valueAt(normalizedOrderArgs[i])); | |
| 45 |
2
1. lambda$applyCurriedFunction$4 : Replaced integer subtraction with addition → KILLED 2. lambda$applyCurriedFunction$4 : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$applyCurriedFunction$4 → KILLED |
return cur.applyLast(context.valueAt(normalizedOrderArgs[context.size() - 1])); |
| 46 | }; | |
| 47 | } | |
| 48 | ||
| 49 | public static int[] normalizeOrderArgs(CurriedContext curriedContext, int[] orderArgs) { | |
| 50 | int[] order; | |
| 51 |
1
1. normalizeOrderArgs : negated conditional → KILLED |
if (orderArgs.length == 0) |
| 52 | order = IntStream.range(0, curriedContext.size()).toArray(); | |
| 53 | else | |
| 54 | order = orderArgs; | |
| 55 |
1
1. normalizeOrderArgs : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::normalizeOrderArgs → KILLED |
return order; |
| 56 | } | |
| 57 | ||
| 58 | static CurriedFunction<Object, Object> curry(MultiFunction<Object> function, List<? super Object> ongoingContext) { | |
| 59 |
1
1. curry : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::curry → KILLED |
return currier().apply(asList(function.name(), function, ongoingContext)); |
| 60 | } | |
| 61 | ||
| 62 | private static String functionName(List<Object> args) { | |
| 63 |
1
1. functionName : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::functionName → KILLED |
return (String) args.get(0); |
| 64 | } | |
| 65 | ||
| 66 | @SuppressWarnings("unchecked") | |
| 67 | private static MultiFunction<Object> function(List<Object> args) { | |
| 68 |
1
1. function : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::function → KILLED |
return (MultiFunction<Object>) args.get(1); |
| 69 | } | |
| 70 | ||
| 71 | @SuppressWarnings("unchecked") | |
| 72 | private static List<? super Object> ongoingContext(List<Object> args) { | |
| 73 |
1
1. ongoingContext : replaced return value with Collections.emptyList for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::ongoingContext → KILLED |
return (List<? super Object>) args.get((2)); |
| 74 | } | |
| 75 | ||
| 76 | private static Function<MultiFunction<Object>, String> functionNameFormatter(String functionName, List<? super Object> ongoingContext) { | |
| 77 |
2
1. functionNameFormatter : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::functionNameFormatter → KILLED 2. lambda$functionNameFormatter$7 : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$functionNameFormatter$7 → KILLED |
return (MultiFunction<Object> function) -> functionName + |
| 78 |
1
1. lambda$functionNameFormatter$7 : negated conditional → KILLED |
(!ongoingContext.isEmpty() ? IntStream.range(0, ongoingContext.size()) |
| 79 |
1
1. lambda$null$5 : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$5 → KILLED |
.mapToObj(i -> function.parameterType(i).getSimpleName() + ":" + ongoingContext.get(i)) |
| 80 | .collect(joining(",", "(", ")")) : "") + | |
| 81 | IntStream.range(ongoingContext.size(), function.arity()) | |
| 82 |
1
1. lambda$null$6 : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$6 → KILLED |
.mapToObj(i -> "(" + function.parameterType(i).getSimpleName() + ")") |
| 83 | .collect(joining()); | |
| 84 | } | |
| 85 | ||
| 86 | public static String formatParameterOrder(List<Integer> paramOrder) { | |
| 87 | String formatted = formatParamOrder(paramOrder.stream()); | |
| 88 | String uncustomized = formatParamOrder(IntStream.range(0, paramOrder.size()).boxed()); | |
| 89 |
2
1. formatParameterOrder : negated conditional → KILLED 2. formatParameterOrder : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::formatParameterOrder → KILLED |
return formatted.equals(uncustomized) ? |
| 90 | "" : | |
| 91 | formatted; | |
| 92 | } | |
| 93 | ||
| 94 | private static String formatParamOrder(Stream<Integer> paramOrderStream) { | |
| 95 |
1
1. formatParamOrder : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::formatParamOrder → KILLED |
return paramOrderStream.map(Object::toString).collect(joining(",", "(", ")")); |
| 96 | } | |
| 97 | ||
| 98 | static Supplier<String> messageInvalidTypeArgument(Object value, Class<?> aClass) { | |
| 99 |
3
1. lambda$messageInvalidTypeArgument$8 : negated conditional → KILLED 2. lambda$messageInvalidTypeArgument$8 : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$messageInvalidTypeArgument$8 → KILLED 3. messageInvalidTypeArgument : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::messageInvalidTypeArgument → KILLED |
return () -> "Given argument:" + InternalUtils.formatObject(value) + |
| 100 | (value == null ? | |
| 101 | "" : | |
| 102 | "(" + value.getClass() + ")") + | |
| 103 | " cannot be assigned to parameter:" + aClass.getCanonicalName(); | |
| 104 | } | |
| 105 | } | |
Mutations | ||
| 27 |
1.1 |
|
| 31 |
1.1 |
|
| 32 |
1.1 |
|
| 33 |
1.1 |
|
| 34 |
1.1 2.2 3.3 |
|
| 36 |
1.1 |
|
| 40 |
1.1 |
|
| 43 |
1.1 2.2 3.3 4.4 |
|
| 45 |
1.1 2.2 |
|
| 51 |
1.1 |
|
| 55 |
1.1 |
|
| 59 |
1.1 |
|
| 63 |
1.1 |
|
| 68 |
1.1 |
|
| 73 |
1.1 |
|
| 77 |
1.1 2.2 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 82 |
1.1 |
|
| 89 |
1.1 2.2 |
|
| 95 |
1.1 |
|
| 99 |
1.1 2.2 3.3 |