• 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

31.58
/src/main/java/ch/jalu/wordeval/evaluators/impl/LongWords.java
1
package ch.jalu.wordeval.evaluators.impl;
2

3
import ch.jalu.wordeval.dictionary.Word;
4
import ch.jalu.wordeval.evaluators.WordEvaluator;
5
import ch.jalu.wordeval.evaluators.result.WordWithScore;
6
import com.google.common.collect.ArrayListMultimap;
7
import com.google.common.collect.ListMultimap;
8
import lombok.Getter;
9

10
import java.util.ArrayList;
11
import java.util.Comparator;
12
import java.util.HashSet;
13
import java.util.List;
14
import java.util.Set;
15

16
/**
17
 * Filters the words by length, with the intention to get the longest words of
18
 * the dictionary.
19
 */
20
public class LongWords implements WordEvaluator {
2✔
21

22
  /** Ignore any words whose length is less than the minimum length. */
23
  private static final int MIN_LENGTH = 6;
24

25
  @Getter
6✔
26
  private final List<WordWithScore> results = new ArrayList<>();
27

28
  @Override
29
  public void evaluate(Word word) {
30
    int length = word.getLowercase().length();
4✔
31
    if (length >= MIN_LENGTH) {
3✔
32
      results.add(new WordWithScore(word, length));
10✔
33
    }
34
  }
1✔
35

36
  @Override
37
  public ListMultimap<Object, Object> getTopResults(int topScores, int maxLimit) {
NEW
38
    List<WordWithScore> sortedResult = results.stream()
×
NEW
39
        .sorted(Comparator.comparing(WordWithScore::getScore).reversed())
×
NEW
40
        .toList();
×
41

NEW
42
    Set<Double> uniqueValues = new HashSet<>();
×
NEW
43
    ListMultimap<Object, Object> filteredResults = ArrayListMultimap.create();
×
NEW
44
    for (WordWithScore wordWithScore : sortedResult) {
×
NEW
45
      if (uniqueValues.add(wordWithScore.getScore()) && uniqueValues.size() > topScores) {
×
NEW
46
        break;
×
47
      }
NEW
48
      filteredResults.put((int) wordWithScore.getScore(), wordWithScore.getWord().getRaw());
×
NEW
49
      if (filteredResults.size() >= maxLimit) {
×
NEW
50
        break;
×
51
      }
UNCOV
52
    }
×
53

NEW
54
    return filteredResults;
×
55
  }
56
}
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