1 | package com.github.valid8j.classic; | |
2 | ||
3 | import com.github.valid8j.pcond.validator.Validator; | |
4 | ||
5 | import java.util.function.Predicate; | |
6 | ||
7 | /** | |
8 | * A class that offers entry-points for checking "postconditions" with a normal | |
9 | * conditional statement of Java language. | |
10 | * That is, `if` or ternary operator, not an `assert` statement. | |
11 | * This means, the user of your product is not able to disable the checks you | |
12 | * write at runtime, unlike ones written using `assert` statements. | |
13 | * | |
14 | * The author of library thinks these methods should be used in "public facing" | |
15 | * methods, when you should claim that the "external" party introduced the bug. | |
16 | * | |
17 | * The author of library thinks these methods should be used in "public facing" | |
18 | * context when the provider of the value to be examined introduced | |
19 | * a bug, which makes the condition `false`. | |
20 | * | |
21 | * For instance, it is an intended use-case, where you call `ensure` at the end of | |
22 | * your method in order to express a condition to be satisfied by the value returned | |
23 | * from your method. | |
24 | */ | |
25 | public enum Ensures { | |
26 | ; | |
27 | ||
28 | /** | |
29 | * Checks if a given value is not `null`. | |
30 | * If not an exception will be thrown. | |
31 | * | |
32 | * @param value A value to be checked. | |
33 | * @return The value itself. | |
34 | * @param <T> The type of the `value`. | |
35 | */ | |
36 | public static <T> T ensureNonNull(T value) { | |
37 |
1
1. ensureNonNull : replaced return value with null for com/github/valid8j/classic/Ensures::ensureNonNull → KILLED |
return Validator.instance().ensureNonNull(value); |
38 | } | |
39 | ||
40 | /** | |
41 | * Checks if a given state `value`satisfies a postcondition `cond`. | |
42 | * If not an exception will be thrown. | |
43 | * | |
44 | * @param value A value to be checked. | |
45 | * @param cond A condition that checks `value`. | |
46 | * @return The `value` itself | |
47 | * @param <T> The type of the `value`. | |
48 | */ | |
49 | public static <T> T ensureState(T value, Predicate<? super T> cond) { | |
50 |
1
1. ensureState : replaced return value with null for com/github/valid8j/classic/Ensures::ensureState → KILLED |
return Validator.instance().ensureState(value, cond); |
51 | } | |
52 | ||
53 | /** | |
54 | * Checks if a given `value` satisfies a postcondition `cond`. | |
55 | * If not an exception will be thrown. | |
56 | * | |
57 | * @param value A value to be checked. | |
58 | * @param cond A condition that checks `value`. | |
59 | * @return The `value` itself. | |
60 | * @param <T> The type of the `value`. | |
61 | */ | |
62 | public static <T> T ensure(T value, Predicate<? super T> cond) { | |
63 |
1
1. ensure : replaced return value with null for com/github/valid8j/classic/Ensures::ensure → KILLED |
return Validator.instance().ensure(value, cond); |
64 | } | |
65 | } | |
Mutations | ||
37 |
1.1 |
|
50 |
1.1 |
|
63 |
1.1 |