• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ljacqu / wordeval / 14540892325

18 Apr 2025 07:50PM UTC coverage: 51.4% (-12.1%) from 63.456%
14540892325

push

github

ljacqu
Merge remote-tracking branch 'origin/master' into dependencies

239 of 546 branches covered (43.77%)

93 of 383 new or added lines in 27 files covered. (24.28%)

5 existing lines in 4 files now uncovered.

679 of 1321 relevant lines covered (51.4%)

3.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.23
/src/main/java/ch/jalu/wordeval/evaluators/processing/AllWordsEvaluatorProvider.java
1
package ch.jalu.wordeval.evaluators.processing;
2

3
import ch.jalu.wordeval.evaluators.AllWordsEvaluator;
4
import lombok.RequiredArgsConstructor;
5

6
import java.util.Collection;
7
import java.util.List;
8
import java.util.function.Predicate;
9

10
/**
11
 * Allows to retrieve another evaluator for a {@link ch.jalu.wordeval.evaluators.PostEvaluator post evaluator}.
12
 */
13
@RequiredArgsConstructor
14
public class AllWordsEvaluatorProvider {
15

16
  private final Collection<AllWordsEvaluator> allWordsEvaluator;
17

18
  /**
19
   * Returns the evaluator of the specified class. Throws an exception if no evaluator of the given type exists,
20
   * or if multiple evaluators exist.
21
   *
22
   * @param clz the evaluator class to retrieve
23
   * @param <E> the evaluator type
24
   * @return evaluator matching the type
25
   */
26
  public <E extends AllWordsEvaluator> E getEvaluator(Class<E> clz) {
27
    return findEvaluatorOfTypeMatching(clz, e -> true);
7✔
28
  }
29

30
  /**
31
   * Returns the evaluator of the specified class which fulfills the given predicate. Throws an exception if zero
32
   * or multiple evaluators were matched.
33
   *
34
   * @param clz the evaluator class to retrieve
35
   * @param predicate predicate the evaluator must fulfill in order to be a match
36
   * @param <E> the evaluator type
37
   * @return matching evaluator
38
   */
39
  public <E extends AllWordsEvaluator> E getEvaluator(Class<E> clz, Predicate<E> predicate) {
40
    return findEvaluatorOfTypeMatching(clz, predicate);
5✔
41
  }
42

43
  private <E extends AllWordsEvaluator> E findEvaluatorOfTypeMatching(Class<E> evaluatorClass,
44
                                                                      Predicate<E> predicate) {
45
    List<E> matchingEvaluators = allWordsEvaluator.stream()
5✔
46
        .filter(evaluatorClass::isInstance)
6✔
47
        .map(evaluatorClass::cast)
5✔
48
        .filter(predicate)
1✔
49
        .toList();
2✔
50
    if (matchingEvaluators.size() == 1) {
4!
51
      return matchingEvaluators.getFirst();
4✔
NEW
52
    } else if (matchingEvaluators.isEmpty()) {
×
NEW
53
      throw new IllegalStateException("Found no matching evaluator of type " + evaluatorClass.getSimpleName());
×
54
    } else {
NEW
55
      throw new IllegalStateException("Found " + matchingEvaluators.size() + " evaluators of type "
×
NEW
56
          + evaluatorClass.getSimpleName() + " but expected only 1");
×
57
    }
58
  }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc