1 | package com.github.valid8j.pcond.experimentals.currying; | |
2 | ||
3 | import com.github.valid8j.pcond.experimentals.currying.multi.MultiFunction; | |
4 | import com.github.valid8j.pcond.internals.InternalUtils; | |
5 | ||
6 | import java.util.List; | |
7 | import java.util.NoSuchElementException; | |
8 | import java.util.function.Function; | |
9 | ||
10 | public interface CurriedFunction<T, R> extends Function<T, R> { | |
11 | R applyFunction(T value); | |
12 | ||
13 | default R apply(T value) { | |
14 |
1
1. apply : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::apply → KILLED |
return Checks.ensureReturnedValueType(this.applyFunction(validateArg(value)), returnType()); |
15 | } | |
16 | ||
17 | @SuppressWarnings("unchecked") | |
18 | default <V> V applyLast(T value) { | |
19 |
1
1. applyLast : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::applyLast → KILLED |
return (V) Checks.requireLast(this).apply(value); |
20 | } | |
21 | ||
22 | @SuppressWarnings("unchecked") | |
23 | default <V extends CurriedFunction<T, R>> V applyNext(T value) { | |
24 |
1
1. applyNext : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::applyNext → KILLED |
return (V) requireHasNext(this).apply(value); |
25 | } | |
26 | ||
27 | static <V extends CurriedFunction<T, R>, T, R> V requireHasNext(V value) { | |
28 |
1
1. requireHasNext : negated conditional → KILLED |
if (!value.hasNext()) |
29 | throw new NoSuchElementException(); | |
30 |
1
1. requireHasNext : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::requireHasNext → KILLED |
return value; |
31 | } | |
32 | ||
33 | Class<?> parameterType(); | |
34 | ||
35 | Class<?> returnType(); | |
36 | ||
37 | default boolean hasNext() { | |
38 |
2
1. hasNext : replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::hasNext → KILLED 2. hasNext : replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::hasNext → KILLED |
return CurriedFunction.class.isAssignableFrom(returnType()); |
39 | } | |
40 | ||
41 | default boolean isValidArg(Object arg) { | |
42 |
2
1. isValidArg : replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::isValidArg → KILLED 2. isValidArg : replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::isValidArg → KILLED |
return Checks.isValidValueForType(arg, this.parameterType()); |
43 | } | |
44 | ||
45 | default <V> V validateArg(V arg) { | |
46 |
1
1. validateArg : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::validateArg → KILLED |
return Checks.validateArgumentType(arg, parameterType(), CurryingUtils.messageInvalidTypeArgument(arg, parameterType())); |
47 | } | |
48 | ||
49 | class Impl implements CurriedFunction<Object, Object> { | |
50 | private final MultiFunction<Object> function; | |
51 | private final List<? super Object> ongoingContext; | |
52 | ||
53 | public Impl(MultiFunction<Object> function, List<? super Object> ongoingContext) { | |
54 | this.function = function; | |
55 | this.ongoingContext = ongoingContext; | |
56 | } | |
57 | ||
58 | @Override | |
59 | public Class<?> parameterType() { | |
60 |
1
1. parameterType : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::parameterType → KILLED |
return function.parameterType(ongoingContext.size()); |
61 | } | |
62 | ||
63 | @Override | |
64 | public Class<?> returnType() { | |
65 |
2
1. returnType : Replaced integer subtraction with addition → KILLED 2. returnType : negated conditional → KILLED |
if (ongoingContext.size() == function.arity() - 1) |
66 |
1
1. returnType : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::returnType → KILLED |
return function.returnType(); |
67 | else | |
68 |
1
1. returnType : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::returnType → KILLED |
return CurriedFunction.class; |
69 | } | |
70 | ||
71 | @Override | |
72 | public Object applyFunction(Object p) { | |
73 |
2
1. applyFunction : Replaced integer subtraction with addition → KILLED 2. applyFunction : negated conditional → KILLED |
if (ongoingContext.size() == function.arity() - 1) |
74 |
1
1. applyFunction : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::applyFunction → KILLED |
return function.apply(InternalUtils.append(ongoingContext, p)); |
75 |
1
1. applyFunction : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::applyFunction → KILLED |
return CurryingUtils.curry(function, InternalUtils.append(ongoingContext, p)); |
76 | } | |
77 | } | |
78 | } | |
Mutations | ||
14 |
1.1 |
|
19 |
1.1 |
|
24 |
1.1 |
|
28 |
1.1 |
|
30 |
1.1 |
|
38 |
1.1 2.2 |
|
42 |
1.1 2.2 |
|
46 |
1.1 |
|
60 |
1.1 |
|
65 |
1.1 2.2 |
|
66 |
1.1 |
|
68 |
1.1 |
|
73 |
1.1 2.2 |
|
74 |
1.1 |
|
75 |
1.1 |