• 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

40.74
/src/main/java/ch/jalu/wordeval/evaluators/impl/VowelCount.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.WordWithKey;
6
import ch.jalu.wordeval.language.Language;
7
import ch.jalu.wordeval.language.LetterType;
8
import com.google.common.collect.ArrayListMultimap;
9
import com.google.common.collect.ListMultimap;
10
import lombok.Getter;
11

12
import java.util.ArrayList;
13
import java.util.Comparator;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Set;
17
import java.util.stream.Collectors;
18

19
/**
20
 * Evaluator which collects all words by count of
21
 * separate vowels or consonants for further processing.
22
 */
23
public class VowelCount implements WordEvaluator {
24

25
  private final List<String> letters;
26
  @Getter
27
  private final LetterType letterType;
28
  @Getter
5✔
29
  private final List<WordWithKey> results = new ArrayList<>();
30

31
  public VowelCount(Language language, LetterType letterType) {
2✔
32
    this.letters = letterType.getLetters(language);
5✔
33
    this.letterType = letterType;
3✔
34
  }
1✔
35

36
  @Override
37
  public void evaluate(Word word) {
38
    // TODO #64: Iterate over the letters of the word instead
39
    String wordWithoutAccents = word.getWithoutAccents();
3✔
40
    String letterProfile = letters.stream()
5✔
41
      .filter(wordWithoutAccents::contains)
4✔
42
      .collect(Collectors.joining());
4✔
43
    results.add(new WordWithKey(word, letterProfile));
9✔
44
  }
1✔
45

46
  @Override
47
  public ListMultimap<Object, Object> getTopResults(int topScores, int maxLimit) {
48
    // TODO: Should probably skip this as PostEvaluators cover the interesting stuff
NEW
49
    List<WordWithKey> sortedResult = results.stream()
×
NEW
50
        .sorted(Comparator.comparing((WordWithKey wwk) -> wwk.getKey().length()).reversed())
×
NEW
51
        .toList();
×
52

NEW
53
    Set<String> uniqueValues = new HashSet<>();
×
NEW
54
    ListMultimap<Object, Object> filteredResults = ArrayListMultimap.create();
×
NEW
55
    for (WordWithKey WordWithKey : sortedResult) {
×
NEW
56
      if (uniqueValues.add(WordWithKey.getKey()) && uniqueValues.size() > topScores) {
×
NEW
57
        break;
×
58
      }
NEW
59
      filteredResults.put(WordWithKey.getKey(), WordWithKey.getWord().getRaw());
×
NEW
60
      if (filteredResults.size() >= maxLimit) {
×
NEW
61
        break;
×
62
      }
NEW
63
    }
×
64

NEW
65
    return filteredResults;
×
66
  }
67

68
  @Override
69
  public String getId() {
NEW
70
    return switch (letterType) {
×
NEW
71
      case VOWELS -> "VowelCount";
×
NEW
72
      case CONSONANTS -> "ConsonantCount";
×
73
    };
74
  }
75
}
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