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