| 1 | package com.github.valid8j.pcond.experimentals.currying; | |
| 2 | ||
| 3 | import com.github.valid8j.pcond.internals.InternalChecks; | |
| 4 | import com.github.valid8j.pcond.internals.InternalUtils; | |
| 5 | ||
| 6 | import java.util.function.Supplier; | |
| 7 | ||
| 8 | import static com.github.valid8j.pcond.internals.InternalUtils.formatObject; | |
| 9 | ||
| 10 | /** | |
| 11 | * A utility class for checking values that the "currying" mechanism of the `pcond` | |
| 12 | * library processes. | |
| 13 | */ | |
| 14 | public enum Checks { | |
| 15 | ; | |
| 16 | ||
| 17 | static <T extends CurriedFunction<?, ?>> T requireLast(T value) { | |
| 18 |
1
1. requireLast : negated conditional → KILLED |
if (value.hasNext()) |
| 19 | throw new IllegalStateException(); | |
| 20 |
1
1. requireLast : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/Checks::requireLast → KILLED |
return value; |
| 21 | } | |
| 22 | ||
| 23 | /** | |
| 24 | * Validates if a given argument value is appropriate for a parameter type (`paramType`). | |
| 25 | * | |
| 26 | * @param arg An argument value is to check with `paramType`. | |
| 27 | * @param paramType An expected type for `arg`. | |
| 28 | * @param messageFormatter A message formatter which generates a message on a failure. | |
| 29 | * @param <T> The type of the argument value. | |
| 30 | * @return The `arg` value itself. | |
| 31 | */ | |
| 32 | static <T> T validateArgumentType(T arg, Class<?> paramType, Supplier<String> messageFormatter) { | |
| 33 |
1
1. validateArgumentType : removed call to com/github/valid8j/pcond/internals/InternalChecks::checkArgument → KILLED |
InternalChecks.checkArgument(isValidValueForType(arg, paramType), messageFormatter); |
| 34 |
1
1. validateArgumentType : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/Checks::validateArgumentType → KILLED |
return arg; |
| 35 | } | |
| 36 | ||
| 37 | static boolean isValidValueForType(Object arg, Class<?> paramType) { | |
| 38 |
1
1. isValidValueForType : negated conditional → KILLED |
if (paramType.isPrimitive()) { |
| 39 |
1
1. isValidValueForType : negated conditional → KILLED |
if (arg == null) |
| 40 |
2
1. isValidValueForType : replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/Checks::isValidValueForType → SURVIVED 2. isValidValueForType : replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/Checks::isValidValueForType → KILLED |
return paramType.equals(void.class); |
| 41 |
1
1. isValidValueForType : negated conditional → KILLED |
if (InternalChecks.isPrimitiveWrapperClassOrPrimitive(arg.getClass())) { |
| 42 | Class<?> wrapperClassForParamType = InternalUtils.wrapperClassOf(paramType); | |
| 43 |
1
1. isValidValueForType : negated conditional → KILLED |
if (wrapperClassForParamType.equals(arg.getClass())) |
| 44 |
1
1. isValidValueForType : replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/Checks::isValidValueForType → KILLED |
return true; |
| 45 |
2
1. isValidValueForType : replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/Checks::isValidValueForType → KILLED 2. isValidValueForType : replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/Checks::isValidValueForType → KILLED |
return InternalChecks.isWiderThan(wrapperClassForParamType, arg.getClass()); |
| 46 | } | |
| 47 |
1
1. isValidValueForType : replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/Checks::isValidValueForType → KILLED |
return false; |
| 48 | } else { | |
| 49 |
1
1. isValidValueForType : negated conditional → KILLED |
if (arg == null) |
| 50 |
1
1. isValidValueForType : replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/Checks::isValidValueForType → KILLED |
return true; |
| 51 |
2
1. isValidValueForType : replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/Checks::isValidValueForType → KILLED 2. isValidValueForType : replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/Checks::isValidValueForType → KILLED |
return paramType.isAssignableFrom(arg.getClass()); |
| 52 | } | |
| 53 | } | |
| 54 | ||
| 55 | @SuppressWarnings("unchecked") | |
| 56 | static <T> T ensureReturnedValueType(Object value, Class<?> returnType) { | |
| 57 |
1
1. ensureReturnedValueType : negated conditional → KILLED |
if (isValidValueForType(value, returnType)) |
| 58 |
1
1. ensureReturnedValueType : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/Checks::ensureReturnedValueType → KILLED |
return (T) value; |
| 59 | else | |
| 60 | throw new IllegalStateException("Returned value:" | |
| 61 |
1
1. ensureReturnedValueType : negated conditional → KILLED |
+ InternalUtils.formatObject(value) |
| 62 | + (value != null ? "(" + value.getClass().getName() + ")" : "") | |
| 63 | + " is neither null nor an instance of " + returnType.getName() + ". "); | |
| 64 | } | |
| 65 | } | |
Mutations | ||
| 18 |
1.1 |
|
| 20 |
1.1 |
|
| 33 |
1.1 |
|
| 34 |
1.1 |
|
| 38 |
1.1 |
|
| 39 |
1.1 |
|
| 40 |
1.1 2.2 |
|
| 41 |
1.1 |
|
| 43 |
1.1 |
|
| 44 |
1.1 |
|
| 45 |
1.1 2.2 |
|
| 47 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 51 |
1.1 2.2 |
|
| 57 |
1.1 |
|
| 58 |
1.1 |
|
| 61 |
1.1 |