| 1 | package com.github.valid8j.pcond.forms; | |
| 2 | ||
| 3 | import com.github.valid8j.pcond.core.printable.PrintablePredicateFactory; | |
| 4 | import com.github.valid8j.pcond.core.refl.MethodQuery; | |
| 5 | import com.github.valid8j.pcond.core.refl.Parameter; | |
| 6 | import com.github.valid8j.pcond.internals.InternalChecks; | |
| 7 | import com.github.valid8j.pcond.internals.InternalUtils; | |
| 8 | ||
| 9 | import java.util.Collection; | |
| 10 | import java.util.function.Function; | |
| 11 | import java.util.function.Predicate; | |
| 12 | import java.util.stream.Stream; | |
| 13 | ||
| 14 | import static com.github.valid8j.pcond.core.refl.ReflUtils.invokeMethod; | |
| 15 | import static com.github.valid8j.pcond.forms.Printables.function; | |
| 16 | import static com.github.valid8j.pcond.forms.Printables.predicate; | |
| 17 | import static com.github.valid8j.pcond.internals.InternalUtils.formatObject; | |
| 18 | import static java.lang.String.format; | |
| 19 | import static java.util.Arrays.asList; | |
| 20 | import static java.util.Collections.singletonList; | |
| 21 | import static java.util.Objects.requireNonNull; | |
| 22 | ||
| 23 | /** | |
| 24 | * An entry point for acquiring predicate objects. | |
| 25 | * Predicates retrieved by methods in this class are all "printable". | |
| 26 | */ | |
| 27 | public class Predicates { | |
| 28 | private Predicates() { | |
| 29 | } | |
| 30 | ||
| 31 | public static <T> Predicate<T> alwaysTrue() { | |
| 32 |
1
1. alwaysTrue : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::alwaysTrue → RUN_ERROR |
return PrintablePredicateFactory.Leaf.ALWAYS_TRUE.instance(); |
| 33 | } | |
| 34 | ||
| 35 | public static Predicate<Boolean> isTrue() { | |
| 36 |
1
1. isTrue : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isTrue → RUN_ERROR |
return PrintablePredicateFactory.Leaf.IS_TRUE.instance(); |
| 37 | } | |
| 38 | ||
| 39 | public static Predicate<Boolean> isFalse() { | |
| 40 |
1
1. isFalse : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isFalse → RUN_ERROR |
return PrintablePredicateFactory.Leaf.IS_FALSE.instance(); |
| 41 | } | |
| 42 | ||
| 43 | public static <T> Predicate<T> isNull() { | |
| 44 |
1
1. isNull : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isNull → RUN_ERROR |
return PrintablePredicateFactory.Leaf.IS_NULL.instance(); |
| 45 | } | |
| 46 | ||
| 47 | public static <T> Predicate<T> isNotNull() { | |
| 48 |
1
1. isNotNull : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isNotNull → RUN_ERROR |
return PrintablePredicateFactory.Leaf.IS_NOT_NULL.instance(); |
| 49 | } | |
| 50 | ||
| 51 | public static <T> Predicate<T> isEqualTo(T value) { | |
| 52 |
1
1. isEqualTo : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isEqualTo → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.IS_EQUAL_TO, singletonList(value)); |
| 53 | } | |
| 54 | ||
| 55 | public static <T> Predicate<T> isSameReferenceAs(T value) { | |
| 56 |
1
1. isSameReferenceAs : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isSameReferenceAs → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.OBJECT_IS_SAME_AS, singletonList(value)); |
| 57 | } | |
| 58 | ||
| 59 | @SuppressWarnings({"unchecked", "RedundantClassCall"}) | |
| 60 | public static <T> Function<Class<?>, Predicate<T>> isInstanceOf() { | |
| 61 |
1
1. isInstanceOf : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isInstanceOf → RUN_ERROR |
return Function.class.cast(Def.IS_INSTANCE_OF$2); |
| 62 | } | |
| 63 | ||
| 64 | public static Predicate<Object> isInstanceOf(Class<?> value) { | |
| 65 |
1
1. isInstanceOf : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isInstanceOf → RUN_ERROR |
return applyOnceExpectingPredicate(requireNonNull(value), isInstanceOf()); |
| 66 | } | |
| 67 | ||
| 68 | private static <T, R> Predicate<R> applyOnceExpectingPredicate(T value, Function<T, Predicate<R>> p) { | |
| 69 |
2
1. applyOnceExpectingPredicate : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::applyOnceExpectingPredicate → RUN_ERROR 2. lambda$applyOnceExpectingPredicate$0 : replaced return value with "" for com/github/valid8j/pcond/forms/Predicates::lambda$applyOnceExpectingPredicate$0 → RUN_ERROR |
return Printables.predicate(() -> String.format("%s[%s]", p, InternalUtils.formatObject(value)), p.apply(value)); |
| 70 | } | |
| 71 | ||
| 72 | public static <T extends Comparable<? super T>> Predicate<T> gt(T value) { | |
| 73 |
1
1. gt : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::gt → RUN_ERROR |
return greaterThan(value); |
| 74 | } | |
| 75 | ||
| 76 | public static <T extends Comparable<? super T>> Predicate<T> greaterThan(T value) { | |
| 77 |
1
1. greaterThan : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::greaterThan → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.GREATER_THAN, singletonList(value)); |
| 78 | } | |
| 79 | ||
| 80 | public static <T extends Comparable<? super T>> Predicate<T> ge(T value) { | |
| 81 |
1
1. ge : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::ge → RUN_ERROR |
return greaterThanOrEqualTo(value); |
| 82 | } | |
| 83 | ||
| 84 | public static <T extends Comparable<? super T>> Predicate<T> greaterThanOrEqualTo(T value) { | |
| 85 |
1
1. greaterThanOrEqualTo : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::greaterThanOrEqualTo → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.GREATER_THAN_OR_EQUAL_TO, singletonList(value)); |
| 86 | } | |
| 87 | ||
| 88 | public static <T extends Comparable<? super T>> Predicate<T> lt(T value) { | |
| 89 |
1
1. lt : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::lt → RUN_ERROR |
return lessThan(value); |
| 90 | } | |
| 91 | ||
| 92 | public static <T extends Comparable<? super T>> Predicate<T> lessThan(T value) { | |
| 93 |
1
1. lessThan : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::lessThan → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.LESS_THAN, singletonList(value)); |
| 94 | } | |
| 95 | ||
| 96 | public static <T extends Comparable<? super T>> Predicate<T> le(T value) { | |
| 97 |
1
1. le : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::le → RUN_ERROR |
return lessThanOrEqualTo(value); |
| 98 | } | |
| 99 | ||
| 100 | public static <T extends Comparable<? super T>> Predicate<T> lessThanOrEqualTo(T value) { | |
| 101 |
1
1. lessThanOrEqualTo : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::lessThanOrEqualTo → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.LESS_THAN_OR_EQUAL_TO, singletonList(value)); |
| 102 | } | |
| 103 | ||
| 104 | public static <T extends Comparable<T>> Predicate<T> eq(T value) { | |
| 105 |
1
1. eq : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::eq → RUN_ERROR |
return equalTo(value); |
| 106 | } | |
| 107 | ||
| 108 | public static <T extends Comparable<T>> Predicate<T> equalTo(T value) { | |
| 109 |
1
1. equalTo : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::equalTo → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.EQUAL_TO, singletonList(value)); |
| 110 | } | |
| 111 | ||
| 112 | public static Predicate<String> matchesRegex(String regex) { | |
| 113 | requireNonNull(regex); | |
| 114 |
1
1. matchesRegex : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::matchesRegex → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.MATCHES_REGEX, singletonList(regex)); |
| 115 | } | |
| 116 | ||
| 117 | public static Predicate<String> containsString(String string) { | |
| 118 | requireNonNull(string); | |
| 119 |
1
1. containsString : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::containsString → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.CONTAINS_STRING, singletonList(string)); |
| 120 | } | |
| 121 | ||
| 122 | public static Predicate<String> startsWith(String string) { | |
| 123 | requireNonNull(string); | |
| 124 |
1
1. startsWith : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::startsWith → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.STARTS_WITH, singletonList(string)); |
| 125 | } | |
| 126 | ||
| 127 | public static Predicate<String> endsWith(String string) { | |
| 128 | requireNonNull(string); | |
| 129 |
1
1. endsWith : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::endsWith → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.ENDS_WITH, singletonList(string)); |
| 130 | } | |
| 131 | ||
| 132 | public static Predicate<String> equalsIgnoreCase(String string) { | |
| 133 | requireNonNull(string); | |
| 134 |
1
1. equalsIgnoreCase : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::equalsIgnoreCase → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.EQUALS_IGNORE_CASE, singletonList(string)); |
| 135 | } | |
| 136 | ||
| 137 | public static Predicate<String> isEmptyString() { | |
| 138 |
1
1. isEmptyString : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isEmptyString → RUN_ERROR |
return PrintablePredicateFactory.Leaf.IS_EMPTY_STRING.instance(); |
| 139 | } | |
| 140 | ||
| 141 | public static Predicate<String> isNullOrEmptyString() { | |
| 142 |
1
1. isNullOrEmptyString : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isNullOrEmptyString → RUN_ERROR |
return PrintablePredicateFactory.Leaf.IS_NULL_OR_EMPTY_STRING.instance(); |
| 143 | } | |
| 144 | ||
| 145 | public static <E> Predicate<Collection<E>> contains(Object entry) { | |
| 146 |
1
1. contains : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::contains → RUN_ERROR |
return PrintablePredicateFactory.ParameterizedLeafFactory.create(PrintablePredicateFactory.ParameterizedLeafFactory.CONTAINS, singletonList(entry)); |
| 147 | } | |
| 148 | ||
| 149 | public static Predicate<Object[]> isEmptyArray() { | |
| 150 |
1
1. isEmptyArray : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isEmptyArray → RUN_ERROR |
return PrintablePredicateFactory.Leaf.IS_EMPTY_ARRAY.instance(); |
| 151 | } | |
| 152 | ||
| 153 | public static Predicate<? super Collection<?>> isEmpty() { | |
| 154 |
1
1. isEmpty : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::isEmpty → RUN_ERROR |
return PrintablePredicateFactory.Leaf.IS_EMPTY_COLLECTION.instance(); |
| 155 | } | |
| 156 | ||
| 157 | public static <E> Predicate<Stream<E>> allMatch(Predicate<E> predicate) { | |
| 158 | requireNonNull(predicate); | |
| 159 |
1
1. allMatch : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::allMatch → RUN_ERROR |
return PrintablePredicateFactory.allMatch(predicate); |
| 160 | } | |
| 161 | ||
| 162 | public static <E> Predicate<Stream<E>> noneMatch(Predicate<E> predicate) { | |
| 163 | requireNonNull(predicate); | |
| 164 |
1
1. noneMatch : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::noneMatch → RUN_ERROR |
return PrintablePredicateFactory.noneMatch(predicate); |
| 165 | } | |
| 166 | ||
| 167 | public static <E> Predicate<Stream<E>> anyMatch(Predicate<E> predicate) { | |
| 168 | requireNonNull(predicate); | |
| 169 |
1
1. anyMatch : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::anyMatch → RUN_ERROR |
return PrintablePredicateFactory.anyMatch(predicate); |
| 170 | } | |
| 171 | ||
| 172 | @SafeVarargs | |
| 173 | public static <T> Predicate<T> and(Predicate<? super T>... predicates) { | |
| 174 |
1
1. and : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::and → RUN_ERROR |
return PrintablePredicateFactory.and(asList(predicates)); |
| 175 | } | |
| 176 | ||
| 177 | @SafeVarargs | |
| 178 | public static <T> Predicate<T> or(Predicate<? super T>... predicates) { | |
| 179 |
1
1. or : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::or → RUN_ERROR |
return PrintablePredicateFactory.or(asList(predicates)); |
| 180 | } | |
| 181 | ||
| 182 | @SafeVarargs | |
| 183 | public static <T> Predicate<T> allOf(Predicate<? super T>... predicates) { | |
| 184 |
1
1. allOf : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::allOf → RUN_ERROR |
return PrintablePredicateFactory.allOf(asList(predicates)); |
| 185 | } | |
| 186 | ||
| 187 | @SafeVarargs | |
| 188 | public static <T> Predicate<T> anyOf(Predicate<? super T>... predicates) { | |
| 189 |
1
1. anyOf : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::anyOf → RUN_ERROR |
return PrintablePredicateFactory.anyOf(asList(predicates)); |
| 190 | } | |
| 191 | ||
| 192 | public static <T> Predicate<T> not(Predicate<T> cond) { | |
| 193 |
1
1. not : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::not → RUN_ERROR |
return PrintablePredicateFactory.not(cond); |
| 194 | } | |
| 195 | ||
| 196 | public static <O, P> PrintablePredicateFactory.TransformingPredicate.Factory<P, O> transform(String funcName, Function<O, P> func) { | |
| 197 |
1
1. transform : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::transform → RUN_ERROR |
return transform(Printables.function(funcName, func)); |
| 198 | } | |
| 199 | ||
| 200 | public static <O, P> PrintablePredicateFactory.TransformingPredicate.Factory<P, O> transform(Function<O, P> function) { | |
| 201 |
1
1. transform : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::transform → RUN_ERROR |
return PrintablePredicateFactory.transform(function); |
| 202 | } | |
| 203 | ||
| 204 | /** | |
| 205 | * // @formatter:off | |
| 206 | * Returns a {@link Predicate} created from a method specified by a {@code methodQuery}. | |
| 207 | * If the {@code methodQuery} matches none or more than one methods, a {@code RuntimeException} will be thrown. | |
| 208 | * | |
| 209 | * The suffix {@code p} stands for "predicate" following the custom in LISP culture | |
| 210 | * and it is necessary to avoid collision with {@link Functions#call( MethodQuery )} method. | |
| 211 | * | |
| 212 | * // @formatter:on | |
| 213 | * | |
| 214 | * @param methodQuery A query object that specifies a method to be invoked by the returned predicate. | |
| 215 | * @param <T> the type of the input to the returned predicate | |
| 216 | * @return Created predicate. | |
| 217 | * @see Functions#classMethod(Class, String, Object[]) | |
| 218 | * @see Functions#instanceMethod(Object, String, Object[]) | |
| 219 | * @see Functions#parameter() | |
| 220 | */ | |
| 221 | @SuppressWarnings("ConstantConditions") | |
| 222 | public static <T> Predicate<T> callp(MethodQuery methodQuery) { | |
| 223 |
1
1. callp : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::callp → RUN_ERROR |
return predicate( |
| 224 | methodQuery.describe(), | |
| 225 |
2
1. lambda$callp$5 : replaced boolean return with false for com/github/valid8j/pcond/forms/Predicates::lambda$callp$5 → RUN_ERROR 2. lambda$callp$5 : replaced boolean return with true for com/github/valid8j/pcond/forms/Predicates::lambda$callp$5 → RUN_ERROR |
t -> InternalChecks.ensureValue( |
| 226 |
3
1. lambda$null$1 : replaced boolean return with false for com/github/valid8j/pcond/forms/Predicates::lambda$null$1 → RUN_ERROR 2. lambda$null$1 : replaced boolean return with true for com/github/valid8j/pcond/forms/Predicates::lambda$null$1 → RUN_ERROR 3. lambda$null$2 : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::lambda$null$2 → RUN_ERROR |
invokeMethod(methodQuery.bindActualArguments((o) -> o instanceof Parameter, o -> t)), |
| 227 |
2
1. lambda$null$3 : replaced boolean return with false for com/github/valid8j/pcond/forms/Predicates::lambda$null$3 → RUN_ERROR 2. lambda$null$3 : replaced boolean return with true for com/github/valid8j/pcond/forms/Predicates::lambda$null$3 → RUN_ERROR |
v -> v instanceof Boolean, |
| 228 |
1
1. lambda$null$4 : replaced return value with "" for com/github/valid8j/pcond/forms/Predicates::lambda$null$4 → RUN_ERROR |
v -> format("Method matched with '%s' must return a boolean value but it gave: '%s'.", methodQuery.describe(), v))); |
| 229 | } | |
| 230 | ||
| 231 | /** | |
| 232 | * // @formatter:off | |
| 233 | * Returns a predicate that calls a method which matches the given {@code methodName} | |
| 234 | * and {@code args} on the object given as input to it. | |
| 235 | * | |
| 236 | * Note that method look up is done when the predicate is applied. | |
| 237 | * This means this method does not throw any exception by itself and in case | |
| 238 | * you give wrong {@code methodName} or {@code arguments}, an exception will be | |
| 239 | * thrown when the returned function is applied. | |
| 240 | * // @formatter:on | |
| 241 | * | |
| 242 | * @param methodName The method name | |
| 243 | * @param arguments Arguments passed to the method. | |
| 244 | * @param <T> The type of input to the returned predicate | |
| 245 | * @return A predicate that invokes the method matching the {@code methodName} and {@code args} | |
| 246 | * @see Functions#parameter() | |
| 247 | */ | |
| 248 | public static <T> Predicate<T> callp(String methodName, Object... arguments) { | |
| 249 |
1
1. callp : replaced return value with null for com/github/valid8j/pcond/forms/Predicates::callp → RUN_ERROR |
return callp(Functions.instanceMethod(Functions.parameter(), methodName, arguments)); |
| 250 | } | |
| 251 | ||
| 252 | enum Def { | |
| 253 | ; | |
| 254 | ||
| 255 |
2
1. lambda$static$0 : replaced return value with "" for com/github/valid8j/pcond/forms/Predicates$Def::lambda$static$0 → KILLED 2. lambda$static$1 : replaced return value with null for com/github/valid8j/pcond/forms/Predicates$Def::lambda$static$1 → KILLED |
public static final Function<Class<?>, Predicate<?>> IS_INSTANCE_OF$2 = Printables.function(() -> "isInstanceOf", (Class<?> c) -> c::isInstance); |
| 256 | } | |
| 257 | ||
| 258 | } | |
Mutations | ||
| 32 |
1.1 |
|
| 36 |
1.1 |
|
| 40 |
1.1 |
|
| 44 |
1.1 |
|
| 48 |
1.1 |
|
| 52 |
1.1 |
|
| 56 |
1.1 |
|
| 61 |
1.1 |
|
| 65 |
1.1 |
|
| 69 |
1.1 2.2 |
|
| 73 |
1.1 |
|
| 77 |
1.1 |
|
| 81 |
1.1 |
|
| 85 |
1.1 |
|
| 89 |
1.1 |
|
| 93 |
1.1 |
|
| 97 |
1.1 |
|
| 101 |
1.1 |
|
| 105 |
1.1 |
|
| 109 |
1.1 |
|
| 114 |
1.1 |
|
| 119 |
1.1 |
|
| 124 |
1.1 |
|
| 129 |
1.1 |
|
| 134 |
1.1 |
|
| 138 |
1.1 |
|
| 142 |
1.1 |
|
| 146 |
1.1 |
|
| 150 |
1.1 |
|
| 154 |
1.1 |
|
| 159 |
1.1 |
|
| 164 |
1.1 |
|
| 169 |
1.1 |
|
| 174 |
1.1 |
|
| 179 |
1.1 |
|
| 184 |
1.1 |
|
| 189 |
1.1 |
|
| 193 |
1.1 |
|
| 197 |
1.1 |
|
| 201 |
1.1 |
|
| 223 |
1.1 |
|
| 225 |
1.1 2.2 |
|
| 226 |
1.1 2.2 3.3 |
|
| 227 |
1.1 2.2 |
|
| 228 |
1.1 |
|
| 249 |
1.1 |
|
| 255 |
1.1 2.2 |