• 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

61.11
/src/main/java/ch/jalu/wordeval/evaluators/impl/AlphabeticalSequence.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

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 that checks if there is a group of letters in a word that is an
18
 * alphabetical sequence, e.g. "rstu" in German "Erstuntersuchung."
19
 */
20
public class AlphabeticalSequence implements WordEvaluator {
2✔
21

22
  private static final int FORWARDS = -1;
23
  private static final int BACKWARDS = 1;
24

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

28
  @Override
29
  public void evaluate(Word word) {
30
    // TODO #15: Make locale-aware instead
31
    findAlphabeticalSequences(word, FORWARDS);
4✔
32
    findAlphabeticalSequences(word, BACKWARDS);
4✔
33
  }
1✔
34

35
  private void findAlphabeticalSequences(Word word, int searchDirection) {
36
    String text = word.getWithoutAccentsWordCharsOnly();
3✔
37
    int alphabeticalStreak = 1;
2✔
38
    String previousChar = String.valueOf(text.charAt(0));
5✔
39
    for (int i = 1; i <= text.length(); ++i) {
8✔
40
      boolean isCharInSequence = false;
2✔
41
      if (i < text.length()) {
4✔
42
        String currentChar = String.valueOf(text.charAt(i));
5✔
43
        isCharInSequence = previousChar.compareTo(currentChar) == searchDirection;
9✔
44
        if (isCharInSequence) {
2✔
45
          ++alphabeticalStreak;
1✔
46
        }
47
        previousChar = currentChar;
2✔
48
      }
49
      if (!isCharInSequence || i == text.length()) {
6!
50
        if (alphabeticalStreak > 2) {
3✔
51
          String alphabeticalSequence = text.substring(i - alphabeticalStreak, i);
7✔
52
          results.add(new WordWithKey(word, alphabeticalSequence));
9✔
53
        }
54
        alphabeticalStreak = 1;
2✔
55
      }
56
    }
57
  }
1✔
58

59
  @Override
60
  public ListMultimap<Object, Object> getTopResults(int topScores, int maxLimit) {
61
    List<WordWithKey> sortedResult = results.stream()
×
NEW
62
        .sorted(Comparator.<WordWithKey>comparingInt(wordWithKey -> wordWithKey.key().length()).reversed())
×
63
        .toList();
×
64

65
    Set<Integer> uniqueValues = new HashSet<>();
×
66
    ListMultimap<Object, Object> filteredResults = EvaluatorExportUtil.newListMultimap();
×
67
    for (WordWithKey wordWithKey : sortedResult) {
×
NEW
68
      int score = wordWithKey.key().length();
×
69
      if (uniqueValues.add(score) && uniqueValues.size() > topScores) {
×
70
        break;
×
71
      }
NEW
72
      filteredResults.put(score, wordWithKey.word().getRaw() + " (" + wordWithKey.key() + ")");
×
73
      if (filteredResults.size() >= maxLimit) {
×
74
        break;
×
75
      }
76
    }
×
77

78
    return filteredResults;
×
79
  }
80
}
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