1 | package com.github.dakusui.pcond.internals; | |
2 | ||
3 | import com.github.dakusui.pcond.core.refl.ReflUtils; | |
4 | ||
5 | import java.lang.reflect.Method; | |
6 | import java.lang.reflect.Modifier; | |
7 | import java.util.HashSet; | |
8 | import java.util.List; | |
9 | import java.util.Set; | |
10 | import java.util.function.Function; | |
11 | import java.util.function.Predicate; | |
12 | import java.util.function.Supplier; | |
13 | ||
14 | import static java.lang.String.format; | |
15 | import static java.util.Collections.emptySet; | |
16 | import static java.util.Collections.unmodifiableList; | |
17 | import static java.util.stream.Collectors.toList; | |
18 | ||
19 | public enum InternalChecks { | |
20 | ; | |
21 | ||
22 | private static final Set<Class<?>> PRIMITIVE_WRAPPERS = new HashSet<Class<?>>() {{ | |
23 | add(Integer.class); | |
24 | add(Long.class); | |
25 | add(Boolean.class); | |
26 | add(Byte.class); | |
27 | add(Character.class); | |
28 | add(Float.class); | |
29 | add(Double.class); | |
30 | add(Short.class); | |
31 | add(Void.class); | |
32 | }}; | |
33 | ||
34 | public static void checkArgument(boolean b, Supplier<String> messageFormatter) { | |
35 |
1
1. checkArgument : negated conditional → KILLED |
if (!b) |
36 | throw new IllegalArgumentException(messageFormatter.get()); | |
37 | } | |
38 | ||
39 | public static <V> V requireArgument(V arg, Predicate<? super V> predicate, Supplier<String> messageFormatter) { | |
40 |
1
1. requireArgument : negated conditional → KILLED |
if (!predicate.test(arg)) |
41 | throw new IllegalArgumentException(messageFormatter.get()); | |
42 |
1
1. requireArgument : replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::requireArgument → KILLED |
return arg; |
43 | } | |
44 | ||
45 | public static <V> V ensureValue(V value, Predicate<? super V> predicate, Function<V, String> messageFormatter) { | |
46 |
1
1. ensureValue : negated conditional → KILLED |
if (!predicate.test(value)) |
47 | throw new IllegalStateException(messageFormatter.apply(value)); | |
48 |
1
1. ensureValue : replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::ensureValue → KILLED |
return value; |
49 | } | |
50 | ||
51 | public static <V> V requireState(V arg, Predicate<? super V> predicate, Function<V, String> messageFormatter) { | |
52 |
1
1. requireState : negated conditional → KILLED |
if (!predicate.test(arg)) |
53 | throw new IllegalStateException(messageFormatter.apply(arg)); | |
54 |
1
1. requireState : replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::requireState → KILLED |
return arg; |
55 | } | |
56 | ||
57 | public static Method requireStaticMethod(Method method) { | |
58 |
1
1. requireStaticMethod : negated conditional → KILLED |
if (!Modifier.isStatic(method.getModifiers())) |
59 | throw new IllegalArgumentException(String.format("The specified method '%s' is not static", method)); | |
60 |
1
1. requireStaticMethod : replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::requireStaticMethod → SURVIVED |
return method; |
61 | } | |
62 | ||
63 | public static List<Object> requireArgumentListSize(List<Object> args, int requiredSize) { | |
64 |
1
1. requireArgumentListSize : negated conditional → KILLED |
if (requiredSize != args.size()) |
65 | throw new IllegalArgumentException(String.format("Wrong number of arguments are given: required: %s, actual: %s", requiredSize, args.size())); | |
66 |
1
1. requireArgumentListSize : replaced return value with Collections.emptyList for com/github/dakusui/pcond/internals/InternalChecks::requireArgumentListSize → KILLED |
return args; |
67 | } | |
68 | ||
69 | public static boolean isWiderThanOrEqualTo(Class<?> classA, Class<?> classB) { | |
70 |
1
1. lambda$isWiderThanOrEqualTo$0 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThanOrEqualTo$0 → SURVIVED |
requireArgument(classA, InternalChecks::isPrimitiveWrapperClass, () -> format("'%s' is not a primitive wrapper class", classA)); |
71 |
1
1. lambda$isWiderThanOrEqualTo$1 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThanOrEqualTo$1 → SURVIVED |
requireArgument(classB, InternalChecks::isPrimitiveWrapperClass, () -> format("'%s' is not a primitive wrapper class", classB)); |
72 |
3
1. isWiderThanOrEqualTo : negated conditional → KILLED 2. isWiderThanOrEqualTo : negated conditional → KILLED 3. isWiderThanOrEqualTo : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isWiderThanOrEqualTo → KILLED |
return classA.equals(classB) || isWiderThan(classA, classB); |
73 | } | |
74 | ||
75 | public static boolean isPrimitiveWrapperClass(Class<?> aClass) { | |
76 |
2
1. isPrimitiveWrapperClass : replaced boolean return with false for com/github/dakusui/pcond/internals/InternalChecks::isPrimitiveWrapperClass → KILLED 2. isPrimitiveWrapperClass : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isPrimitiveWrapperClass → KILLED |
return PRIMITIVE_WRAPPERS.contains(aClass); |
77 | } | |
78 | ||
79 | public static boolean isPrimitiveWrapperClassOrPrimitive(Class<?> aClass) { | |
80 |
3
1. isPrimitiveWrapperClassOrPrimitive : negated conditional → KILLED 2. isPrimitiveWrapperClassOrPrimitive : negated conditional → KILLED 3. isPrimitiveWrapperClassOrPrimitive : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isPrimitiveWrapperClassOrPrimitive → KILLED |
return aClass.isPrimitive() || isPrimitiveWrapperClass(aClass); |
81 | } | |
82 | ||
83 | /** | |
84 | * @param classA A non-primitive type class. | |
85 | * @param classB Another non-primitive type class. | |
86 | * @return {@code true} iff {@code classA} is a "wider" wrapper class than {@code classB}. | |
87 | */ | |
88 | public static boolean isWiderThan(Class<?> classA, Class<?> classB) { | |
89 |
1
1. lambda$isWiderThan$2 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThan$2 → SURVIVED |
requireArgument(classA, InternalChecks::isPrimitiveWrapperClass, () -> format("'%s' is not a primitive wrapper class", classA)); |
90 |
1
1. lambda$isWiderThan$3 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThan$3 → SURVIVED |
requireArgument(classB, InternalChecks::isPrimitiveWrapperClass, () -> format("'%s' is not a primitive wrapper class", classB)); |
91 | Set<Class<?>> widerBoxedClassesForClassA = widerTypesThan(classB); | |
92 |
2
1. isWiderThan : replaced boolean return with false for com/github/dakusui/pcond/internals/InternalChecks::isWiderThan → KILLED 2. isWiderThan : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isWiderThan → KILLED |
return widerBoxedClassesForClassA.contains(classA); |
93 | } | |
94 | ||
95 | private static Set<Class<?>> widerTypesThan(Class<?> classB) { | |
96 |
1
1. widerTypesThan : replaced return value with Collections.emptySet for com/github/dakusui/pcond/internals/InternalChecks::widerTypesThan → KILLED |
return ReflUtils.WIDER_TYPES.getOrDefault(classB, emptySet()); |
97 | } | |
98 | ||
99 | public static List<Integer> validateParamOrderList(List<Integer> order, int numParameters) { | |
100 | final List<Integer> paramOrder = unmodifiableList(order.stream().distinct().collect(toList())); | |
101 |
3
1. lambda$validateParamOrderList$4 : negated conditional → KILLED 2. lambda$validateParamOrderList$4 : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$4 → KILLED 3. lambda$validateParamOrderList$5 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$5 → KILLED |
requireArgument(order, o -> o.size() == paramOrder.size(), () -> "Duplicated elements are found in the 'order' argument:" + order.toString() + " " + paramOrder); |
102 |
3
1. lambda$validateParamOrderList$6 : negated conditional → KILLED 2. lambda$validateParamOrderList$6 : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$6 → KILLED 3. lambda$validateParamOrderList$7 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$7 → KILLED |
requireArgument(order, o -> o.size() == numParameters, () -> "Inconsistent number of parameters are supplied by 'order'. Expected:" + numParameters + ", Actual: " + order.size()); |
103 |
1
1. validateParamOrderList : replaced return value with Collections.emptyList for com/github/dakusui/pcond/internals/InternalChecks::validateParamOrderList → KILLED |
return paramOrder; |
104 | } | |
105 | } | |
Mutations | ||
35 |
1.1 |
|
40 |
1.1 |
|
42 |
1.1 |
|
46 |
1.1 |
|
48 |
1.1 |
|
52 |
1.1 |
|
54 |
1.1 |
|
58 |
1.1 |
|
60 |
1.1 |
|
64 |
1.1 |
|
66 |
1.1 |
|
70 |
1.1 |
|
71 |
1.1 |
|
72 |
1.1 2.2 3.3 |
|
76 |
1.1 2.2 |
|
80 |
1.1 2.2 3.3 |
|
89 |
1.1 |
|
90 |
1.1 |
|
92 |
1.1 2.2 |
|
96 |
1.1 |
|
101 |
1.1 2.2 3.3 |
|
102 |
1.1 2.2 3.3 |
|
103 |
1.1 |