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