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