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

ljacqu / wordeval / 14537988077

18 Apr 2025 04:05PM UTC coverage: 63.456% (+0.2%) from 63.217%
14537988077

push

github

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

237 of 406 branches covered (58.37%)

3 of 16 new or added lines in 4 files covered. (18.75%)

1 existing line in 1 file now uncovered.

672 of 1059 relevant lines covered (63.46%)

3.67 hits per line

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

0.0
/src/main/java/ch/jalu/wordeval/evaluators/processing/ResultsProvider.java
1
package ch.jalu.wordeval.evaluators.processing;
2

3
import ch.jalu.wordeval.evaluators.AllWordsEvaluator;
4
import ch.jalu.wordeval.evaluators.result.EvaluationResult;
5
import com.google.common.collect.ImmutableList;
6

7
import java.util.List;
8
import java.util.Map;
9
import java.util.function.Predicate;
10
import java.util.stream.Collectors;
11

12
/**
13
 * Argument passed to {@link ch.jalu.wordeval.evaluators.PostEvaluator} instances to allow them to fetch
14
 * a <b>read-only</b> view of other evaluator's results.
15
 */
16
public class ResultsProvider {
17

18
  private final Map<AllWordsEvaluator<?>, ResultStore<?>> evaluatorResults;
19

20
  /**
21
   * Constructor.
22
   *
23
   * @param evaluatorResults the evaluator processor with the results
24
   */
NEW
25
  ResultsProvider(Map<AllWordsEvaluator<?>, ResultStore<?>> evaluatorResults) {
×
26
    this.evaluatorResults = evaluatorResults;
×
27
  }
×
28

29
  /** // TODO JAVADOC
30
   * Returns the results of the evaluator of the given class. Throws an exception if more than one evaluator of
31
   * this class exists.
32
   *
33
   * @param clz the evaluator class to search for
34
   * @return the results of the evaluator of the provided class
35
   */
36
  public <R extends EvaluationResult, E extends AllWordsEvaluator<R>> ImmutableList<R> getResultsOfEvaluatorOfType(
37
                                                                                                         Class<E> clz) {
38
    return getResultsOfEvaluatorOfType(clz, e -> true);
×
39
  }
40

41
  /** TODO JAVADOC
42
   * Returns the results of the evaluator that is an instance of the given class and which satisfies the provided
43
   * predicate. An exception is thrown if more than one evaluator is matched successfully.
44
   *
45
   * @param clz the evaluator class to search for
46
   * @param predicate the predicate the evaluator must satisfy
47
   * @param <E> the evaluator type
48
   * @return the results of the matching evaluator
49
   */
50
  public <R extends EvaluationResult, E extends AllWordsEvaluator<R>> ImmutableList<R> getResultsOfEvaluatorOfType(
51
                                                                                 Class<E> clz, Predicate<E> predicate) {
52

53
    E evaluator = findEvaluatorOfTypeMatching(clz, predicate);
×
NEW
54
    return (ImmutableList<R>) evaluatorResults.get(evaluator).getEntries();
×
55
  }
56

57
  private <E extends AllWordsEvaluator<?>> E findEvaluatorOfTypeMatching(Class<E> evaluatorClass,
58
                                                                         Predicate<E> predicate) {
59
    List<E> matchingEvaluators = evaluatorResults.keySet().stream()
×
60
      .filter(evaluatorClass::isInstance)
×
61
      .map(evaluatorClass::cast)
×
62
      .filter(predicate)
×
63
      .collect(Collectors.toList());
×
64
    if (matchingEvaluators.size() == 1) {
×
65
      return matchingEvaluators.get(0);
×
66
    } else if (matchingEvaluators.isEmpty()) {
×
67
      throw new IllegalStateException("Found no matching evaluator");
×
68
    } else {
69
      throw new IllegalStateException("Found " + matchingEvaluators.size() + " evaluators but expected only 1");
×
70
    }
71
  }
72
}
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