| 1 | package com.github.valid8j.pcond.core.fluent; | |
| 2 | ||
| 3 | import com.github.valid8j.pcond.fluent.Statement; | |
| 4 | import com.github.valid8j.pcond.forms.Predicates; | |
| 5 | ||
| 6 | import java.util.function.Function; | |
| 7 | import java.util.function.Predicate; | |
| 8 | import java.util.function.Supplier; | |
| 9 | ||
| 10 | import static java.util.Objects.requireNonNull; | |
| 11 | ||
| 12 | /** | |
| 13 | * // @formatter:off | |
| 14 | * An interface that defines methods to check a target value. | |
| 15 | * By default, calls of checking methods defined in this and sub-interfaces of this interface will be a conjunction of them. | |
| 16 | * To make it a disjunction, call {@link Checker#anyOf()}. | |
| 17 | * | |
| 18 | * User-exposing methods to check values in this method names should be progressive and its objective so that they can | |
| 19 | * follow "to be" or "satisfies" in an English sentence. | |
| 20 | * | |
| 21 | * // @formatter:on | |
| 22 | * | |
| 23 | * @param <V> The type of the checker. | |
| 24 | * @param <T> The type from which the target value is transformed. | |
| 25 | * @param <R> The type of the target value. | |
| 26 | */ | |
| 27 | public interface Checker< | |
| 28 | V extends Checker<V, T, R>, | |
| 29 | T, | |
| 30 | R> extends | |
| 31 | Matcher<V, T, R>, | |
| 32 | Statement<T> { | |
| 33 | V addCheckPhrase(Function<Checker<?, R, R>, Predicate<R>> phrase); | |
| 34 | ||
| 35 | /** | |
| 36 | * Checks if the target value satisfies the given `predicate`. | |
| 37 | * | |
| 38 | * @param predicate A predicate to check the target value. | |
| 39 | * @return This object. | |
| 40 | */ | |
| 41 | @SuppressWarnings("unchecked") | |
| 42 | default V checkWithPredicate(Predicate<? super R> predicate) { | |
| 43 | requireNonNull(predicate); | |
| 44 |
2
1. checkWithPredicate : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker::checkWithPredicate → KILLED 2. lambda$checkWithPredicate$0 : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker::lambda$checkWithPredicate$0 → KILLED |
return addCheckPhrase(w -> (Predicate<R>) predicate); |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * A synonym of {@link Checker#checkWithPredicate(Predicate)}. | |
| 49 | * | |
| 50 | * @param predicate A predicate to check the target value. | |
| 51 | * @return this object. | |
| 52 | */ | |
| 53 | default V predicate(Predicate<? super R> predicate) { | |
| 54 |
1
1. predicate : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker::predicate → KILLED |
return checkWithPredicate(predicate); |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * Convert this object into a printable predicate to check the target value. | |
| 59 | * | |
| 60 | * @return A predicate to check the target value. | |
| 61 | */ | |
| 62 | default Predicate<T> done() { | |
| 63 |
1
1. done : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker::done → KILLED |
return statementPredicate(); |
| 64 | } | |
| 65 | ||
| 66 | @SuppressWarnings("unchecked") | |
| 67 | default V not(Function<V, V> phrase) { | |
| 68 |
2
1. lambda$not$1 : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker::lambda$not$1 → SURVIVED 2. not : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker::not → SURVIVED |
return this.addCheckPhrase((v) -> (Predicate<R>) Predicates.not(phrase.apply((V) v).done())); |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * // @formatter:off | |
| 73 | * When you use an assertion method that accepts multiple statements (`Statement`), it requires all the elements in the array (`varargs`) should have the same generic parameter type. | |
| 74 | * However, you sometimes want to check multiple types at once. | |
| 75 | * By calling this method for every statement building method calling chain, you can address the compilation error. | |
| 76 | * | |
| 77 | * [source, java] | |
| 78 | * ``` | |
| 79 | * class Example { | |
| 80 | * public static void main(String... args) { | |
| 81 | * assert all( | |
| 82 | * objectValue(arg[0]).isNotNull().$(), | |
| 83 | * objectValue(new Example()).isNotNull().$(), | |
| 84 | * ... | |
| 85 | * ); | |
| 86 | * } | |
| 87 | * } | |
| 88 | * ``` | |
| 89 | * | |
| 90 | * // @formatter.off | |
| 91 | * | |
| 92 | * @return A statement for `java.lang.Object` type. | |
| 93 | */ | |
| 94 | @SuppressWarnings("unchecked") | |
| 95 | default Statement<Object> $() { | |
| 96 |
1
1. $ : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker::$ → KILLED |
return (Statement<Object>) this; |
| 97 | } | |
| 98 | ||
| 99 | abstract class Base< | |
| 100 | V extends Checker<V, T, R>, | |
| 101 | T, | |
| 102 | R> extends | |
| 103 | Matcher.Base< | |
| 104 | V, | |
| 105 | T, | |
| 106 | R | |
| 107 | > implements | |
| 108 | Checker< | |
| 109 | V, | |
| 110 | T, | |
| 111 | R> { | |
| 112 | public Base(Supplier<T> baseValue, Function<T, R> transformFunction) { | |
| 113 | super(baseValue, transformFunction); | |
| 114 | } | |
| 115 | ||
| 116 | @SuppressWarnings("unchecked") | |
| 117 | @Override | |
| 118 | public V addCheckPhrase(Function<Checker<?, R, R>, Predicate<R>> phrase) { | |
| 119 |
2
1. addCheckPhrase : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker$Base::addCheckPhrase → KILLED 2. lambda$addCheckPhrase$0 : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker$Base::lambda$addCheckPhrase$0 → KILLED |
return this.addPredicate((Matcher<?, R, R> v) -> phrase.apply((Checker<?, R, R>) v)); |
| 120 | } | |
| 121 | ||
| 122 | @Override | |
| 123 | public T statementValue() { | |
| 124 |
1
1. statementValue : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker$Base::statementValue → KILLED |
return this.baseValue(); |
| 125 | } | |
| 126 | ||
| 127 | @Override | |
| 128 | public Predicate<T> statementPredicate() { | |
| 129 |
1
1. statementPredicate : replaced return value with null for com/github/valid8j/pcond/core/fluent/Checker$Base::statementPredicate → KILLED |
return toPredicate(); |
| 130 | } | |
| 131 | } | |
| 132 | } | |
Mutations | ||
| 44 |
1.1 2.2 |
|
| 54 |
1.1 |
|
| 63 |
1.1 |
|
| 68 |
1.1 2.2 |
|
| 96 |
1.1 |
|
| 119 |
1.1 2.2 |
|
| 124 |
1.1 |
|
| 129 |
1.1 |