CurryingUtils.java

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
Location : curry
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::curry → KILLED

31

1.1
Location : currier
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
negated conditional → KILLED

32

1.1
Location : currier
Killed by : none
removed call to java/lang/ThreadLocal::set → SURVIVED

33

1.1
Location : lambda$currier$3
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$currier$3 → KILLED

34

1.1
Location : lambda$null$0
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenToStringOnOngoing$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$0 → KILLED

2.2
Location : lambda$null$1
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$1 → KILLED

3.3
Location : lambda$null$2
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$2 → KILLED

36

1.1
Location : currier
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::currier → KILLED

40

1.1
Location : applyCurriedFunction
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello_b(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::applyCurriedFunction → KILLED

43

1.1
Location : lambda$applyCurriedFunction$4
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello_b(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
changed conditional boundary → KILLED

2.2
Location : lambda$applyCurriedFunction$4
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello_b(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
Changed increment from 1 to -1 → KILLED

3.3
Location : lambda$applyCurriedFunction$4
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello_b(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
Replaced integer subtraction with addition → KILLED

4.4
Location : lambda$applyCurriedFunction$4
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello_b(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
negated conditional → KILLED

45

1.1
Location : lambda$applyCurriedFunction$4
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello_b(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
Replaced integer subtraction with addition → KILLED

2.2
Location : lambda$applyCurriedFunction$4
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello_b(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$applyCurriedFunction$4 → KILLED

51

1.1
Location : normalizeOrderArgs
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello_b(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
negated conditional → KILLED

55

1.1
Location : normalizeOrderArgs
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello_b(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::normalizeOrderArgs → KILLED

59

1.1
Location : curry
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::curry → KILLED

63

1.1
Location : functionName
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenToStringOnOngoing$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::functionName → KILLED

68

1.1
Location : function
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::function → KILLED

73

1.1
Location : ongoingContext
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyNextMoreThanExpected$thenNoSuchElementIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with Collections.emptyList for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::ongoingContext → KILLED

77

1.1
Location : functionNameFormatter
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenToStringOnOngoing$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::functionNameFormatter → KILLED

2.2
Location : lambda$functionNameFormatter$7
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenToStringOnOngoing$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$functionNameFormatter$7 → KILLED

78

1.1
Location : lambda$functionNameFormatter$7
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenToStringOnOngoing$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
negated conditional → KILLED

79

1.1
Location : lambda$null$5
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenToStringOnOngoing$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$5 → KILLED

82

1.1
Location : lambda$null$6
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenToStringOnOngoing$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$null$6 → KILLED

89

1.1
Location : formatParameterOrder
Killed by : com.github.valid8j.ut.internal.FunctionsTest$MultiFunctionTest.toStringMultiParameterFunction$thenExpectedValueReturned(com.github.valid8j.ut.internal.FunctionsTest$MultiFunctionTest)
negated conditional → KILLED

2.2
Location : formatParameterOrder
Killed by : com.github.valid8j.ut.internal.FunctionsTest$MultiFunctionTest.toStringMultiParameterFunction$withReversedOrder$thenExpectedValueReturned(com.github.valid8j.ut.internal.FunctionsTest$MultiFunctionTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::formatParameterOrder → KILLED

95

1.1
Location : formatParamOrder
Killed by : com.github.valid8j.ut.internal.FunctionsTest$MultiFunctionTest.toStringMultiParameterFunction$withReversedOrder$thenExpectedValueReturned(com.github.valid8j.ut.internal.FunctionsTest$MultiFunctionTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::formatParamOrder → KILLED

99

1.1
Location : lambda$messageInvalidTypeArgument$8
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyWithInvalidArg$thenThrown(com.github.valid8j.ut.currying.CurryingTest)
negated conditional → KILLED

2.2
Location : lambda$messageInvalidTypeArgument$8
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyWithInvalidArg$thenThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::lambda$messageInvalidTypeArgument$8 → KILLED

3.3
Location : messageInvalidTypeArgument
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyWithInvalidArg$thenThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurryingUtils::messageInvalidTypeArgument → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3