| 1 | package com.github.dakusui.pcond.experimentals.cursor; | |
| 2 | ||
| 3 | import com.github.dakusui.pcond.core.Evaluable; | |
| 4 | import com.github.dakusui.pcond.core.Evaluator; | |
| 5 | import com.github.dakusui.pcond.core.printable.PrintablePredicate; | |
| 6 | import com.github.dakusui.pcond.forms.Predicates; | |
| 7 | import com.github.dakusui.pcond.forms.Printables; | |
| 8 | import com.github.dakusui.pcond.internals.InternalUtils; | |
| 9 | ||
| 10 | import java.util.*; | |
| 11 | import java.util.concurrent.atomic.AtomicBoolean; | |
| 12 | import java.util.concurrent.atomic.AtomicInteger; | |
| 13 | import java.util.function.BiFunction; | |
| 14 | import java.util.function.Function; | |
| 15 | import java.util.function.Predicate; | |
| 16 | import java.util.function.Supplier; | |
| 17 | import java.util.regex.Pattern; | |
| 18 | import java.util.stream.Stream; | |
| 19 | ||
| 20 | import static com.github.dakusui.pcond.forms.Printables.function; | |
| 21 | import static com.github.dakusui.pcond.forms.Printables.predicate; | |
| 22 | import static com.github.dakusui.pcond.internals.InternalUtils.formatObject; | |
| 23 | import static java.lang.String.format; | |
| 24 | import static java.util.Collections.emptyList; | |
| 25 | import static java.util.stream.Collectors.joining; | |
| 26 | import static java.util.stream.Collectors.toList; | |
| 27 | ||
| 28 | public enum Cursors { | |
| 29 | ; | |
| 30 | | |
| 31 | /** | |
| 32 | * Note that a predicate returned by this method is stateful and not to be re-used. | |
| 33 | * | |
| 34 | * @param locatorFactory A function to return a cursor which points the location where a given token appears in an original string. | |
| 35 | * @param tokens Tokens to be found in a given string passed to the returned predicate. | |
| 36 | * @param <T> The type of token to be searched for. | |
| 37 | * @return A predicate that checks if `tokens` are all contained in a given string | |
| 38 | * in the order, where they appear in the argument. | |
| 39 | */ | |
| 40 | @SuppressWarnings("unchecked") | |
| 41 | static <T> Predicate<String> findTokens(Function<T, Function<String, Cursor>> locatorFactory, T... tokens) { | |
| 42 | AtomicBoolean result = new AtomicBoolean(true); | |
| 43 | AtomicInteger lastTestedPosition = new AtomicInteger(0); | |
| 44 | StringBuilder bExpectation = new StringBuilder(); | |
| 45 | StringBuilder bActual = new StringBuilder(); | |
| 46 | class CursoredString implements Evaluator.Snapshottable { | |
| 47 | public int previousFailingPosition; | |
| 48 | String originalString; | |
| 49 | int position; | |
| 50 | ||
| 51 | CursoredString(String originalString) { | |
| 52 | this.originalString = originalString; | |
| 53 | this.position = 0; | |
| 54 | } | |
| 55 | ||
| 56 | CursoredString findNext(T token) { | |
| 57 | Function<String, Cursor> locator = locatorFactory.apply(token); | |
| 58 | Cursor cursor = locator.apply(originalString.substring(this.position)); | |
| 59 |
2
1. findNext : changed conditional boundary → KILLED 2. findNext : negated conditional → KILLED |
if (cursor.position >= 0) { |
| 60 |
2
1. findNext : removed call to com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredString::updateOngoingExplanation → SURVIVED 2. lambda$findNext$0 : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredString::lambda$findNext$0 → SURVIVED |
updateOngoingExplanation(bExpectation, token, cursor, (lf, t) -> "found for:" + locatorFactory + "[" + t + "]"); |
| 61 |
2
1. findNext : removed call to com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredString::updateOngoingExplanation → SURVIVED 2. lambda$findNext$1 : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredString::lambda$findNext$1 → SURVIVED |
updateOngoingExplanation(bActual, token, cursor, (lf, t) -> "found for:" + locatorFactory + "[" + t + "]"); |
| 62 | ||
| 63 |
2
1. findNext : Replaced integer addition with subtraction → KILLED 2. findNext : Replaced integer addition with subtraction → KILLED |
this.position += cursor.position + cursor.length; |
| 64 | } else { | |
| 65 | this.previousFailingPosition = this.position; | |
| 66 | } | |
| 67 |
1
1. findNext : removed call to java/util/concurrent/atomic/AtomicInteger::set → SURVIVED |
lastTestedPosition.set(this.position); |
| 68 |
1
1. findNext : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredString::findNext → KILLED |
return this; |
| 69 | } | |
| 70 | ||
| 71 | private void updateOngoingExplanation(StringBuilder b, T token, Cursor cursor, BiFunction<Object, T, String> locatorFactoryFormatter) { | |
| 72 |
1
1. updateOngoingExplanation : Replaced integer addition with subtraction → KILLED |
b.append(this.originalString, this.position, this.position + cursor.position); |
| 73 | b.append("<"); | |
| 74 |
3
1. updateOngoingExplanation : Replaced integer addition with subtraction → KILLED 2. updateOngoingExplanation : Replaced integer addition with subtraction → KILLED 3. updateOngoingExplanation : Replaced integer addition with subtraction → KILLED |
b.append(formatObject(this.originalString.substring(this.position + cursor.position, this.position + cursor.position + cursor.length))); |
| 75 | b.append(":"); | |
| 76 | b.append(locatorFactoryFormatter.apply(locatorFactory, token)); | |
| 77 | b.append(">"); | |
| 78 | } | |
| 79 | ||
| 80 | @Override | |
| 81 | public Object snapshot() { | |
| 82 |
1
1. snapshot : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredString::snapshot → SURVIVED |
return originalString.substring(position); |
| 83 | } | |
| 84 | ||
| 85 | @Override | |
| 86 | public String toString() { | |
| 87 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredString::toString → SURVIVED |
return "CursoredString:[" + originalString + "]"; |
| 88 | } | |
| 89 | } | |
| 90 | CursoredString cursoredStringForSnapshotting = new CursoredString(null); | |
| 91 | class CursoredStringPredicate extends PrintablePredicate<CursoredString> implements | |
| 92 | Predicate<CursoredString>, | |
| 93 | Evaluable.LeafPred<CursoredString>, | |
| 94 | Evaluator.Explainable { | |
| 95 | final T each; | |
| 96 | ||
| 97 | CursoredStringPredicate(T each) { | |
| 98 |
1
1. lambda$new$0 : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::lambda$new$0 → NO_COVERAGE |
super(new Object(), emptyList(), () -> "findTokenBy[" + locatorFactory + "[" + each + "]]", cursoredString -> { |
| 99 | cursoredStringForSnapshotting.previousFailingPosition = cursoredString.previousFailingPosition; | |
| 100 | cursoredStringForSnapshotting.position = cursoredString.position; | |
| 101 | cursoredStringForSnapshotting.originalString = cursoredString.originalString; | |
| 102 |
2
1. lambda$new$1 : negated conditional → KILLED 2. lambda$new$1 : replaced boolean return with true for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::lambda$new$1 → KILLED |
return cursoredString.position != cursoredString.findNext(each).position; |
| 103 | }); | |
| 104 | this.each = each; | |
| 105 | } | |
| 106 | ||
| 107 | @Override | |
| 108 | public boolean test(CursoredString v) { | |
| 109 | boolean ret = super.test(v); | |
| 110 |
3
1. test : negated conditional → SURVIVED 2. test : removed call to java/util/concurrent/atomic/AtomicBoolean::set → SURVIVED 3. test : negated conditional → KILLED |
result.set(ret && result.get()); |
| 111 |
2
1. test : replaced boolean return with true for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::test → SURVIVED 2. test : replaced boolean return with false for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::test → KILLED |
return ret; |
| 112 | } | |
| 113 | ||
| 114 | @Override | |
| 115 | public String toString() { | |
| 116 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::toString → SURVIVED |
return "findTokenBy[" + locatorFactoryName() + "]"; |
| 117 | } | |
| 118 | ||
| 119 | private String locatorFactoryName() { | |
| 120 |
1
1. locatorFactoryName : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::locatorFactoryName → SURVIVED |
return locatorFactory + "[" + each + "]"; |
| 121 | } | |
| 122 | ||
| 123 | @Override | |
| 124 | public Predicate<? super CursoredString> predicate() { | |
| 125 |
1
1. predicate : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::predicate → KILLED |
return this; |
| 126 | } | |
| 127 | ||
| 128 | ||
| 129 | @Override | |
| 130 | public Object explainOutputExpectation() { | |
| 131 |
1
1. explainOutputExpectation : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::explainOutputExpectation → SURVIVED |
return formatExplanation(bExpectation, "SHOULD BE FOUND AFTER THIS POSITION"); |
| 132 | } | |
| 133 | ||
| 134 | @Override | |
| 135 | public Object explainActual(Object actualValue) { | |
| 136 |
1
1. explainActual : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::explainActual → SURVIVED |
return formatExplanation(bActual, "BUT NOT FOUND"); |
| 137 | } | |
| 138 | ||
| 139 | private String formatExplanation(StringBuilder b, String keyword) { | |
| 140 | String ret = b.toString() + format("%n") + "<" + this.locatorFactoryName() + ":" + keyword + ">"; | |
| 141 | b.delete(0, b.length()); | |
| 142 |
1
1. formatExplanation : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$1CursoredStringPredicate::formatExplanation → SURVIVED |
return ret; |
| 143 | } | |
| 144 | } | |
| 145 |
2
1. findTokens : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::findTokens → KILLED 2. lambda$findTokens$0 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findTokens$0 → KILLED |
return Predicates.transform(function("findTokens" + formatObject(tokens), CursoredString::new)) |
| 146 | .check(Predicates.allOf( | |
| 147 | Stream.concat( | |
| 148 |
1
1. lambda$findTokens$1 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findTokens$1 → KILLED |
Arrays.stream(tokens).map(CursoredStringPredicate::new), |
| 149 |
1
1. lambda$findTokens$2 : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findTokens$2 → KILLED |
Stream.of(endMarkPredicateForString(lastTestedPosition, bExpectation, bActual, result, () -> cursoredStringForSnapshotting.originalString))) |
| 150 |
1
1. lambda$findTokens$3 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findTokens$3 → KILLED |
.toArray(Predicate[]::new))); |
| 151 | ||
| 152 | } | |
| 153 | | |
| 154 | private static Predicate<Object> endMarkPredicateForString(AtomicInteger lastTestedPosition, StringBuilder ongoingExpectationExplanation, StringBuilder ongoingActualExplanation, AtomicBoolean result, Supplier<String> originalStringSupplier) { | |
| 155 |
3
1. lambda$endMarkPredicateForString$4 : replaced boolean return with true for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$endMarkPredicateForString$4 → SURVIVED 2. endMarkPredicateForString : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::endMarkPredicateForString → KILLED 3. lambda$endMarkPredicateForString$4 : replaced boolean return with false for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$endMarkPredicateForString$4 → KILLED |
return makeExplainable((PrintablePredicate<? super Object>) predicate("(end)", v -> result.get()), new Evaluator.Explainable() { |
| 156 | ||
| 157 | @Override | |
| 158 | public Object explainOutputExpectation() { | |
| 159 |
1
1. explainOutputExpectation : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1::explainOutputExpectation → SURVIVED |
return ongoingExpectationExplanation.toString() + originalStringSupplier.get().substring(lastTestedPosition.get()); |
| 160 | } | |
| 161 | ||
| 162 | @Override | |
| 163 | public Object explainActual(Object actualValue) { | |
| 164 |
1
1. explainActual : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1::explainActual → SURVIVED |
return ongoingActualExplanation.toString() + originalStringSupplier.get().substring(lastTestedPosition.get()); |
| 165 | } | |
| 166 | }); | |
| 167 | } | |
| 168 | | |
| 169 | private static <T> Predicate<T> makeExplainable(PrintablePredicate<? super T> p, Evaluator.Explainable explainable) { | |
| 170 | class ExplainablePredicate extends PrintablePredicate<T> implements | |
| 171 | Predicate<T>, | |
| 172 | Evaluable.LeafPred<T>, | |
| 173 | Evaluator.Explainable { | |
| 174 | ||
| 175 | protected ExplainablePredicate() { | |
| 176 | super(new Object(), emptyList(), p::toString, p); | |
| 177 | } | |
| 178 | ||
| 179 | @Override | |
| 180 | public Predicate<? super T> predicate() { | |
| 181 |
1
1. predicate : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1ExplainablePredicate::predicate → KILLED |
return predicate; |
| 182 | } | |
| 183 | ||
| 184 | @Override | |
| 185 | public Object explainOutputExpectation() { | |
| 186 |
1
1. explainOutputExpectation : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1ExplainablePredicate::explainOutputExpectation → SURVIVED |
return explainable.explainOutputExpectation(); |
| 187 | } | |
| 188 | ||
| 189 | @Override | |
| 190 | public Object explainActual(Object actualValue) { | |
| 191 |
1
1. explainActual : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$1ExplainablePredicate::explainActual → SURVIVED |
return explainable.explainActual(actualValue); |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 195 |
1
1. makeExplainable : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::makeExplainable → KILLED |
return new ExplainablePredicate(); |
| 196 | } | |
| 197 | | |
| 198 | public static Predicate<String> findSubstrings(String... tokens) { | |
| 199 |
3
1. findSubstrings : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::findSubstrings → KILLED 2. lambda$findSubstrings$6 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findSubstrings$6 → KILLED 3. lambda$null$5 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$null$5 → KILLED |
return findTokens(Printables.function("substring", token -> string -> new Cursor(string.indexOf(token), token.length())), tokens); |
| 200 | } | |
| 201 | | |
| 202 | public static Predicate<String> findRegexPatterns(Pattern... patterns) { | |
| 203 |
2
1. findRegexPatterns : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::findRegexPatterns → KILLED 2. lambda$findRegexPatterns$8 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findRegexPatterns$8 → KILLED |
return findTokens(function("matchesRegex", token -> string -> { |
| 204 | java.util.regex.Matcher m = token.matcher(string); | |
| 205 |
1
1. lambda$null$7 : negated conditional → KILLED |
if (m.find()) { |
| 206 |
2
1. lambda$null$7 : Replaced integer subtraction with addition → KILLED 2. lambda$null$7 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$null$7 → KILLED |
return new Cursor(m.start(), m.end() - m.start()); |
| 207 | } else | |
| 208 |
1
1. lambda$null$7 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$null$7 → SURVIVED |
return new Cursor(-1, 0); |
| 209 | ||
| 210 | }), patterns); | |
| 211 | } | |
| 212 | | |
| 213 | public static Predicate<String> findRegexes(String... regexes) { | |
| 214 |
2
1. findRegexes : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::findRegexes → KILLED 2. lambda$findRegexes$9 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findRegexes$9 → KILLED |
return findRegexPatterns(Arrays.stream(regexes).map(Pattern::compile).toArray(Pattern[]::new)); |
| 215 | } | |
| 216 | | |
| 217 | @SuppressWarnings("unchecked") | |
| 218 | @SafeVarargs | |
| 219 | public static <E> Predicate<List<E>> findElements(Predicate<? super E>... predicates) { | |
| 220 | AtomicBoolean result = new AtomicBoolean(true); | |
| 221 | List<Object> expectationExplanationList = new LinkedList<>(); | |
| 222 | List<Object> actualExplanationList = new LinkedList<>(); | |
| 223 | List<Object> rest = new LinkedList<>(); | |
| 224 | AtomicInteger previousPosition = new AtomicInteger(0); | |
| 225 |
1
1. lambda$findElements$12 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findElements$12 → KILLED |
Function<Predicate<? super E>, Predicate<CursoredList<E>>> predicatePredicateFunction = (Predicate<? super E> p) -> (Predicate<CursoredList<E>>) cursoredList -> { |
| 226 | AtomicInteger j = new AtomicInteger(0); | |
| 227 | boolean isFound = cursoredList.currentList().stream() | |
| 228 | .peek((E each) -> j.getAndIncrement()) | |
| 229 | .anyMatch(p); | |
| 230 |
1
1. lambda$null$11 : negated conditional → KILLED |
if (isFound) { |
| 231 |
1
1. lambda$null$11 : removed call to com/github/dakusui/pcond/experimentals/cursor/Cursors::updateExplanationsForFoundElement → SURVIVED |
updateExplanationsForFoundElement( |
| 232 | expectationExplanationList, actualExplanationList, | |
| 233 |
1
1. lambda$null$11 : Replaced integer subtraction with addition → SURVIVED |
cursoredList.currentList().get(j.get() - 1), |
| 234 |
1
1. lambda$null$11 : Replaced integer subtraction with addition → SURVIVED |
p, (List<Object>) cursoredList.currentList().subList(0, j.get() - 1)); |
| 235 |
1
1. lambda$null$11 : removed call to java/util/List::clear → SURVIVED |
rest.clear(); |
| 236 | rest.add(cursoredList.currentList().subList(j.get(), cursoredList.currentList().size())); | |
| 237 |
1
1. lambda$null$11 : Replaced integer addition with subtraction → KILLED |
cursoredList.position += j.get(); |
| 238 |
1
1. lambda$null$11 : removed call to java/util/concurrent/atomic/AtomicInteger::set → SURVIVED |
previousPosition.set(cursoredList.position); |
| 239 |
1
1. lambda$null$11 : replaced boolean return with false for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$null$11 → KILLED |
return true; |
| 240 | } | |
| 241 |
1
1. lambda$null$11 : removed call to com/github/dakusui/pcond/experimentals/cursor/Cursors::updateExplanationsForMissedPredicateIfCursorMoved → SURVIVED |
updateExplanationsForMissedPredicateIfCursorMoved( |
| 242 | expectationExplanationList, actualExplanationList, | |
| 243 |
2
1. lambda$null$11 : changed conditional boundary → SURVIVED 2. lambda$null$11 : negated conditional → SURVIVED |
cursoredList.position > previousPosition.get(), |
| 244 | p, cursoredList.currentList().subList(0, j.get())); | |
| 245 |
1
1. lambda$null$11 : removed call to java/util/concurrent/atomic/AtomicBoolean::set → SURVIVED |
result.set(false); |
| 246 |
1
1. lambda$null$11 : removed call to java/util/concurrent/atomic/AtomicInteger::set → SURVIVED |
previousPosition.set(cursoredList.position); |
| 247 |
1
1. lambda$null$11 : replaced boolean return with true for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$null$11 → SURVIVED |
return false; |
| 248 | }; | |
| 249 |
2
1. findElements : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::findElements → KILLED 2. lambda$findElements$13 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findElements$13 → KILLED |
return Predicates.transform(function("toCursoredList", (List<E> v)-> new CursoredList<>(v))) |
| 250 | .check(Predicates.allOf(Stream.concat( | |
| 251 | Arrays.stream(predicates) | |
| 252 |
1
1. lambda$findElements$14 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findElements$14 → KILLED |
.map((Predicate<? super E> each) -> predicate("findElementBy[" + each + "]", predicatePredicateFunction.apply(each))), |
| 253 | Stream.of(endMarkPredicateForList(result, expectationExplanationList, actualExplanationList, rest))) | |
| 254 |
1
1. lambda$findElements$15 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$findElements$15 → KILLED |
.toArray(Predicate[]::new))); |
| 255 | } | |
| 256 | | |
| 257 | private static <E> void updateExplanationsForFoundElement(List<Object> expectationExplanationList, List<Object> actualExplanationList, E foundElement, Predicate<? super E> matchedPredicate, List<Object> skippedElements) { | |
| 258 |
1
1. updateExplanationsForFoundElement : negated conditional → SURVIVED |
if (!skippedElements.isEmpty()) { |
| 259 | // expectationExplanationList.add(skippedElements); | |
| 260 | actualExplanationList.add(skippedElements); | |
| 261 | } | |
| 262 | actualExplanationList.add(new Explanation(foundElement, "<%s:found for:" + matchedPredicate + ">")); | |
| 263 | expectationExplanationList.add(new Explanation(matchedPredicate, "<matching element for:%s>")); | |
| 264 | } | |
| 265 | | |
| 266 | private static <E> void updateExplanationsForMissedPredicateIfCursorMoved(List<Object> expectationExplanationList, List<Object> actualExplanationList, boolean isCursorMoved, Predicate<? super E> missedPredicate, List<E> scannedElements) { | |
| 267 |
1
1. updateExplanationsForMissedPredicateIfCursorMoved : negated conditional → SURVIVED |
if (isCursorMoved) { |
| 268 | //expectationExplanationList.add(scannedElements); | |
| 269 | actualExplanationList.add(scannedElements); | |
| 270 | } | |
| 271 | Explanation missedInExpectation = new Explanation(missedPredicate, "<matching element for:%s>"); | |
| 272 | expectationExplanationList.add(missedInExpectation); | |
| 273 | ||
| 274 | Explanation missedInActual = new Explanation(missedPredicate, "<NOT FOUND:matching element for:%s>"); | |
| 275 | actualExplanationList.add(missedInActual); | |
| 276 | } | |
| 277 | | |
| 278 | private static Predicate<Object> endMarkPredicateForList(AtomicBoolean result, List<Object> expectationExplanationList, List<Object> actualExplanationList, List<?> rest) { | |
| 279 |
3
1. lambda$endMarkPredicateForList$16 : replaced boolean return with true for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$endMarkPredicateForList$16 → SURVIVED 2. endMarkPredicateForList : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors::endMarkPredicateForList → KILLED 3. lambda$endMarkPredicateForList$16 : replaced boolean return with false for com/github/dakusui/pcond/experimentals/cursor/Cursors::lambda$endMarkPredicateForList$16 → KILLED |
return makeExplainable((PrintablePredicate<? super Object>) predicate("(end)", v -> result.get()), new Evaluator.Explainable() { |
| 280 | ||
| 281 | @Override | |
| 282 | public Object explainOutputExpectation() { | |
| 283 |
1
1. explainOutputExpectation : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$2::explainOutputExpectation → SURVIVED |
return renderExplanationString(expectationExplanationList); |
| 284 | } | |
| 285 | ||
| 286 | @Override | |
| 287 | public Object explainActual(Object actualValue) { | |
| 288 |
1
1. explainActual : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$2::explainActual → SURVIVED |
return renderExplanationString(createFullExplanationList(actualExplanationList, rest)); |
| 289 | } | |
| 290 | ||
| 291 | private List<Object> createFullExplanationList(List<Object> explanationList, List<?> rest) { | |
| 292 |
1
1. createFullExplanationList : replaced return value with Collections.emptyList for com/github/dakusui/pcond/experimentals/cursor/Cursors$2::createFullExplanationList → SURVIVED |
return Stream.concat(explanationList.stream(), rest.stream()).collect(toList()); |
| 293 | } | |
| 294 | ||
| 295 | private String renderExplanationString(List<Object> fullExplanationList) { | |
| 296 |
1
1. renderExplanationString : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$2::renderExplanationString → SURVIVED |
return fullExplanationList |
| 297 | .stream() | |
| 298 | .map(e -> { | |
| 299 |
1
1. lambda$renderExplanationString$0 : negated conditional → KILLED |
if (e instanceof List) { |
| 300 |
1
1. lambda$renderExplanationString$0 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$2::lambda$renderExplanationString$0 → KILLED |
return String.format("<%s:skipped>", |
| 301 | ((List<?>) e).stream() | |
| 302 | .map(InternalUtils::formatObject) | |
| 303 | .collect(joining(","))); | |
| 304 | } | |
| 305 |
1
1. lambda$renderExplanationString$0 : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$2::lambda$renderExplanationString$0 → KILLED |
return e; |
| 306 | }) | |
| 307 | .map(Object::toString) | |
| 308 | .collect(joining(String.format("%n"))); | |
| 309 | } | |
| 310 | }); | |
| 311 | } | |
| 312 | | |
| 313 | static class Cursor { | |
| 314 | /** | |
| 315 | * The "relative" position, where the token was found, from the beginning of the string passed to a locator. | |
| 316 | * By convention, it is designed to pass a substring of the original string, which starts from the position, | |
| 317 | * where a token (element) searching attempt was made. | |
| 318 | */ | |
| 319 | final int position; | |
| 320 | /** | |
| 321 | * A length of a token to be searched. | |
| 322 | */ | |
| 323 | final int length; | |
| 324 | ||
| 325 | Cursor(int position, int length) { | |
| 326 | this.position = position; | |
| 327 | this.length = length; | |
| 328 | } | |
| 329 | } | |
| 330 | | |
| 331 | static class CursoredList<EE> extends AbstractList<EE> implements Evaluator.Snapshottable, Collection<EE> { | |
| 332 | int position; | |
| 333 | final List<EE> originalList; | |
| 334 | ||
| 335 | CursoredList(List<EE> originalList) { | |
| 336 | this.originalList = originalList; | |
| 337 | } | |
| 338 | ||
| 339 | List<EE> currentList() { | |
| 340 |
1
1. currentList : replaced return value with Collections.emptyList for com/github/dakusui/pcond/experimentals/cursor/Cursors$CursoredList::currentList → KILLED |
return this.originalList.subList(position, this.originalList.size()); |
| 341 | } | |
| 342 | ||
| 343 | @Override | |
| 344 | public Object snapshot() { | |
| 345 |
1
1. snapshot : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$CursoredList::snapshot → SURVIVED |
return originalList.subList(position, originalList.size()); |
| 346 | } | |
| 347 | ||
| 348 | @Override | |
| 349 | public int size() { | |
| 350 |
2
1. size : replaced int return with 0 for com/github/dakusui/pcond/experimentals/cursor/Cursors$CursoredList::size → SURVIVED 2. size : Replaced integer subtraction with addition → KILLED |
return originalList.size() - position; |
| 351 | } | |
| 352 | ||
| 353 | @Override | |
| 354 | public EE get(int index) { | |
| 355 |
2
1. get : replaced return value with null for com/github/dakusui/pcond/experimentals/cursor/Cursors$CursoredList::get → SURVIVED 2. get : Replaced integer addition with subtraction → KILLED |
return originalList.get(position + index); |
| 356 | } | |
| 357 | ||
| 358 | @Override | |
| 359 | public String toString() { | |
| 360 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$CursoredList::toString → SURVIVED |
return "CursoredList:" + originalList; |
| 361 | } | |
| 362 | } | |
| 363 | | |
| 364 | private static class Explanation { | |
| 365 | final Object value; | |
| 366 | private final String formatString; | |
| 367 | ||
| 368 | private Explanation(Object value, String formatString) { | |
| 369 | this.value = value; | |
| 370 | this.formatString = formatString; | |
| 371 | } | |
| 372 | ||
| 373 | @Override | |
| 374 | public String toString() { | |
| 375 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/experimentals/cursor/Cursors$Explanation::toString → SURVIVED |
return format(formatString, formatObject(this.value)); |
| 376 | } | |
| 377 | } | |
| 378 | } | |
Mutations | ||
| 59 |
1.1 2.2 |
|
| 60 |
1.1 2.2 |
|
| 61 |
1.1 2.2 |
|
| 63 |
1.1 2.2 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |
|
| 72 |
1.1 |
|
| 74 |
1.1 2.2 3.3 |
|
| 82 |
1.1 |
|
| 87 |
1.1 |
|
| 98 |
1.1 |
|
| 102 |
1.1 2.2 |
|
| 110 |
1.1 2.2 3.3 |
|
| 111 |
1.1 2.2 |
|
| 116 |
1.1 |
|
| 120 |
1.1 |
|
| 125 |
1.1 |
|
| 131 |
1.1 |
|
| 136 |
1.1 |
|
| 142 |
1.1 |
|
| 145 |
1.1 2.2 |
|
| 148 |
1.1 |
|
| 149 |
1.1 |
|
| 150 |
1.1 |
|
| 155 |
1.1 2.2 3.3 |
|
| 159 |
1.1 |
|
| 164 |
1.1 |
|
| 181 |
1.1 |
|
| 186 |
1.1 |
|
| 191 |
1.1 |
|
| 195 |
1.1 |
|
| 199 |
1.1 2.2 3.3 |
|
| 203 |
1.1 2.2 |
|
| 205 |
1.1 |
|
| 206 |
1.1 2.2 |
|
| 208 |
1.1 |
|
| 214 |
1.1 2.2 |
|
| 225 |
1.1 |
|
| 230 |
1.1 |
|
| 231 |
1.1 |
|
| 233 |
1.1 |
|
| 234 |
1.1 |
|
| 235 |
1.1 |
|
| 237 |
1.1 |
|
| 238 |
1.1 |
|
| 239 |
1.1 |
|
| 241 |
1.1 |
|
| 243 |
1.1 2.2 |
|
| 245 |
1.1 |
|
| 246 |
1.1 |
|
| 247 |
1.1 |
|
| 249 |
1.1 2.2 |
|
| 252 |
1.1 |
|
| 254 |
1.1 |
|
| 258 |
1.1 |
|
| 267 |
1.1 |
|
| 279 |
1.1 2.2 3.3 |
|
| 283 |
1.1 |
|
| 288 |
1.1 |
|
| 292 |
1.1 |
|
| 296 |
1.1 |
|
| 299 |
1.1 |
|
| 300 |
1.1 |
|
| 305 |
1.1 |
|
| 340 |
1.1 |
|
| 345 |
1.1 |
|
| 350 |
1.1 2.2 |
|
| 355 |
1.1 2.2 |
|
| 360 |
1.1 |
|
| 375 |
1.1 |