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

ljacqu / wordeval / 14562991048

20 Apr 2025 08:19PM UTC coverage: 55.116% (+1.7%) from 53.367%
14562991048

push

github

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

269 of 568 branches covered (47.36%)

212 of 313 new or added lines in 36 files covered. (67.73%)

6 existing lines in 5 files now uncovered.

738 of 1339 relevant lines covered (55.12%)

3.27 hits per line

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

48.15
/src/main/java/ch/jalu/wordeval/evaluators/impl/SameLetterConsecutive.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.export.EvaluatorExportUtil;
6
import ch.jalu.wordeval.evaluators.result.WordWithKey;
7
import com.google.common.collect.ListMultimap;
8
import lombok.Getter;
9
import org.apache.commons.lang3.StringUtils;
10

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

17
/**
18
 * Finds words wherein the same letter appears multiple times consecutively,
19
 * e.g. "lll" in German "Rollladen."
20
 */
21
public class SameLetterConsecutive implements WordEvaluator {
2✔
22

23
  @Getter
6✔
24
  private final List<WordWithKey> results = new ArrayList<>();
25

26
  @Override
27
  public void evaluate(Word wordObject) {
28
    String word = wordObject.getWithoutAccents();
3✔
29
    int counter = 0;
2✔
30
    char lastChar = '\0';
2✔
31
    for (int i = 0; i <= word.length(); ++i) {
8✔
32
      if (i < word.length() && word.charAt(i) == lastChar) {
9✔
33
        ++counter;
2✔
34
      } else {
35
        if (counter > 1) {
3✔
36
          results.add(new WordWithKey(wordObject, StringUtils.repeat(lastChar, counter)));
11✔
37
        }
38
        lastChar = i < word.length() ? word.charAt(i) : '\0';
10✔
39
        counter = 1;
2✔
40
      }
41
    }
42
  }
1✔
43

44
  @Override
45
  public ListMultimap<Object, Object> getTopResults(int topScores, int maxLimit) {
46
    List<WordWithKey> sortedResult = results.stream()
×
NEW
47
        .sorted(Comparator.<WordWithKey>comparingInt(wordWithKey -> wordWithKey.key().length()).reversed())
×
48
        .toList();
×
49

50
    Set<Integer> uniqueValues = new HashSet<>();
×
51
    ListMultimap<Object, Object> filteredResults = EvaluatorExportUtil.newListMultimap();
×
52
    for (WordWithKey wordWithKey : sortedResult) {
×
NEW
53
      int score = wordWithKey.key().length();
×
54
      if (uniqueValues.add(score) && uniqueValues.size() > topScores) {
×
55
        break;
×
56
      }
NEW
57
      filteredResults.put(score, wordWithKey.word().getRaw() + " (" + wordWithKey.key() + ")");
×
58
      if (filteredResults.size() >= maxLimit) {
×
59
        break;
×
60
      }
61
    }
×
62

63
    return filteredResults;
×
64
  }
65
}
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